Class: Mittsu::PointCloud

Inherits:
Object3D show all
Defined in:
lib/mittsu/objects/point_cloud.rb,
lib/mittsu/renderers/opengl/objects/point_cloud.rb

Constant Summary

Constants inherited from Object3D

Object3D::DefaultUp

Instance Attribute Summary collapse

Attributes inherited from Object3D

#active, #cast_shadow, #children, #frustum_culled, #id, #initted, #matrix, #matrix_auto_update, #matrix_world, #matrix_world_needs_update, #model_view_matrix, #morph_target_influences, #name, #parent, #position, #quaternion, #receive_shadow, #render_order, #renderer, #rotation, #rotation_auto_update, #scale, #type, #up, #user_data, #uuid, #visible

Instance Method Summary collapse

Methods inherited from Object3D

#active?, #add, #apply_matrix, #buffer_material, #deinit, #get_object_by_id, #get_object_by_name, #get_object_by_property, #get_world_direction, #get_world_position, #get_world_quaternion, #get_world_rotation, #get_world_scale, #init, #load_uniforms_matrices, #local_to_world, #look_at, #print_tree, #project, #remove, #rotate_on_axis, #rotate_x, #rotate_y, #rotate_z, #set_rotation_from_axis_angle, #set_rotation_from_euler, #set_rotation_from_matrix, #set_rotation_from_quaternion, #setup_matrices, #to_json, #to_s, #translate_on_axis, #translate_x, #translate_y, #translate_z, #traverse, #traverse_ancestors, #traverse_visible, #update_matrix, #update_matrix_world, #world_to_local

Methods included from EventDispatcher

#add_event_listener, #dispatch_event, #has_event_listener, #remove_event_listener

Constructor Details

#initialize(geometry = Geometry.new, material = PointCloudMaterial.new(color: rand * 0xffffff)) ⇒ PointCloud

Returns a new instance of PointCloud.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/mittsu/objects/point_cloud.rb', line 5

def initialize(geometry = Geometry.new, material = PointCloudMaterial.new(color: rand * 0xffffff))
  super()

  @type = 'PointCloud'

  @geometry = geometry
  @material = material

  @_inverse_matrix = Matrix4.new
  @_ray = Ray.new
end

Instance Attribute Details

#geometryObject

Returns the value of attribute geometry.



3
4
5
# File 'lib/mittsu/objects/point_cloud.rb', line 3

def geometry
  @geometry
end

#materialObject

Returns the value of attribute material.



3
4
5
# File 'lib/mittsu/objects/point_cloud.rb', line 3

def material
  @material
end

Instance Method Details

#add_opengl_objectObject



35
36
37
# File 'lib/mittsu/renderers/opengl/objects/point_cloud.rb', line 35

def add_opengl_object
  @renderer.add_opengl_object(geometry, self)
end

#clone(object = PointCloud.new(@geometry, @material)) ⇒ Object



76
77
78
# File 'lib/mittsu/objects/point_cloud.rb', line 76

def clone(object = PointCloud.new(@geometry, @material))
  super(object)
end

#init_geometryObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/mittsu/renderers/opengl/objects/point_cloud.rb', line 24

def init_geometry
  geometry.renderer = @renderer
  if geometry.vertex_buffer.nil?
    geometry.create_particle_buffers
    geometry.init_particle_buffers(self)

    geometry.vertices_need_update = true
    geometry.colors_need_update = true
  end
end

#raycast(raycaster, intersects) ⇒ Object



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
71
72
73
74
# File 'lib/mittsu/objects/point_cloud.rb', line 17

def raycast(raycaster, intersects)
  threshold = raycaster.params[:point_cloud][:threshold]
  @_inverse_matrix.inverse(self.materix_world)
  @_ray.copy(raycaster.ray).apply_matrix4(@_inverse_matrix)

  if !geometry.bounding_box.nil?
    return if ray.intersection_box?(geometry.bounding_box) == false
  end

  local_threshold = threshold / ((self.scale.x + self.scale.y + self.scale.z) / 3.0)
  position = Vector3.new

  if geometry.is_a?(BufferGeometry)
    attributes = geometry.attributes
    positions = attributes.position.array

    if !attributes[:index].nil?
      indices = attributes[:index][:array]
      offsets = geometry.compute_offsets

      if offsets.empty?
        offsets = [{
          start: 0,
          count: indices.length,
          index: 0
        }]
      end

      offsets.each do |offset|
        start = offset[:start]
        count = offset[:count]
        index = offset[:index]

        (start...start+count).each do |i|
          a = index + indices[i]
          position.from_array(positions, a * 3)
          test_point(position, a, local_threshold, raycaster, intersects)
        end
      end
    else
      point_count = positions.count / 3

      point_count.times do |i|
        position.set(
          positions[3 * i],
          positions[3 * i + 1],
          positions[3 * i + 2]
        )

        test_point(position, i, local_threshold, raycaster, intersects)
      end
    end
  else
    geometry.vertices.each_with_index do |vertex, i|
      test_point(vertex, i, local_threshold, raycaster, intersects)
    end
  end
end

#render_buffer(camera, lights, fog, material, geometry_group, update_buffers) ⇒ Object



3
4
5
6
7
8
# File 'lib/mittsu/renderers/opengl/objects/point_cloud.rb', line 3

def render_buffer(camera, lights, fog, material, geometry_group, update_buffers)
  glDrawArrays(GL_POINTS, 0, geometry_group.particle_count)

  @renderer.info[:render][:calls] += 1
  @renderer.info[:render][:points] += geometry_group.particle_count
end

#updateObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/mittsu/renderers/opengl/objects/point_cloud.rb', line 10

def update
			material = buffer_material(geometry)
			custom_attributes_dirty = material.attributes &&  material.custom_attributes_dirty?

			if geometry.vertices_need_update || geometry.colors_need_update || custom_attributes_dirty
geometry.set_particle_buffers(GL_DYNAMIC_DRAW)
			end

			geometry.vertices_need_update = false
			geometry.colors_need_update = false

  material.attributes && material.clear_custom_attributes
end