Class: Assimp::MeshCopier

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

Constant Summary collapse

VECTOR_SIZE =
Native::Vector3D.size
UV_BATCH_SIZE =
1024
PRIMITIVES =
{
  0x1 => :points,
  0x2 => :lines,
  0x4 => :triangles,
  0x8 => :polygons
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(native: Native) ⇒ MeshCopier

Returns a new instance of MeshCopier.



14
15
16
# File 'lib/assimp/mesh_copier.rb', line 14

def initialize(native: Native)
  @bone_type = native.version[1].zero? ? Native::LegacyBone : Native::Bone
end

Instance Method Details

#copy(pointer) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/assimp/mesh_copier.rb', line 18

def copy(pointer)
  source = Native::Mesh.new(pointer)
  vertex_count = source[:num_vertices]
  positions = NativeReader.bytes(source[:vertices], VECTOR_SIZE * vertex_count)
  normals = optional_vectors(source[:normals], vertex_count)

  Mesh.new(
    name: source[:name].to_s,
    material_index: source[:material_index],
    primitive: primitive(source[:primitive_types]),
    positions:,
    normals:,
    tangents: copy_tangents(source, normals, vertex_count),
    uv_sets: copy_uv_sets(source, vertex_count),
    colors: optional_colors(source[:colors][0], vertex_count),
    indices: copy_indices(source, vertex_count),
    bones: copy_bones(source),
    vertex_count:,
    aabb: bounds(positions, vertex_count)
  )
end