Class: Mittsu::BoxGeometry

Inherits:
Geometry show all
Defined in:
lib/mittsu/extras/geometries/box_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

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(width, height, depth, width_segments = nil, height_segments = nil, depth_segments = nil) ⇒ BoxGeometry

Returns a new instance of BoxGeometry.



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
# File 'lib/mittsu/extras/geometries/box_geometry.rb', line 6

def initialize(width, height, depth, width_segments = nil, height_segments = nil, depth_segments = nil)
  super()

  @type = 'BoxGeometry'

  @parameters = {
    width: width,
    height: height,
    depth: depth,
    width_segments: width_segments,
    height_segments: height_segments,
    depth_segments: depth_segments
  }

  @width_segments = width_segments || 1
  @height_segments = height_segments || 1
  @depth_segments = depth_segments || 1

  width_half = width / 2.0
  height_half = height / 2.0
  depth_half = depth / 2.0

  build_plane(:z, :y, -1, -1, depth.to_f, height.to_f, width_half,   0) # px
  build_plane(:z, :y,  1, -1, depth.to_f, height.to_f, -width_half,  1) # nx
  build_plane(:x, :z,  1,  1, width.to_f, depth.to_f,  height_half,  2) # py
  build_plane(:x, :z,  1, -1, width.to_f, depth.to_f,  -height_half, 3) # ny
  build_plane(:x, :y,  1, -1, width.to_f, height.to_f, depth_half,   4) # pz
  build_plane(:x, :y, -1, -1, width.to_f, height.to_f, -depth_half,  5) # nz

  merge_vertices
end