Class: Mittsu::PolyhedronGeometry
- Defined in:
- lib/mittsu/extras/geometries/polyhedron_geometry.rb
Direct Known Subclasses
DodecahedronGeometry, IcosahedronGeometry, OctahedronGeometry, TetrahedronGeometry
Instance Attribute Summary
Attributes inherited from Geometry
#bounding_box, #bounding_sphere, #colors, #dynamic, #face_vertex_uvs, #faces, #has_tangents, #id, #line_distances, #morph_colors, #morph_normals, #morph_targets, #name, #skin_indices, #skin_weights, #type, #uuid, #vertices
Instance Method Summary collapse
-
#initialize(vertices, indices, radius = 1.0, detail = 0) ⇒ PolyhedronGeometry
constructor
A new instance of PolyhedronGeometry.
Methods inherited from Geometry
#apply_matrix, #center, #clone, #compute_bounding_box, #compute_bounding_sphere, #compute_face_normals, #compute_line_distances, #compute_morph_normals, #compute_tangents, #compute_vertex_normals, #dispose, #from_buffer_geometry, #merge, #merge_mesh, #merge_vertices, #to_json
Methods included from EventDispatcher
#add_event_listener, #dispatch_event, #has_event_listener, #remove_event_listener
Constructor Details
#initialize(vertices, indices, radius = 1.0, detail = 0) ⇒ PolyhedronGeometry
Returns a new instance of PolyhedronGeometry.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/mittsu/extras/geometries/polyhedron_geometry.rb', line 6 def initialize(vertices, indices, radius = 1.0, detail = 0) super() @type = 'PolyhedronGeometry' @parameters = { vertices: vertices, indices: indices, radius: radius, detail: detail } for i in (0...vertices.length).step(3) do prepare(Vector3.new(vertices[i], vertices[i + 1], vertices[i + 2])) end faces = [] i = 0 j = 0 while i < indices.length do v1 = @vertices[indices[i]] v2 = @vertices[indices[i + 1]] v3 = @vertices[indices[i + 2]] faces[j] = Face3.new(v1.index, v2.index, v3.index, [v1.clone, v2.clone, v3.clone]) i += 3 j += 1 end @centroid = Vector3.new for i in 0...faces.length do subdivide(faces[i], detail) end # Handle case when face straddles the seam @face_vertex_uvs[0].each do |uv0, uv1, uv2| x0 = uv0.x x1 = uv1.x x2 = uv2.x max = [x0, x1, x2].max min = [x0, x1, x2].min if max > 0.9 && min < 0.1 # 0.9 is somewhat arbitrary uv0.x += 1.0 if x0 < 0.2 uv1.x += 1.0 if x1 < 0.2 uv2.x += 1.0 if x2 < 0.2 end end # Apply radius @vertices.each do |v| v.multiply_scalar(radius) end merge_vertices compute_face_normals @bounding_sphere = Sphere.new(Vector3.new, radius) end |