mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 23:52:35 +00:00
Added evergreen_tree model, added work-in-progress collada parser, renamed ModelLoader to ModelCache
This commit is contained in:
@@ -57,9 +57,9 @@ class IMICFPS
|
||||
end
|
||||
|
||||
def bind_model
|
||||
model = ModelLoader.new(manifest: @manifest, entity: @dummy_entity)
|
||||
model = ModelCache.new(manifest: @manifest, entity: @dummy_entity)
|
||||
|
||||
raise "model isn't a model!" unless model.is_a?(ModelLoader)
|
||||
raise "model isn't a model!" unless model.is_a?(ModelCache)
|
||||
@bound_model = model
|
||||
@bound_model.model.entity = self
|
||||
@bounding_box = normalize_bounding_box_with_offset
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
class IMICFPS
|
||||
class ModelLoader
|
||||
def self.supported_models
|
||||
["Wavefront OBJ"]
|
||||
end
|
||||
|
||||
CACHE = {}
|
||||
|
||||
attr_reader :model, :name, :debug_color
|
||||
|
||||
def initialize(manifest:, entity: nil)
|
||||
@name = manifest.name
|
||||
@model_file = model_file = manifest.file_path + "/model/#{manifest.model}"
|
||||
|
||||
@type = File.basename(@model_file).split(".").last.to_sym
|
||||
@debug_color = Color.new(0.0, 1.0, 0.0)
|
||||
|
||||
@model = nil
|
||||
@supported_models = ["OBJ"]
|
||||
|
||||
unless load_model_from_cache
|
||||
case @type
|
||||
when :obj
|
||||
@model = IMICFPS::Model.new(file_path: @model_file)
|
||||
else
|
||||
raise "Unsupported model type, supported models are: #{@supported_models.join(', ')}"
|
||||
end
|
||||
|
||||
cache_model
|
||||
end
|
||||
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
def load_model_from_cache
|
||||
found = false
|
||||
if CACHE[@type].is_a?(Hash)
|
||||
if CACHE[@type][@model_file]
|
||||
@model = CACHE[@type][@model_file]#.dup # Don't know why, but adding .dup improves performance with Sponza (1 fps -> 20 fps)
|
||||
puts "Used cached model for: #{@model_file.split('/').last}" if $window.config.get(:debug_options, :stats)
|
||||
found = true
|
||||
end
|
||||
end
|
||||
|
||||
return found
|
||||
end
|
||||
|
||||
def cache_model
|
||||
CACHE[@type] = {} unless CACHE[@type].is_a?(Hash)
|
||||
CACHE[@type][@model_file] = @model
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user