Class: Three::BufferAttribute

Inherits:
EventDispatcher show all
Includes:
Dirty
Defined in:
lib/three/core/buffer_attribute.rb

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

Methods inherited from EventDispatcher

#add_event_listener, #dispatch_event, #has_event_listener?, #remove_event_listener

Constructor Details

#initialize(array, item_size, normalized = false, component_type: :generic) ⇒ BufferAttribute

Returns a new instance of BufferAttribute.



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/three/core/buffer_attribute.rb', line 20

def initialize(array, item_size, normalized = false, component_type: :generic)
  super()
  @id = self.class.allocate_id
  @name = ""
  @array = array.dup
  @item_size = item_size
  @normalized = normalized
  @usage = :static_draw
  @update_ranges = []
  @version = 0
  @component_type = component_type
  mark_dirty!
end

Class Attribute Details

.next_idObject

Returns the value of attribute next_id.



13
14
15
# File 'lib/three/core/buffer_attribute.rb', line 13

def next_id
  @next_id
end

Instance Attribute Details

#arrayObject

Returns the value of attribute array.



17
18
19
# File 'lib/three/core/buffer_attribute.rb', line 17

def array
  @array
end

#component_typeObject

Returns the value of attribute component_type.



18
19
20
# File 'lib/three/core/buffer_attribute.rb', line 18

def component_type
  @component_type
end

#idObject (readonly)

Returns the value of attribute id.



16
17
18
# File 'lib/three/core/buffer_attribute.rb', line 16

def id
  @id
end

#item_sizeObject

Returns the value of attribute item_size.



17
18
19
# File 'lib/three/core/buffer_attribute.rb', line 17

def item_size
  @item_size
end

#nameObject

Returns the value of attribute name.



17
18
19
# File 'lib/three/core/buffer_attribute.rb', line 17

def name
  @name
end

#normalizedObject

Returns the value of attribute normalized.



17
18
19
# File 'lib/three/core/buffer_attribute.rb', line 17

def normalized
  @normalized
end

#update_rangesObject

Returns the value of attribute update_ranges.



17
18
19
# File 'lib/three/core/buffer_attribute.rb', line 17

def update_ranges
  @update_ranges
end

#usageObject

Returns the value of attribute usage.



17
18
19
# File 'lib/three/core/buffer_attribute.rb', line 17

def usage
  @usage
end

#versionObject

Returns the value of attribute version.



17
18
19
# File 'lib/three/core/buffer_attribute.rb', line 17

def version
  @version
end

Class Method Details

.allocate_idObject



34
35
36
37
38
# File 'lib/three/core/buffer_attribute.rb', line 34

def self.allocate_id
  id = BufferAttribute.next_id
  BufferAttribute.next_id += 1
  id
end

Instance Method Details

#add_update_range(start, count) ⇒ Object



63
64
65
66
67
# File 'lib/three/core/buffer_attribute.rb', line 63

def add_update_range(start, count)
  @update_ranges << { start: start, count: count }
  mark_dirty!(:update_ranges)
  self
end

#clear_update_rangesObject



69
70
71
72
73
# File 'lib/three/core/buffer_attribute.rb', line 69

def clear_update_ranges
  @update_ranges.clear
  mark_dirty!(:update_ranges)
  self
end

#cloneObject



86
87
88
# File 'lib/three/core/buffer_attribute.rb', line 86

def clone
  self.class.new(@array, @item_size, @normalized)
end

#copy(source) ⇒ Object



75
76
77
78
79
80
81
82
83
84
# File 'lib/three/core/buffer_attribute.rb', line 75

def copy(source)
  @name = source.name
  @array = source.array.dup
  @item_size = source.item_size
  @normalized = source.normalized
  @usage = source.usage
  @component_type = source.component_type
  needs_update!
  self
end

#countObject



40
41
42
# File 'lib/three/core/buffer_attribute.rb', line 40

def count
  @array.length / @item_size
end

#get_component(index, component) ⇒ Object



90
91
92
# File 'lib/three/core/buffer_attribute.rb', line 90

def get_component(index, component)
  @array[index * @item_size + component]
end

#get_x(index) ⇒ Object



100
101
102
# File 'lib/three/core/buffer_attribute.rb', line 100

def get_x(index)
  get_component(index, 0)
end

#get_y(index) ⇒ Object



104
105
106
# File 'lib/three/core/buffer_attribute.rb', line 104

def get_y(index)
  get_component(index, 1)
end

#get_z(index) ⇒ Object



108
109
110
# File 'lib/three/core/buffer_attribute.rb', line 108

def get_z(index)
  get_component(index, 2)
end

#needs_update!Object



50
51
52
53
54
55
# File 'lib/three/core/buffer_attribute.rb', line 50

def needs_update!
  @version += 1
  mark_dirty!(:array)
  dispatch_event(:change)
  self
end

#needs_update=(value) ⇒ Object



44
45
46
47
48
# File 'lib/three/core/buffer_attribute.rb', line 44

def needs_update=(value)
  return unless value

  needs_update!
end

#set_component(index, component, value) ⇒ Object



94
95
96
97
98
# File 'lib/three/core/buffer_attribute.rb', line 94

def set_component(index, component, value)
  @array[index * @item_size + component] = value
  needs_update!
  self
end

#set_usage(value) ⇒ Object



57
58
59
60
61
# File 'lib/three/core/buffer_attribute.rb', line 57

def set_usage(value)
  @usage = value
  mark_dirty!(:usage)
  self
end

#set_x(index, value) ⇒ Object



112
113
114
# File 'lib/three/core/buffer_attribute.rb', line 112

def set_x(index, value)
  set_component(index, 0, value)
end

#set_y(index, value) ⇒ Object



116
117
118
# File 'lib/three/core/buffer_attribute.rb', line 116

def set_y(index, value)
  set_component(index, 1, value)
end

#set_z(index, value) ⇒ Object



120
121
122
# File 'lib/three/core/buffer_attribute.rb', line 120

def set_z(index, value)
  set_component(index, 2, value)
end

#to_hObject



124
125
126
127
128
129
130
131
# File 'lib/three/core/buffer_attribute.rb', line 124

def to_h
  {
    item_size: @item_size,
    component_type: @component_type,
    normalized: @normalized,
    array: @array.dup
  }
end