class ObjParser::SingleIndexedObj
Attributes
detailed_vertice[RW]
indexes[RW]
Public Class Methods
build_with_obj(obj)
click to toggle source
# File lib/obj_parser/single_indexed_obj.rb, line 13 def build_with_obj(obj) instance = self.new(obj) instance.setup instance end
Public Instance Methods
class()
click to toggle source
# File lib/obj_parser/single_indexed_obj.rb, line 10 def class; target.class ;end
setup()
click to toggle source
# File lib/obj_parser/single_indexed_obj.rb, line 20 def setup compute_detailed_vertice temp_vertice = [] temp_normals = [] temp_textures = [] temp_tangents = [] vec_indexes = [] self.vertice_indexes.each_with_index do |vertex_index, index| vertex = self.detailed_vertice[vertex_index] normal = vertex.normals.select{|n| n == self.normals[self.normals_indexes[index]] }.first texture = vertex.textures.select{|n| n == self.textures[self.textures_indexes[index]] }.first tangent = vertex.tangents.select{|n| n == self.tangents[self.tangents_indexes[index]] }.first if(point_used_for_vertex_at_index?(normal, vertex_index) && point_used_for_vertex_at_index?(texture, vertex_index)) candids = texture.flag[vertex_index] & normal.flag[vertex_index] vec_indexes << candids.first else temp_vertice << vertex temp_tangents << tangent if tangent vec_indexes << temp_vertice.count - 1 if(normal) temp_normals << normal normal.flag ||= {} normal.flag[vertex_index] ||= [] normal.flag[vertex_index] << temp_vertice.count - 1 end if(texture) temp_textures << texture texture.flag ||= {} texture.flag[vertex_index] ||= [] texture.flag[vertex_index] << temp_vertice.count - 1 end end end self.vertice = temp_vertice.map {|detailed_vertice| Point.new(detailed_vertice.data)} self.normals = temp_normals.map {|detailed_vertice| Point.new(detailed_vertice.data)} self.textures = temp_textures.map {|detailed_vertice| Point.new(detailed_vertice.data)} self.tangents = temp_tangents.map {|detailed_vertice| Point.new(detailed_vertice.data)} self.vertice_indexes = vec_indexes self.normals_indexes = vec_indexes self.textures_indexes = vec_indexes self.tangents_indexes = vec_indexes self.indexes = vec_indexes end
target()
click to toggle source
# File lib/obj_parser/single_indexed_obj.rb, line 9 def target; __getobj__ ;end
Private Instance Methods
compute_detailed_vertice()
click to toggle source
# File lib/obj_parser/single_indexed_obj.rb, line 70 def compute_detailed_vertice self.detailed_vertice = self.vertice.map {|vertex| Point.new(vertex.data)} self.vertice_indexes.each_with_index do |vertex_index, index| vertex = self.detailed_vertice[vertex_index] [:normals, :textures, :tangents].each do |element| if(self.send(element).any? && self.send("#{element}_indexes")[index]) candid = self.send(element)[self.send("#{element}_indexes")[index]] vertex.send(element) << candid unless vertex.send(element).include?(candid) end end end end
point_used_for_vertex_at_index?(point, vertex_index)
click to toggle source
# File lib/obj_parser/single_indexed_obj.rb, line 66 def point_used_for_vertex_at_index?(point, vertex_index) point && point.flag && point.flag[vertex_index] end