Class: Three::Texture

Inherits:
EventDispatcher show all
Includes:
Dirty
Defined in:
lib/three/textures/texture.rb

Direct Known Subclasses

CubeTexture, RGBETexture

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(source = nil, mapping: Three::UVMapping, color_space: Three::NoColorSpace, flip_y: true, wrap_s: Three::ClampToEdgeWrapping, wrap_t: Three::ClampToEdgeWrapping, mag_filter: Three::LinearFilter, min_filter: Three::LinearMipmapLinearFilter, offset: nil, repeat: nil, center: nil, rotation: 0, matrix_auto_update: true, matrix: nil) ⇒ Texture

Returns a new instance of Texture.



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
# File 'lib/three/textures/texture.rb', line 24

def initialize(
  source = nil,
  mapping: Three::UVMapping,
  color_space: Three::NoColorSpace,
  flip_y: true,
  wrap_s: Three::ClampToEdgeWrapping,
  wrap_t: Three::ClampToEdgeWrapping,
  mag_filter: Three::LinearFilter,
  min_filter: Three::LinearMipmapLinearFilter,
  offset: nil,
  repeat: nil,
  center: nil,
  rotation: 0,
  matrix_auto_update: true,
  matrix: nil
)
  super()
  @id = self.class.allocate_id
  @uuid = MathUtils.generate_uuid
  @source = source
  @mapping = mapping
  @color_space = color_space
  @flip_y = flip_y
  @wrap_s = wrap_s
  @wrap_t = wrap_t
  @mag_filter = mag_filter
  @min_filter = min_filter
  @offset = coerce_vector2(offset || [0, 0], field: :offset)
  @repeat = coerce_vector2(repeat || [1, 1], field: :repeat)
  @center = coerce_vector2(center || [0, 0], field: :center)
  @rotation = rotation
  @matrix_auto_update = matrix_auto_update
  @matrix = coerce_matrix3(matrix || Matrix3.new)
  @user_data = {}
  bind_vector_changes
  mark_dirty!
end

Class Attribute Details

.next_idObject

Returns the value of attribute next_id.



17
18
19
# File 'lib/three/textures/texture.rb', line 17

def next_id
  @next_id
end

Instance Attribute Details

#centerObject

Returns the value of attribute center.



21
22
23
# File 'lib/three/textures/texture.rb', line 21

def center
  @center
end

#color_spaceObject

Returns the value of attribute color_space.



20
21
22
# File 'lib/three/textures/texture.rb', line 20

def color_space
  @color_space
end

#flip_yObject

Returns the value of attribute flip_y.



20
21
22
# File 'lib/three/textures/texture.rb', line 20

def flip_y
  @flip_y
end

#idObject (readonly)

Returns the value of attribute id.



20
21
22
# File 'lib/three/textures/texture.rb', line 20

def id
  @id
end

#mag_filterObject

Returns the value of attribute mag_filter.



20
21
22
# File 'lib/three/textures/texture.rb', line 20

def mag_filter
  @mag_filter
end

#mappingObject

Returns the value of attribute mapping.



20
21
22
# File 'lib/three/textures/texture.rb', line 20

def mapping
  @mapping
end

#matrixObject

Returns the value of attribute matrix.



21
22
23
# File 'lib/three/textures/texture.rb', line 21

def matrix
  @matrix
end

#matrix_auto_updateObject

Returns the value of attribute matrix_auto_update.



21
22
23
# File 'lib/three/textures/texture.rb', line 21

def matrix_auto_update
  @matrix_auto_update
end

#min_filterObject

Returns the value of attribute min_filter.



20
21
22
# File 'lib/three/textures/texture.rb', line 20

def min_filter
  @min_filter
end

#offsetObject

Returns the value of attribute offset.



21
22
23
# File 'lib/three/textures/texture.rb', line 21

def offset
  @offset
end

#repeatObject

Returns the value of attribute repeat.



21
22
23
# File 'lib/three/textures/texture.rb', line 21

def repeat
  @repeat
end

#rotationObject

Returns the value of attribute rotation.



21
22
23
# File 'lib/three/textures/texture.rb', line 21

def rotation
  @rotation
end

#sourceObject

Returns the value of attribute source.



20
21
22
# File 'lib/three/textures/texture.rb', line 20

def source
  @source
end

#user_dataObject

Returns the value of attribute user_data.



22
23
24
# File 'lib/three/textures/texture.rb', line 22

def user_data
  @user_data
end

#uuidObject (readonly)

Returns the value of attribute uuid.



20
21
22
# File 'lib/three/textures/texture.rb', line 20

def uuid
  @uuid
end

#wrap_sObject

Returns the value of attribute wrap_s.



20
21
22
# File 'lib/three/textures/texture.rb', line 20

def wrap_s
  @wrap_s
end

#wrap_tObject

Returns the value of attribute wrap_t.



20
21
22
# File 'lib/three/textures/texture.rb', line 20

def wrap_t
  @wrap_t
end

Class Method Details

.allocate_idObject



166
167
168
169
170
# File 'lib/three/textures/texture.rb', line 166

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

Instance Method Details

#disposeObject



141
142
143
# File 'lib/three/textures/texture.rb', line 141

def dispose
  dispatch_event(:dispose)
end

#to_hObject



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/three/textures/texture.rb', line 145

def to_h
  {
    uuid: @uuid,
    type: "Texture",
    source: @source,
    mapping: @mapping,
    color_space: @color_space,
    flip_y: @flip_y,
    wrap_s: @wrap_s,
    wrap_t: @wrap_t,
    mag_filter: @mag_filter,
    min_filter: @min_filter,
    offset: @offset.to_a,
    repeat: @repeat.to_a,
    center: @center.to_a,
    rotation: @rotation,
    matrix_auto_update: @matrix_auto_update,
    matrix: @matrix.to_a
  }
end

#update_matrixObject



135
136
137
138
139
# File 'lib/three/textures/texture.rb', line 135

def update_matrix
  @matrix.set_uv_transform(@offset.x, @offset.y, @repeat.x, @repeat.y, @rotation, @center.x, @center.y)
  mark_dirty!(:parameters)
  self
end