Class: Mittsu::RingGeometry
- Defined in:
- lib/mittsu/extras/geometries/ring_geometry.rb
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
- #clone ⇒ Object
-
#initialize(inner_radius = 0.0, outer_radius = 50.0, theta_segments = 8, phi_segments = 8, theta_start = 0.0, theta_length = (::Math::PI * 2.0)) ⇒ RingGeometry
constructor
A new instance of RingGeometry.
Methods inherited from Geometry
#apply_matrix, #center, #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(inner_radius = 0.0, outer_radius = 50.0, theta_segments = 8, phi_segments = 8, theta_start = 0.0, theta_length = (::Math::PI * 2.0)) ⇒ RingGeometry
Returns a new instance of RingGeometry.
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 |
# File 'lib/mittsu/extras/geometries/ring_geometry.rb', line 6 def initialize(inner_radius = 0.0, outer_radius = 50.0, theta_segments = 8, phi_segments = 8, theta_start = 0.0, theta_length = (::Math::PI * 2.0)) super() @type = 'RingGeometry' @parameters = { inner_radius: inner_radius, outer_radius: outer_radius, theta_segments: theta_segments, phi_segments: phi_segments, theta_start: theta_start, theta_length: theta_length } theta_segments = [3, theta_segments].max phi_segments = [1, phi_segments].max uvs = [] radius = inner_radius radius_step = ((outer_radius - inner_radius) / phi_segments.to_f) for i in 0..phi_segments do # concentric circles inside ring for o in 0..theta_segments do # number of segments per circle vertex = Vector3.new segment = theta_start + o.to_f / theta_segments.to_f * theta_length vertex.x = radius * ::Math.cos(segment) vertex.y = radius * ::Math.sin(segment) @vertices << vertex uvs << Vector2.new((vertex.x / outer_radius + 1.0) / 2.0, (vertex.y / outer_radius + 1.0) / 2.0) end radius += radius_step end n = Vector3.new(0.0, 0.0, 1.0) for i in 0...phi_segments do # concentric circles inside ring theta_segment = i * (theta_segments + 1) for o in 0...theta_segments do # number of segments per circle segment = o + theta_segment v1 = segment v2 = segment + theta_segments + 1 v3 = segment + theta_segments + 2 @faces << Face3.new(v1, v2, v3, [n.clone, n.clone, n.clone]) @face_vertex_uvs[0] << [uvs[v1].clone, uvs[v2].clone, uvs[v3].clone] v1 = segment v2 = segment + theta_segments + 2 v3 = segment + 1 @faces << Face3.new(v1, v2, v3, [n.clone, n.clone, n.clone]) @face_vertex_uvs[0] << [uvs[v1].clone, uvs[v2].clone, uvs[v3].clone] end end compute_face_normals @bounding_sphere = Sphere.new(Vector3.new, radius) end |
Instance Method Details
#clone ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/mittsu/extras/geometries/ring_geometry.rb', line 69 def clone RingGeometry.new( @parameters[:inner_radius], @parameters[:outer_radius], @parameters[:theta_segments], @parameters[:phi_segments], @parameters[:theta_start], @parameters[:theta_length] ) end |