Added Asset Viewer

This commit is contained in:
2020-01-30 15:30:58 -06:00
parent dbf4edbb93
commit eb1bfe204b
10 changed files with 197 additions and 20 deletions

View 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

View 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

View 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