Class: Assimp::MaterialCopier

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

Constant Summary collapse

PROPERTY_FLOAT =
0x1
PROPERTY_DOUBLE =
0x2
PROPERTY_STRING =
0x3
PROPERTY_INTEGER =
0x4
PROPERTY_BUFFER =
0x5
TEXTURE_TYPES =
{
  diffuse: 1, specular: 2, ambient: 3, emissive: 4, height: 5, normals: 6,
  shininess: 7, opacity: 8, displacement: 9, lightmap: 10, reflection: 11,
  base_color: 12, normal_camera: 13, emission_color: 14, metalness: 15,
  roughness: 16, ao: 17, unknown: 18, sheen: 19, clearcoat: 20, transmission: 21
}.freeze
WRAP_MODES =
{ 0 => :wrap, 1 => :clamp, 2 => :mirror, 3 => :decal }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(native: Native, embedded_textures: []) ⇒ MaterialCopier

Returns a new instance of MaterialCopier.



19
20
21
22
# File 'lib/assimp/material_copier.rb', line 19

def initialize(native: Native, embedded_textures: [])
  @native = native
  @embedded_texture_indices = embedded_texture_indices(embedded_textures)
end

Instance Method Details

#copy(pointer) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/assimp/material_copier.rb', line 24

def copy(pointer)
  properties = copy_properties(pointer)
  textures = copy_textures(pointer)
  shininess = scalar(properties, "$mat.shininess")
  Material.new(
    name: properties.fetch(["?mat.name", 0, 0], ""),
    base_color: color(properties, "$clr.base") || color(properties, "$clr.diffuse") || [1.0, 1.0, 1.0, 1.0],
    metallic: scalar(properties, "$mat.metallicFactor") || texture_default(textures, :metalness, 0.0),
    roughness: scalar(properties, "$mat.roughnessFactor") ||
               texture_default(textures, :roughness, roughness_from(shininess)),
    shininess:,
    opacity: scalar(properties, "$mat.opacity") || 1.0,
    two_sided: (scalar(properties, "$mat.twosided") || 0).to_i != 0,
    textures:,
    properties:
  )
end