Class: Three::BufferGeometry
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Dirty
#add_dirty_dependent, #dirty?, #dirty_dependents, #dirty_field?, #dirty_fields, #mark_clean!, #mark_dirty!, #remove_dirty_dependent
#add_event_listener, #dispatch_event, #has_event_listener?, #remove_event_listener
Constructor Details
Returns a new instance of BufferGeometry.
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/three/core/buffer_geometry.rb', line 23
def initialize
super()
@id = self.class.allocate_id
@uuid = MathUtils.generate_uuid
@name = ""
@type = "BufferGeometry"
@index = nil
@attributes = {}
@groups = []
@bounding_box = nil
@bounding_sphere = nil
@draw_range = { start: 0, count: Float::INFINITY }
@user_data = {}
mark_dirty!
end
|
Class Attribute Details
.next_id ⇒ Object
Returns the value of attribute next_id.
16
17
18
|
# File 'lib/three/core/buffer_geometry.rb', line 16
def next_id
@next_id
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
20
21
22
|
# File 'lib/three/core/buffer_geometry.rb', line 20
def attributes
@attributes
end
|
#bounding_box ⇒ Object
Returns the value of attribute bounding_box.
21
22
23
|
# File 'lib/three/core/buffer_geometry.rb', line 21
def bounding_box
@bounding_box
end
|
#bounding_sphere ⇒ Object
Returns the value of attribute bounding_sphere.
21
22
23
|
# File 'lib/three/core/buffer_geometry.rb', line 21
def bounding_sphere
@bounding_sphere
end
|
#draw_range ⇒ Object
Returns the value of attribute draw_range.
20
21
22
|
# File 'lib/three/core/buffer_geometry.rb', line 20
def draw_range
@draw_range
end
|
#groups ⇒ Object
Returns the value of attribute groups.
20
21
22
|
# File 'lib/three/core/buffer_geometry.rb', line 20
def groups
@groups
end
|
#id ⇒ Object
Returns the value of attribute id.
19
20
21
|
# File 'lib/three/core/buffer_geometry.rb', line 19
def id
@id
end
|
#index ⇒ Object
Returns the value of attribute index.
20
21
22
|
# File 'lib/three/core/buffer_geometry.rb', line 20
def index
@index
end
|
#name ⇒ Object
Returns the value of attribute name.
20
21
22
|
# File 'lib/three/core/buffer_geometry.rb', line 20
def name
@name
end
|
#type ⇒ Object
Returns the value of attribute type.
20
21
22
|
# File 'lib/three/core/buffer_geometry.rb', line 20
def type
@type
end
|
#user_data ⇒ Object
Returns the value of attribute user_data.
21
22
23
|
# File 'lib/three/core/buffer_geometry.rb', line 21
def user_data
@user_data
end
|
#uuid ⇒ Object
Returns the value of attribute uuid.
19
20
21
|
# File 'lib/three/core/buffer_geometry.rb', line 19
def uuid
@uuid
end
|
Instance Method Details
#add_group(start, count, material_index = 0) ⇒ Object
83
84
85
86
87
|
# File 'lib/three/core/buffer_geometry.rb', line 83
def add_group(start, count, material_index = 0)
@groups << { start: start, count: count, material_index: material_index }
mark_dirty!(:groups)
self
end
|
#center ⇒ Object
Also known as:
center!
102
103
104
105
106
|
# File 'lib/three/core/buffer_geometry.rb', line 102
def center
@centered = true
mark_dirty!(:geometry_operations)
self
end
|
#centered? ⇒ Boolean
110
111
112
|
# File 'lib/three/core/buffer_geometry.rb', line 110
def centered?
@centered == true
end
|
#clear_groups ⇒ Object
89
90
91
92
93
|
# File 'lib/three/core/buffer_geometry.rb', line 89
def clear_groups
@groups.clear
mark_dirty!(:groups)
self
end
|
#compute_bounding_box ⇒ Object
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/three/core/buffer_geometry.rb', line 114
def compute_bounding_box
position = get_attribute(:position)
@bounding_box = nil
return self unless position && position.count.positive?
min = Vector3.new(Float::INFINITY, Float::INFINITY, Float::INFINITY)
max = Vector3.new(-Float::INFINITY, -Float::INFINITY, -Float::INFINITY)
position.count.times do |index|
x = position.get_x(index)
y = position.get_y(index)
z = position.get_z(index)
min.x = [min.x, x].min
min.y = [min.y, y].min
min.z = [min.z, z].min
max.x = [max.x, x].max
max.y = [max.y, y].max
max.z = [max.z, z].max
end
@bounding_box = { min: min, max: max }
self
end
|
#compute_bounding_sphere ⇒ Object
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
# File 'lib/three/core/buffer_geometry.rb', line 138
def compute_bounding_sphere
compute_bounding_box unless @bounding_box
position = get_attribute(:position)
@bounding_sphere = nil
return self unless position && @bounding_box
center = @bounding_box[:min].clone.add(@bounding_box[:max]).multiply_scalar(0.5)
max_radius_sq = 0
position.count.times do |index|
point = Vector3.new(position.get_x(index), position.get_y(index), position.get_z(index))
max_radius_sq = [max_radius_sq, center.distance_to_squared(point)].max
end
@bounding_sphere = { center: center, radius: Math.sqrt(max_radius_sq) }
self
end
|
#delete_attribute(name) ⇒ Object
73
74
75
76
77
|
# File 'lib/three/core/buffer_geometry.rb', line 73
def delete_attribute(name)
@attributes.delete(name.to_sym)
mark_dirty!(:attributes)
self
end
|
#dispose ⇒ Object
156
157
158
|
# File 'lib/three/core/buffer_geometry.rb', line 156
def dispose
dispatch_event(:dispose)
end
|
#get_attribute(name) ⇒ Object
62
63
64
|
# File 'lib/three/core/buffer_geometry.rb', line 62
def get_attribute(name)
@attributes[name.to_sym]
end
|
#get_index ⇒ Object
45
46
47
|
# File 'lib/three/core/buffer_geometry.rb', line 45
def get_index
@index
end
|
#has_attribute?(name) ⇒ Boolean
79
80
81
|
# File 'lib/three/core/buffer_geometry.rb', line 79
def has_attribute?(name)
@attributes.key?(name.to_sym)
end
|
#set_attribute(name, attribute) ⇒ Object
66
67
68
69
70
71
|
# File 'lib/three/core/buffer_geometry.rb', line 66
def set_attribute(name, attribute)
@attributes[name.to_sym] = attribute
bind_attribute_change(attribute)
mark_dirty!(:attributes)
self
end
|
#set_draw_range(start, count) ⇒ Object
95
96
97
98
99
100
|
# File 'lib/three/core/buffer_geometry.rb', line 95
def set_draw_range(start, count)
@draw_range[:start] = start
@draw_range[:count] = count
mark_dirty!(:draw_range)
self
end
|
#set_index(index) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/three/core/buffer_geometry.rb', line 49
def set_index(index)
@index =
if index.is_a?(Array)
attribute_class = index.any? { |value| value > 65_535 } ? Uint32BufferAttribute : Uint16BufferAttribute
attribute_class.new(index, 1)
else
index
end
bind_attribute_change(@index)
mark_dirty!(:index)
self
end
|
#to_h ⇒ Object
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
# File 'lib/three/core/buffer_geometry.rb', line 160
def to_h
{
uuid: @uuid,
type: @type,
name: @name,
index: @index&.to_h,
attributes: @attributes.transform_values(&:to_h),
groups: @groups.map(&:dup),
draw_range: serialize_draw_range(@draw_range),
bounding_box: serialize_bounds(@bounding_box),
bounding_sphere: serialize_sphere(@bounding_sphere),
user_data: @user_data
}
end
|