Class: Three::MeshPhysicalMaterial

Inherits:
MeshStandardMaterial show all
Defined in:
lib/three/materials/mesh_physical_material.rb

Constant Summary collapse

PHYSICAL_TEXTURE_SLOTS =
%i[
  anisotropy_map
  clearcoat_map
  clearcoat_normal_map
  clearcoat_roughness_map
  transmission_map
  thickness_map
  iridescence_map
  iridescence_thickness_map
  sheen_color_map
  sheen_roughness_map
  specular_color_map
  specular_intensity_map
].freeze
TEXTURE_SLOTS =
(MeshStandardMaterial::TEXTURE_SLOTS + PHYSICAL_TEXTURE_SLOTS).freeze

Instance Attribute Summary collapse

Attributes inherited from MeshStandardMaterial

#color, #flat_shading, #fog, #metalness, #roughness, #wireframe, #wireframe_linewidth

Attributes inherited from Material

#blending, #id, #name, #opacity, #side, #transparent, #type, #user_data, #uuid, #vertex_colors, #visible

Instance Method Summary collapse

Methods inherited from MeshStandardMaterial

#alpha_map=, #ao_map=, #bump_map=, #displacement_map=, #emissive_map=, #env_map=, #light_map=, #map=, #metalness_map=, #normal_map=, #roughness_map=

Methods inherited from Material

allocate_id, #dirty_dependency_changed, #dispose, #needs_update, #needs_update!, #needs_update=, #set_values, #textures

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) ⇒ MeshPhysicalMaterial

Returns a new instance of MeshPhysicalMaterial.



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
# File 'lib/three/materials/mesh_physical_material.rb', line 30

def initialize(parameters = nil)
  super(nil)
  @type = "MeshPhysicalMaterial"
  @anisotropy = 0
  @anisotropy_rotation = 0
  @clearcoat = 0
  @clearcoat_roughness = 0
  @transmission = 0
  @thickness = 0
  @ior = 1.5
  @iridescence = 0
  @iridescence_ior = 1.3
  @iridescence_thickness_range = [100, 400]
  @sheen = 0
  @sheen_color = Color.new(0x000000)
  @sheen_roughness = 1
  @dispersion = 0
  @specular_intensity = 1
  @specular_color = Color.new(0xffffff)
  @attenuation_distance = nil
  @attenuation_color = Color.new(0xffffff)
  PHYSICAL_TEXTURE_SLOTS.each { |slot| instance_variable_set(:"@#{slot}", nil) }
  bind_physical_color_changes
  set_values(parameters) if parameters
  mark_dirty!
end

Instance Attribute Details

#anisotropyObject (readonly)

Returns the value of attribute anisotropy.



25
26
27
# File 'lib/three/materials/mesh_physical_material.rb', line 25

def anisotropy
  @anisotropy
end

#anisotropy_rotationObject (readonly)

Returns the value of attribute anisotropy_rotation.



25
26
27
# File 'lib/three/materials/mesh_physical_material.rb', line 25

def anisotropy_rotation
  @anisotropy_rotation
end

#attenuation_colorObject

Returns the value of attribute attenuation_color.



27
28
29
# File 'lib/three/materials/mesh_physical_material.rb', line 27

def attenuation_color
  @attenuation_color
end

#attenuation_distanceObject (readonly)

Returns the value of attribute attenuation_distance.



27
28
29
# File 'lib/three/materials/mesh_physical_material.rb', line 27

def attenuation_distance
  @attenuation_distance
end

#clearcoatObject (readonly)

Returns the value of attribute clearcoat.



25
26
27
# File 'lib/three/materials/mesh_physical_material.rb', line 25

def clearcoat
  @clearcoat
end

#clearcoat_roughnessObject (readonly)

Returns the value of attribute clearcoat_roughness.



25
26
27
# File 'lib/three/materials/mesh_physical_material.rb', line 25

def clearcoat_roughness
  @clearcoat_roughness
end

#dispersionObject (readonly)

Returns the value of attribute dispersion.



27
28
29
# File 'lib/three/materials/mesh_physical_material.rb', line 27

def dispersion
  @dispersion
end

#iorObject (readonly)

Returns the value of attribute ior.



25
26
27
# File 'lib/three/materials/mesh_physical_material.rb', line 25

def ior
  @ior
end

#iridescenceObject (readonly)

Returns the value of attribute iridescence.



26
27
28
# File 'lib/three/materials/mesh_physical_material.rb', line 26

def iridescence
  @iridescence
end

#iridescence_iorObject (readonly)

Returns the value of attribute iridescence_ior.



26
27
28
# File 'lib/three/materials/mesh_physical_material.rb', line 26

def iridescence_ior
  @iridescence_ior
end

#iridescence_thickness_rangeObject

Returns the value of attribute iridescence_thickness_range.



26
27
28
# File 'lib/three/materials/mesh_physical_material.rb', line 26

def iridescence_thickness_range
  @iridescence_thickness_range
end

#sheenObject (readonly)

Returns the value of attribute sheen.



26
27
28
# File 'lib/three/materials/mesh_physical_material.rb', line 26

def sheen
  @sheen
end

#sheen_colorObject

Returns the value of attribute sheen_color.



26
27
28
# File 'lib/three/materials/mesh_physical_material.rb', line 26

def sheen_color
  @sheen_color
end

#sheen_roughnessObject (readonly)

Returns the value of attribute sheen_roughness.



26
27
28
# File 'lib/three/materials/mesh_physical_material.rb', line 26

def sheen_roughness
  @sheen_roughness
end

#specular_colorObject

Returns the value of attribute specular_color.



27
28
29
# File 'lib/three/materials/mesh_physical_material.rb', line 27

def specular_color
  @specular_color
end

#specular_intensityObject (readonly)

Returns the value of attribute specular_intensity.



27
28
29
# File 'lib/three/materials/mesh_physical_material.rb', line 27

def specular_intensity
  @specular_intensity
end

#thicknessObject (readonly)

Returns the value of attribute thickness.



25
26
27
# File 'lib/three/materials/mesh_physical_material.rb', line 25

def thickness
  @thickness
end

#transmissionObject (readonly)

Returns the value of attribute transmission.



25
26
27
# File 'lib/three/materials/mesh_physical_material.rb', line 25

def transmission
  @transmission
end

Instance Method Details

#reflectivityObject



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

def reflectivity
  MathUtils.clamp(2.5 * (@ior - 1) / (@ior + 1), 0, 1)
end

#reflectivity=(value) ⇒ Object



88
89
90
91
92
93
# File 'lib/three/materials/mesh_physical_material.rb', line 88

def reflectivity=(value)
  return if value.nil?

  @ior = (1 + 0.4 * value) / (1 - 0.4 * value)
  mark_dirty!(:parameters)
end

#texture_slotsObject



117
118
119
# File 'lib/three/materials/mesh_physical_material.rb', line 117

def texture_slots
  TEXTURE_SLOTS
end

#to_hObject



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/three/materials/mesh_physical_material.rb', line 121

def to_h
  result = super.merge(
    anisotropy: @anisotropy,
    anisotropy_rotation: @anisotropy_rotation,
    clearcoat: @clearcoat,
    clearcoat_roughness: @clearcoat_roughness,
    transmission: @transmission,
    thickness: @thickness,
    ior: @ior,
    reflectivity: reflectivity,
    iridescence: @iridescence,
    iridescence_ior: @iridescence_ior,
    iridescence_thickness_range: @iridescence_thickness_range&.dup,
    sheen: @sheen,
    sheen_color: @sheen_color.hex,
    sheen_roughness: @sheen_roughness,
    dispersion: @dispersion,
    specular_intensity: @specular_intensity,
    specular_color: @specular_color.hex,
    attenuation_distance: @attenuation_distance,
    attenuation_color: @attenuation_color.hex
  )
  PHYSICAL_TEXTURE_SLOTS.each { |slot| result[slot] = public_send(slot)&.to_h }
  result
end