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

@@ -101,6 +101,25 @@ require_relative "lib/demo"
require_relative "lib/window"
if ARGV[0] == "tool"
case ARGV[1]
when "viewer" # Turn Table
require_relative "lib/tools/asset_viewer/asset_viewer"
when "editor" # Level Editor
raise NotImplementedError
else
if ARGV[1].nil?
puts "### I-MIC FPS Tools ###"
puts "viewer - 3D Turn Table"
puts "editor - Level Editor"
else
raise "No such tool: #{ARGV[1]}"
end
end
return # Don't launch game, but load all required files
end
if ARGV.join.include?("--profile")
begin
require "ruby-prof"

View File

@@ -111,7 +111,10 @@ class IMICFPS
def free_move
relative_y_rotation = (@orientation.y + 180)
relative_speed = 0.25
relative_speed = 2.5
relative_speed = 1.5 if InputMapper.down?(:sneak)
relative_speed = 10.0 if InputMapper.down?(:sprint)
relative_speed *= window.dt
if InputMapper.down?( :forward)
@position.z+=Math.cos(relative_y_rotation * Math::PI / 180) * relative_speed

View File

@@ -11,13 +11,24 @@ class IMICFPS
def initialize(manifest:, map_entity: nil, spawnpoint: nil, backface_culling: true, auto_manage: true)
@manifest = manifest
@position = map_entity ? map_entity.position.clone : spawnpoint.position.clone
@orientation = map_entity ? map_entity.orientation.clone : spawnpoint.orientation.clone
@scale = map_entity ? map_entity.scale.clone : Vector.new(1, 1, 1)
if map_entity
@position = map_entity.position.clone
@orientation = map_entity.orientation.clone
@scale = map_entity.scale.clone
@bound_model = bind_model
elsif spawnpoint
@position = spawnpoint.position.clone
@orientation = spawnpoint.orientation.clone
@scale = Vector.new(1, 1, 1)
else
@position = Vector.new
@orientation = Vector.up
@scale = Vector.new(1, 1, 1)
end
@backface_culling = backface_culling
@name = @manifest.name
@bound_model = map_entity ? bind_model : nil
@visible = true
@renderable = true
@@ -57,7 +68,7 @@ class IMICFPS
end
def bind_model
model = ModelCache.new(manifest: @manifest, entity: @dummy_entity)
model = ModelCache.new(manifest: @manifest)
raise "model isn't a model!" unless model.is_a?(ModelCache)
@bound_model = model

View File

@@ -1,7 +1,7 @@
class IMICFPS
module EntityManager # Get included into GameState context
def add_entity(entity)
@collision_manager.add(entity) if entity.manifest.collision# Add every entity to collision manager
@collision_manager.add(entity) if @collision_manager && entity.manifest.collision# Add every entity to collision manager
Publisher.instance.publish(:create, nil, entity)
@entities << entity
end
@@ -22,7 +22,7 @@ class IMICFPS
def remove_entity(entity)
ent = @entities.detect {|entity| entity == entity}
if ent
@collision_manager.remove(entity) if entity.manifest.collision
@collision_manager.remove(entity) if @collision_manager && entity.manifest.collision
@publisher.publish(:destroy, nil, entity)
@entities.delete(ent)
end

View File

@@ -112,6 +112,7 @@ IMICFPS::InputMapper.set(:strife_right, Gosu::KbD)
IMICFPS::InputMapper.set(:turn_left, Gosu::KbLeft)
IMICFPS::InputMapper.set(:turn_right, Gosu::KbRight)
IMICFPS::InputMapper.set(:jump, Gosu::KbSpace)
IMICFPS::InputMapper.set(:sneak, [Gosu::KbLeftShift])
IMICFPS::InputMapper.set(:sprint, [Gosu::KbLeftControl])
IMICFPS::InputMapper.set(:turn_180, Gosu::KbX)

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

View File

@@ -30,7 +30,6 @@ class IMICFPS
draw_background
draw_menu_box
draw_menu
window.draw_cursor
end
def draw_background

View File

@@ -40,15 +40,14 @@ class IMICFPS
super
@console.draw if @show_console
draw_cursor if needs_cursor
end
def draw_cursor
size = 16
if needs_cursor
@cursor.draw(mouse_x, mouse_y, Float::INFINITY)
end
end
def update
super