Camera can bind to model

This commit is contained in:
2018-03-20 22:48:01 -05:00
parent d390d3d728
commit 2de1c0ffdf
6 changed files with 47 additions and 22 deletions

View File

@@ -11,13 +11,14 @@ class IMICFPS
include Parser
attr_accessor :objects, :materials, :vertexes, :texures, :normals, :faces
attr_accessor :x, :y, :z
attr_accessor :x, :y, :z, :scale
attr_reader :bounding_box
def initialize(object = "objects/cube.obj")
@x, @y, @z = 0, 0, 0
@object_path = object
@file = File.open(object, 'r')
def initialize(file_path:, x: 0, y: 0, z: 0, scale: MODEL_METER_SCALE)
@x, @y, @z = x, y, z
@scale = scale
@file_path = file_path
@file = File.open(file_path, 'r')
@material_file = nil
@current_object = nil
@current_material=nil
@@ -33,7 +34,7 @@ class IMICFPS
@bounding_box = BoundingBox.new(nil,nil,nil, nil,nil,nil)
start_time = Time.now
parse
puts "#{object.split('/').last} took #{(Time.now-start_time).round(2)} seconds to parse"
puts "#{@file_path.split('/').last} took #{(Time.now-start_time).round(2)} seconds to parse"
p @bounding_box
face_count = 0

View File

@@ -1,10 +1,11 @@
class IMICFPS
class Wavefront
class Object
attr_reader :name, :vertices, :textures, :normals, :bounding_box, :debug_color
attr_reader :parent, :name, :vertices, :textures, :normals, :bounding_box, :debug_color
attr_accessor :faces
def initialize(name)
def initialize(parent, name)
@parent = parent
@name = name
@vertices = []
@textures = []
@@ -28,9 +29,9 @@ class IMICFPS
@faces.each do |face|
[face[0]].each do |v|
next unless v
list << v.x
list << v.y
list << v.z
list << v.x*@parent.scale#+@parent.x
list << v.y*@parent.scale#+@parent.y
list << v.z*@parent.scale#+@parent.z
list << v.weight
end
end

View File

@@ -52,7 +52,7 @@ class IMICFPS
end
def parse_mtllib
file = File.open(@object_path.sub(File.basename(@object_path), '')+@material_file, 'r')
file = File.open(@file_path.sub(File.basename(@file_path), '')+@material_file, 'r')
file.readlines.each do |line|
array = line.strip.split(' ')
case array.first
@@ -78,7 +78,7 @@ class IMICFPS
end
def change_object(name)
@objects << Object.new(name)
@objects << Object.new(self, name)
@current_object = @objects.last
end