lib/mittsu/core/geometry.rb in mittsu-0.2.4 vs lib/mittsu/core/geometry.rb in mittsu-0.3.0
- old
+ new
@@ -1,7 +1,8 @@
require 'securerandom'
require 'mittsu'
+require 'securerandom'
module Mittsu
class Geometry
include EventDispatcher
@@ -17,10 +18,12 @@
def initialize
super
@id = (@@id ||= 1).tap { @@id += 1 }
+ @uuid = SecureRandom.uuid
+
@name = ''
@type = 'Geometry'
@vertices = []
@colors = [] # one-to-one vertex colors, used in Points and Line
@@ -103,11 +106,11 @@
scope.face_vertex_uvs[0] << [temp_uvs[a].clone, temp_uvs[b].clone, temp_uvs[c].clone]
end
}
if indices
draw_calls = geometry.draw_calls
- if !draw_calls.length.empty?
+ if !draw_calls.empty?
draw_calls.each do |draw_call|
start = draw_call.start
count = draw_call.count
index = draw_call.index
j = start
@@ -117,25 +120,25 @@
j += 3
end
end
else
indices.each_slice(3).with_index do |index|
- add_face(*index)
+ add_face[*index]
end
end
else
i = 0, il = vertices.length / 3
while i < il
add_face[i, i + 1, i + 2]
i += 3
end
end
self.compute_face_normals
- if geometry.boundingBox
+ if geometry.bounding_box
@bounding_box = geometry.bounding_box.clone
end
- if geometry.boundingSphere
+ if geometry.bounding_sphere
@bounding_sphere = geometry.bounding_sphere.clone
end
self
end
@@ -158,15 +161,15 @@
cb.normalize
face.normal.copy(cb)
end
end
- def compute_vertex_normals(area_weigted)
+ def compute_vertex_normals(area_weighted = false)
vertices = Array.new(@vertices.length)
@vertices.length.times do |v|
vertices[v] = Mittsu::Vector3.new
end
- if area_weigted
+ if area_weighted
# vertex normals weighted by triangle areas
# http:#www.iquilezles.org/www/articles/normals/normals.htm
cb = Mittsu::Vector3.new, ab = Mittsu::Vector3.new
@faces.each do |face|
v_a = @vertices[face.a]