mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2026-03-28 14:46:12 +00:00
Added a large portion of I-MIC-FPS's opengl rendering and model loading systems
This commit is contained in:
75
lib/cyberarm_engine/model/parser.rb
Normal file
75
lib/cyberarm_engine/model/parser.rb
Normal file
@@ -0,0 +1,75 @@
|
||||
module CyberarmEngine
|
||||
TextureCoordinate = Struct.new(:u, :v, :weight)
|
||||
Point = Struct.new(:x, :y)
|
||||
Color = Struct.new(:red, :green, :blue, :alpha)
|
||||
Face = Struct.new(:vertices, :uvs, :normals, :colors, :material, :smoothing)
|
||||
|
||||
class Model
|
||||
class Parser
|
||||
@@parsers = []
|
||||
|
||||
def self.handles
|
||||
raise NotImplementedError, "Model::Parser#handles must return an array of file extensions that this parser supports"
|
||||
end
|
||||
|
||||
def self.inherited(parser)
|
||||
@@parsers << parser
|
||||
end
|
||||
|
||||
def self.find(file_type)
|
||||
found_parser = @@parsers.find do |parser|
|
||||
parser.handles.include?(file_type)
|
||||
end
|
||||
|
||||
return found_parser
|
||||
end
|
||||
|
||||
def self.supported_formats
|
||||
@@parsers.map { |parser| parser.handles }.flatten.map { |s| ".#{s}" }.join(", ")
|
||||
end
|
||||
|
||||
def initialize(model)
|
||||
@model = model
|
||||
end
|
||||
|
||||
def parse
|
||||
end
|
||||
|
||||
def set_object(id: nil, name: nil)
|
||||
_model = nil
|
||||
|
||||
if id
|
||||
_model = @model.objects.find { |o| o.id == id }
|
||||
elsif name
|
||||
_model = @model.objects.find { |o| o.name == name }
|
||||
else
|
||||
raise "Must provide either an id: or name:"
|
||||
end
|
||||
|
||||
if _model
|
||||
@model.current_object = _model
|
||||
else
|
||||
raise "Couldn't find ModelObject!"
|
||||
end
|
||||
end
|
||||
|
||||
def change_object(id, name)
|
||||
@model.objects << Model::ModelObject.new(id, name)
|
||||
@model.current_object = @model.objects.last
|
||||
end
|
||||
|
||||
def set_material(name)
|
||||
@model.current_material = name
|
||||
@model.current_object.materials << current_material
|
||||
end
|
||||
|
||||
def add_material(name, material)
|
||||
@model.materials[name] = material
|
||||
end
|
||||
|
||||
def current_material
|
||||
@model.materials[@model.current_material]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user