Class: Rgltf::Material

Inherits:
Properties::Base show all
Defined in:
lib/rgltf/properties/material.rb

Constant Summary collapse

ALPHA_MODES =
{ 'OPAQUE' => :opaque, 'MASK' => :mask, 'BLEND' => :blend }.freeze

Instance Attribute Summary collapse

Attributes inherited from Properties::Base

#extensions, #extras, #index, #name, #owner_type, #source_json

Instance Method Summary collapse

Methods inherited from Properties::Base

#extension, #parse_extensions!

Constructor Details

#initialize(json, document:, index:) ⇒ Material

Returns a new instance of Material.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/rgltf/properties/material.rb', line 68

def initialize(json, document:, index:)
  super(json, document:, index:, owner_type: :material)
  @pbr = PbrMetallicRoughness.new(json.fetch('pbrMetallicRoughness', {}), document:)
  @normal_texture = NormalTextureInfo.new(json['normalTexture'], document:) if json['normalTexture']
  @occlusion_texture = OcclusionTextureInfo.new(json['occlusionTexture'], document:) if json['occlusionTexture']
  @emissive_texture = TextureInfo.new(json['emissiveTexture'], document:) if json['emissiveTexture']
  @emissive_factor = json.fetch('emissiveFactor', [0.0, 0.0, 0.0]).freeze
  @alpha_mode = ALPHA_MODES.fetch(json.fetch('alphaMode', 'OPAQUE'))
  @alpha_cutoff = json.fetch('alphaCutoff', 0.5)
  @alpha_cutoff_explicit = json.key?('alphaCutoff')
  @double_sided = json.fetch('doubleSided', false)
rescue KeyError => e
  raise FormatError, "invalid material #{index}: #{e.message}"
end

Instance Attribute Details

#alpha_cutoffObject (readonly)

Returns the value of attribute alpha_cutoff.



65
66
67
# File 'lib/rgltf/properties/material.rb', line 65

def alpha_cutoff
  @alpha_cutoff
end

#alpha_modeObject (readonly)

Returns the value of attribute alpha_mode.



65
66
67
# File 'lib/rgltf/properties/material.rb', line 65

def alpha_mode
  @alpha_mode
end

#double_sidedObject (readonly)

Returns the value of attribute double_sided.



65
66
67
# File 'lib/rgltf/properties/material.rb', line 65

def double_sided
  @double_sided
end

#emissive_factorObject (readonly)

Returns the value of attribute emissive_factor.



65
66
67
# File 'lib/rgltf/properties/material.rb', line 65

def emissive_factor
  @emissive_factor
end

#emissive_textureObject (readonly)

Returns the value of attribute emissive_texture.



65
66
67
# File 'lib/rgltf/properties/material.rb', line 65

def emissive_texture
  @emissive_texture
end

#normal_textureObject (readonly)

Returns the value of attribute normal_texture.



65
66
67
# File 'lib/rgltf/properties/material.rb', line 65

def normal_texture
  @normal_texture
end

#occlusion_textureObject (readonly)

Returns the value of attribute occlusion_texture.



65
66
67
# File 'lib/rgltf/properties/material.rb', line 65

def occlusion_texture
  @occlusion_texture
end

#pbrObject (readonly)

Returns the value of attribute pbr.



65
66
67
# File 'lib/rgltf/properties/material.rb', line 65

def pbr
  @pbr
end

Instance Method Details

#alpha_cutoff_explicit?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/rgltf/properties/material.rb', line 87

def alpha_cutoff_explicit?
  @alpha_cutoff_explicit
end

#nested_propertiesObject



91
92
93
# File 'lib/rgltf/properties/material.rb', line 91

def nested_properties
  [pbr, normal_texture, occlusion_texture, emissive_texture].compact
end

#unlit?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/rgltf/properties/material.rb', line 83

def unlit?
  extensions.key?('KHR_materials_unlit')
end