Class: Rgltf::Material
- Inherits:
-
Properties::Base
- Object
- Properties::Base
- Rgltf::Material
- Defined in:
- lib/rgltf/properties/material.rb
Constant Summary collapse
- ALPHA_MODES =
{ 'OPAQUE' => :opaque, 'MASK' => :mask, 'BLEND' => :blend }.freeze
Instance Attribute Summary collapse
-
#alpha_cutoff ⇒ Object
readonly
Returns the value of attribute alpha_cutoff.
-
#alpha_mode ⇒ Object
readonly
Returns the value of attribute alpha_mode.
-
#double_sided ⇒ Object
readonly
Returns the value of attribute double_sided.
-
#emissive_factor ⇒ Object
readonly
Returns the value of attribute emissive_factor.
-
#emissive_texture ⇒ Object
readonly
Returns the value of attribute emissive_texture.
-
#normal_texture ⇒ Object
readonly
Returns the value of attribute normal_texture.
-
#occlusion_texture ⇒ Object
readonly
Returns the value of attribute occlusion_texture.
-
#pbr ⇒ Object
readonly
Returns the value of attribute pbr.
Attributes inherited from Properties::Base
#extensions, #extras, #index, #name, #owner_type, #source_json
Instance Method Summary collapse
- #alpha_cutoff_explicit? ⇒ Boolean
-
#initialize(json, document:, index:) ⇒ Material
constructor
A new instance of Material.
- #nested_properties ⇒ Object
- #unlit? ⇒ Boolean
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.}" end |
Instance Attribute Details
#alpha_cutoff ⇒ Object (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_mode ⇒ Object (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_sided ⇒ Object (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_factor ⇒ Object (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_texture ⇒ Object (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_texture ⇒ Object (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_texture ⇒ Object (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 |
#pbr ⇒ Object (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
87 88 89 |
# File 'lib/rgltf/properties/material.rb', line 87 def alpha_cutoff_explicit? @alpha_cutoff_explicit end |
#nested_properties ⇒ Object
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
83 84 85 |
# File 'lib/rgltf/properties/material.rb', line 83 def unlit? extensions.key?('KHR_materials_unlit') end |