Refactored Model to make faces first class objects for use in AABBTree, renamed BoundingBox.intersect to intersect?

This commit is contained in:
2019-02-25 17:59:09 -06:00
parent 0d7210b3f7
commit 8ccd1506f3
7 changed files with 60 additions and 32 deletions

View File

@@ -58,6 +58,23 @@ class IMICFPS
@textured_material = key
end
end
@aabb_tree = AABBTree.new
@faces.each do |face|
box = BoundingBox.new
box.min = face.vertices.first.dup
box.max = face.vertices.first.dup
face.vertices.each do |vertex|
if vertex.sum < box.min.sum
box.min = vertex.dup
elsif vertex.sum > box.max.sum
box.max = vertex.dup
end
end
@aabb_tree.insert(face, box)
end
end
def allocate_gl_objects

View File

@@ -34,11 +34,11 @@ class IMICFPS
def flattened_vertices
unless @vertices_list
@debug_color = @faces.first[3].diffuse
@debug_color = @faces.first.material.diffuse
list = []
@faces.each do |face|
[face[0]].each do |v|
face.vertices.each do |v|
next unless v
list << v.x*@scale
list << v.y*@scale
@@ -61,8 +61,8 @@ class IMICFPS
def flattened_textures
unless @textures_list
list = []
@faces.each_with_index do |face, i|
[face[1]].each do |v|
@faces.each do |face|
face.uvs.each do |v|
next unless v
list << v.x
list << v.y
@@ -81,12 +81,11 @@ class IMICFPS
unless @normals_list
list = []
@faces.each do |face|
[face[2]].each do |v|
next unless v
list << v.x
list << v.y
list << v.z
# list << v.weight
face.normals.each do |n|
next unless n
list << n.x
list << n.y
list << n.z
end
end
@@ -101,15 +100,14 @@ class IMICFPS
unless @materials_list
list = []
@faces.each do |face|
# p face
[face[3]].each do |v|
next unless v
# p v
# exit
list << v.diffuse.red
list << v.diffuse.green
list << v.diffuse.blue
# list << v.alpha
material = face.material
next unless material
face.vertices.each do # Add material to each vertex
list << material.diffuse.red
list << material.diffuse.green
list << material.diffuse.blue
# list << material.alpha
end
end

View File

@@ -38,15 +38,27 @@ class IMICFPS
norms << f.split("/")[2]
end
face = Face.new
face.vertices = []
face.uvs = []
face.normals = []
face.material = material
face.smoothing= @smoothing
verts.each_with_index do |v, index|
if uvs.first != ""
face = [@vertices[Integer(v)-1], @uvs[Integer(uvs[index])-1], @normals[Integer(norms[index])-1], material, @smoothing]
face.vertices << @vertices[Integer(v)-1]
face.uvs << @uvs[Integer(uvs[index])-1]
face.normals << @normals[Integer(norms[index])-1]
else
face = [@vertices[Integer(v)-1], nil, @normals[Integer(norms[index])-1], material, @smoothing]
face.vertices << @vertices[Integer(v)-1]
face.uvs << nil
face.normals << @normals[Integer(norms[index])-1]
end
@current_object.faces << face
@faces << face
end
@current_object.faces << face
@faces << face
end
end