Class: Three::Material

Inherits:
EventDispatcher show all
Includes:
Dirty
Defined in:
lib/three/materials/material.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(parameters = nil) ⇒ Material

Returns a new instance of Material.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/three/materials/material.rb', line 22

def initialize(parameters = nil)
  super()
  @id = self.class.allocate_id
  @uuid = MathUtils.generate_uuid
  @name = ""
  @type = "Material"
  @blending = NormalBlending
  @side = FrontSide
  @vertex_colors = false
  @opacity = 1
  @transparent = false
  @visible = true
  @user_data = {}
  @needs_update = false
  set_values(parameters) if parameters
  mark_dirty!
end

Class Attribute Details

.next_idObject

Returns the value of attribute next_id.



15
16
17
# File 'lib/three/materials/material.rb', line 15

def next_id
  @next_id
end

Instance Attribute Details

#blendingObject

Returns the value of attribute blending.



19
20
21
# File 'lib/three/materials/material.rb', line 19

def blending
  @blending
end

#idObject (readonly)

Returns the value of attribute id.



18
19
20
# File 'lib/three/materials/material.rb', line 18

def id
  @id
end

#nameObject

Returns the value of attribute name.



19
20
21
# File 'lib/three/materials/material.rb', line 19

def name
  @name
end

#opacityObject

Returns the value of attribute opacity.



19
20
21
# File 'lib/three/materials/material.rb', line 19

def opacity
  @opacity
end

#sideObject

Returns the value of attribute side.



19
20
21
# File 'lib/three/materials/material.rb', line 19

def side
  @side
end

#transparentObject

Returns the value of attribute transparent.



19
20
21
# File 'lib/three/materials/material.rb', line 19

def transparent
  @transparent
end

#typeObject

Returns the value of attribute type.



19
20
21
# File 'lib/three/materials/material.rb', line 19

def type
  @type
end

#user_dataObject

Returns the value of attribute user_data.



20
21
22
# File 'lib/three/materials/material.rb', line 20

def user_data
  @user_data
end

#uuidObject (readonly)

Returns the value of attribute uuid.



18
19
20
# File 'lib/three/materials/material.rb', line 18

def uuid
  @uuid
end

#vertex_colorsObject

Returns the value of attribute vertex_colors.



19
20
21
# File 'lib/three/materials/material.rb', line 19

def vertex_colors
  @vertex_colors
end

#visibleObject

Returns the value of attribute visible.



19
20
21
# File 'lib/three/materials/material.rb', line 19

def visible
  @visible
end

Class Method Details

.allocate_idObject



94
95
96
97
98
# File 'lib/three/materials/material.rb', line 94

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

Instance Method Details

#dirty_dependency_changed(_resource, _field) ⇒ Object



119
120
121
# File 'lib/three/materials/material.rb', line 119

def dirty_dependency_changed(_resource, _field)
  mark_dirty!(:textures)
end

#disposeObject



115
116
117
# File 'lib/three/materials/material.rb', line 115

def dispose
  dispatch_event(:dispose)
end

#needs_updateObject



80
81
82
# File 'lib/three/materials/material.rb', line 80

def needs_update
  @needs_update
end

#needs_update!Object



89
90
91
92
# File 'lib/three/materials/material.rb', line 89

def needs_update!
  self.needs_update = true
  self
end

#needs_update=(value) ⇒ Object



84
85
86
87
# File 'lib/three/materials/material.rb', line 84

def needs_update=(value)
  @needs_update = value
  mark_dirty!(:parameters) if value
end

#set_values(values) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/three/materials/material.rb', line 100

def set_values(values)
  values.each do |key, value|
    setter = "#{key}="
    next unless respond_to?(setter)

    current_value = public_send(key) if respond_to?(key)
    if current_value.respond_to?(:set)
      current_value.set(value)
    else
      public_send(setter, value)
    end
  end
  self
end

#texture_slotsObject



123
124
125
# File 'lib/three/materials/material.rb', line 123

def texture_slots
  respond_to?(:map) ? [:map] : []
end

#texturesObject



127
128
129
130
131
132
# File 'lib/three/materials/material.rb', line 127

def textures
  texture_slots.each_with_object([]) do |slot, result|
    texture = public_send(slot)
    result << texture if texture && !result.include?(texture)
  end
end

#to_hObject



134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/three/materials/material.rb', line 134

def to_h
  {
    uuid: @uuid,
    type: @type,
    name: @name,
    side: @side,
    opacity: @opacity,
    transparent: @transparent,
    visible: @visible,
    vertex_colors: @vertex_colors
  }
end