mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-16 16:12:35 +00:00
Added Asset Viewer
This commit is contained in:
12
lib/tools/asset_viewer/asset_viewer.rb
Normal file
12
lib/tools/asset_viewer/asset_viewer.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
require_relative "lib/main_menu"
|
||||
require_relative "lib/turn_table"
|
||||
|
||||
class AssetViewerWindow < IMICFPS::Window
|
||||
def initialize(*args)
|
||||
super(*args)
|
||||
|
||||
push_state(IMICFPS::AssetViewerTool::MainMenu)
|
||||
end
|
||||
end
|
||||
|
||||
AssetViewerWindow.new.show
|
||||
33
lib/tools/asset_viewer/lib/main_menu.rb
Normal file
33
lib/tools/asset_viewer/lib/main_menu.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
class IMICFPS
|
||||
class AssetViewerTool
|
||||
class MainMenu < CyberarmEngine::GuiState
|
||||
def setup
|
||||
window.needs_cursor = true
|
||||
|
||||
label "#{IMICFPS::NAME}", text_size: 50
|
||||
label "Asset Viewer", text_size: 28
|
||||
|
||||
@manifests = []
|
||||
Dir.glob(GAME_ROOT_PATH + "/assets/**/manifest.yaml").each do |manifest|
|
||||
begin
|
||||
@manifests << Manifest.new(manifest_file: manifest)
|
||||
rescue
|
||||
warn "Broken manifest: #{manifest}"
|
||||
end
|
||||
end
|
||||
|
||||
flow(margin: 10) do
|
||||
@manifests.each do |manifest|
|
||||
button manifest.name do
|
||||
push_state(TurnTable, manifest: manifest)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
button "Exit", margin_top: 25 do
|
||||
window.close
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
100
lib/tools/asset_viewer/lib/turn_table.rb
Normal file
100
lib/tools/asset_viewer/lib/turn_table.rb
Normal file
@@ -0,0 +1,100 @@
|
||||
class IMICFPS
|
||||
class AssetViewerTool
|
||||
class TurnTable < CyberarmEngine::GuiState
|
||||
include LightManager
|
||||
|
||||
attr_reader :map
|
||||
def setup
|
||||
@manifest = @options[:manifest]
|
||||
|
||||
if window.config.get(:debug, :use_shaders)
|
||||
Shader.new(
|
||||
name: "default",
|
||||
includes_dir: "shaders/include",
|
||||
vertex: "shaders/vertex/default.glsl",
|
||||
fragment: "shaders/fragment/default.glsl"
|
||||
)
|
||||
end
|
||||
|
||||
@map = ProtoMap.new
|
||||
Publisher.new
|
||||
|
||||
@entity = Entity.new(manifest: @manifest, auto_manage: false)
|
||||
@entity.bind_model
|
||||
@map.add_entity(@entity)
|
||||
@map.entities.each { |e| e.backface_culling = false }
|
||||
|
||||
@lights = []
|
||||
@light = Light.new(id: available_light, position: Vector.new, diffuse: Vector.new(1, 1, 1, 1))
|
||||
@lights << @light
|
||||
|
||||
@camera = Camera.new(position: Vector.new(0, 1.5, 5), orientation: Vector.forward)
|
||||
@renderer = Renderer.new
|
||||
|
||||
label @manifest.name, text_size: 50
|
||||
label @manifest.model
|
||||
@camera_position = label ""
|
||||
@camera_orientation = label ""
|
||||
|
||||
button "Back" do
|
||||
pop_state
|
||||
end
|
||||
end
|
||||
|
||||
def draw
|
||||
window.show_cursor = true
|
||||
|
||||
color_top = Gosu::Color::GRAY
|
||||
color_bottom = Gosu::Color::BLACK
|
||||
|
||||
Gosu.draw_quad(
|
||||
0, 0, color_top,
|
||||
window.width, 0, color_top,
|
||||
window.width, window.height, color_bottom,
|
||||
0, window.height, color_bottom,
|
||||
)
|
||||
|
||||
Gosu.gl do
|
||||
@renderer.draw(@camera, [@light], @map.entities)
|
||||
end
|
||||
|
||||
super
|
||||
end
|
||||
|
||||
def update
|
||||
super
|
||||
|
||||
@camera.update
|
||||
@light.position = @camera.position.clone
|
||||
@light.position.y += 1.5
|
||||
@camera_position.value = "Camera Position: X #{@camera.position.x.round(2)}, Y #{@camera.position.y.round(2)}, Z #{@camera.position.z.round(2)}"
|
||||
@camera_orientation.value = "Camera Orientation: X #{@camera.orientation.x.round(2)}, Y #{@camera.orientation.y.round(2)}, Z #{@camera.orientation.z.round(2)}\nEntities: #{@map.entities.count}"
|
||||
|
||||
@map.entities.each(&:update)
|
||||
end
|
||||
|
||||
def button_down(id)
|
||||
super
|
||||
|
||||
InputMapper.keydown(id)
|
||||
end
|
||||
|
||||
def button_up(id)
|
||||
super
|
||||
|
||||
InputMapper.keyup(id)
|
||||
@camera.button_up(id)
|
||||
end
|
||||
end
|
||||
|
||||
# Stub for enabling scripted models to load properly
|
||||
class ProtoMap
|
||||
include EntityManager
|
||||
|
||||
attr_reader :entities
|
||||
def initialize
|
||||
@entities = []
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user