Class: Assimp::Material

Inherits:
Object
  • Object
show all
Defined in:
lib/assimp/material.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, base_color:, metallic:, roughness:, shininess:, opacity:, two_sided:, textures:, properties:) ⇒ Material

Returns a new instance of Material.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/assimp/material.rb', line 9

def initialize(name:, base_color:, metallic:, roughness:, shininess:, opacity:, two_sided:,
               textures:, properties:)
  @name = String(name).dup.freeze
  @base_color = base_color&.map { |value| Float(value) }&.freeze
  @metallic = metallic.nil? ? nil : Float(metallic)
  @roughness = roughness.nil? ? nil : Float(roughness)
  @shininess = shininess.nil? ? nil : Float(shininess)
  @opacity = opacity.nil? ? nil : Float(opacity)
  @two_sided = !!two_sided
  @textures = textures.freeze
  @properties = properties.freeze
  freeze
end

Instance Attribute Details

#base_colorObject (readonly)

Returns the value of attribute base_color.



7
8
9
# File 'lib/assimp/material.rb', line 7

def base_color
  @base_color
end

#metallicObject (readonly)

Returns the value of attribute metallic.



7
8
9
# File 'lib/assimp/material.rb', line 7

def metallic
  @metallic
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/assimp/material.rb', line 7

def name
  @name
end

#opacityObject (readonly)

Returns the value of attribute opacity.



7
8
9
# File 'lib/assimp/material.rb', line 7

def opacity
  @opacity
end

#roughnessObject (readonly)

Returns the value of attribute roughness.



7
8
9
# File 'lib/assimp/material.rb', line 7

def roughness
  @roughness
end

#shininessObject (readonly)

Returns the value of attribute shininess.



7
8
9
# File 'lib/assimp/material.rb', line 7

def shininess
  @shininess
end

Instance Method Details

#[](key, semantic: 0, index: 0) ⇒ Object



49
50
51
# File 'lib/assimp/material.rb', line 49

def [](key, semantic: 0, index: 0)
  @properties[[String(key), Integer(semantic), Integer(index)]]
end

#propertiesObject



53
54
55
# File 'lib/assimp/material.rb', line 53

def properties
  @properties.dup.freeze
end

#texture(type, index: 0) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/assimp/material.rb', line 27

def texture(type, index: 0)
  kind = type.to_sym
  texture_index = Integer(index)
  direct = @textures[[kind, texture_index]]
  return direct if direct

  fallback_types(kind).each do |fallback|
    reference = @textures[[fallback, texture_index]]
    return reference if reference
  end
  nil
end

#textures(type = nil) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/assimp/material.rb', line 40

def textures(type = nil)
  return @textures.dup.freeze unless type

  kind = type.to_sym
  @textures.each_with_object([]) do |((texture_type, _index), texture), matches|
    matches << texture if texture_type == kind
  end.freeze
end

#two_sided?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/assimp/material.rb', line 23

def two_sided?
  @two_sided
end