Module: Assimp::Native

Extended by:
FFI::Library
Defined in:
lib/assimp/native.rb,
lib/assimp/native/types.rb,
lib/assimp/native/platform.rb,
lib/assimp/native/generated.rb

Defined Under Namespace

Modules: Platform Classes: AABB, AnimMesh, Animation, Bone, Buffer, Camera, Color3D, Color4D, Face, ImporterDesc, LegacyBone, LegacyQuatKey, LegacyVectorKey, Light, LogStream, Material, MaterialProperty, Matrix3x3, Matrix4x4, MemoryInfo, Mesh, MeshAnim, MeshKey, MeshMorphAnim, MeshMorphKey, Metadata, MetadataEntry, Node, NodeAnim, Plane, PropertyStore, QuatKey, Quaternion, Ray, Scene, Skeleton, SkeletonBone, StringValue, Texel, Texture, UVTransform, Vector2D, Vector3D, VectorKey, VertexWeight

Constant Summary collapse

ENVIRONMENT_KEY =
"ASSIMP_LIBRARY_PATH"
REQUIRED_MAJOR =
5
LOAD_MUTEX =
Mutex.new
ENUMS =
{
  "aiAnimBehaviour" => { "aiAnimBehaviour_DEFAULT" => 0, "aiAnimBehaviour_CONSTANT" => 1, "aiAnimBehaviour_LINEAR" => 2, "aiAnimBehaviour_REPEAT" => 3, "_aiAnimBehaviour_Force32Bit" => 2147483647 }.freeze,
  "aiAnimInterpolation" => { "aiAnimInterpolation_Step" => 0, "aiAnimInterpolation_Linear" => 1, "aiAnimInterpolation_Spherical_Linear" => 2, "aiAnimInterpolation_Cubic_Spline" => 3, "_aiAnimInterpolation_Force32Bit" => 2147483647 }.freeze,
  "aiBlendMode" => { "aiBlendMode_Default" => 0, "aiBlendMode_Additive" => 1, "_aiBlendMode_Force32Bit" => 2147483647 }.freeze,
  "aiDefaultLogStream" => { "aiDefaultLogStream_FILE" => 1, "aiDefaultLogStream_STDOUT" => 2, "aiDefaultLogStream_STDERR" => 4, "aiDefaultLogStream_DEBUGGER" => 8, "_AI_DLS_ENFORCE_ENUM_SIZE" => 2147483647 }.freeze,
  "aiImporterFlags" => { "aiImporterFlags_SupportTextFlavour" => 1, "aiImporterFlags_SupportBinaryFlavour" => 2, "aiImporterFlags_SupportCompressedFlavour" => 4, "aiImporterFlags_LimitedSupport" => 8, "aiImporterFlags_Experimental" => 16 }.freeze,
  "aiLightSourceType" => { "aiLightSource_UNDEFINED" => 0, "aiLightSource_DIRECTIONAL" => 1, "aiLightSource_POINT" => 2, "aiLightSource_SPOT" => 3, "aiLightSource_AMBIENT" => 4, "aiLightSource_AREA" => 5, "_aiLightSource_Force32Bit" => 2147483647 }.freeze,
  "aiMetadataType" => { "AI_BOOL" => 0, "AI_INT32" => 1, "AI_UINT64" => 2, "AI_FLOAT" => 3, "AI_DOUBLE" => 4, "AI_AISTRING" => 5, "AI_AIVECTOR3D" => 6, "AI_AIMETADATA" => 7, "AI_INT64" => 8, "AI_UINT32" => 9, "AI_META_MAX" => 10, "FORCE_32BIT" => 2147483647 }.freeze,
  "aiMorphingMethod" => { "aiMorphingMethod_UNKNOWN" => 0, "aiMorphingMethod_VERTEX_BLEND" => 1, "aiMorphingMethod_MORPH_NORMALIZED" => 2, "aiMorphingMethod_MORPH_RELATIVE" => 3, "_aiMorphingMethod_Force32Bit" => 2147483647 }.freeze,
  "aiOrigin" => { "aiOrigin_SET" => 0, "aiOrigin_CUR" => 1, "aiOrigin_END" => 2, "_AI_ORIGIN_ENFORCE_ENUM_SIZE" => 2147483647 }.freeze,
  "aiPostProcessSteps" => { "aiProcess_CalcTangentSpace" => 1, "aiProcess_JoinIdenticalVertices" => 2, "aiProcess_MakeLeftHanded" => 4, "aiProcess_Triangulate" => 8, "aiProcess_RemoveComponent" => 16, "aiProcess_GenNormals" => 32, "aiProcess_GenSmoothNormals" => 64, "aiProcess_SplitLargeMeshes" => 128, "aiProcess_PreTransformVertices" => 256, "aiProcess_LimitBoneWeights" => 512, "aiProcess_ValidateDataStructure" => 1024, "aiProcess_ImproveCacheLocality" => 2048, "aiProcess_RemoveRedundantMaterials" => 4096, "aiProcess_FixInfacingNormals" => 8192, "aiProcess_PopulateArmatureData" => 16384, "aiProcess_SortByPType" => 32768, "aiProcess_FindDegenerates" => 65536, "aiProcess_FindInvalidData" => 131072, "aiProcess_GenUVCoords" => 262144, "aiProcess_TransformUVCoords" => 524288, "aiProcess_FindInstances" => 1048576, "aiProcess_OptimizeMeshes" => 2097152, "aiProcess_OptimizeGraph" => 4194304, "aiProcess_FlipUVs" => 8388608, "aiProcess_FlipWindingOrder" => 16777216, "aiProcess_SplitByBoneCount" => 33554432, "aiProcess_Debone" => 67108864, "aiProcess_GlobalScale" => 134217728, "aiProcess_EmbedTextures" => 268435456, "aiProcess_ForceGenNormals" => 536870912, "aiProcess_DropNormals" => 1073741824, "aiProcess_GenBoundingBoxes" => -2147483648 }.freeze,
  "aiPrimitiveType" => { "aiPrimitiveType_POINT" => 1, "aiPrimitiveType_LINE" => 2, "aiPrimitiveType_TRIANGLE" => 4, "aiPrimitiveType_POLYGON" => 8, "aiPrimitiveType_NGONEncodingFlag" => 16, "_aiPrimitiveType_Force32Bit" => 2147483647 }.freeze,
  "aiPropertyTypeInfo" => { "aiPTI_Float" => 1, "aiPTI_Double" => 2, "aiPTI_String" => 3, "aiPTI_Integer" => 4, "aiPTI_Buffer" => 5, "_aiPTI_Force32Bit" => 2147483647 }.freeze,
  "aiReturn" => { "aiReturn_SUCCESS" => 0, "aiReturn_FAILURE" => -1, "aiReturn_OUTOFMEMORY" => -3, "_AI_ENFORCE_ENUM_SIZE" => 2147483647 }.freeze,
  "aiShadingMode" => { "aiShadingMode_Flat" => 1, "aiShadingMode_Gouraud" => 2, "aiShadingMode_Phong" => 3, "aiShadingMode_Blinn" => 4, "aiShadingMode_Toon" => 5, "aiShadingMode_OrenNayar" => 6, "aiShadingMode_Minnaert" => 7, "aiShadingMode_CookTorrance" => 8, "aiShadingMode_NoShading" => 9, "aiShadingMode_Unlit" => 9, "aiShadingMode_Fresnel" => 10, "aiShadingMode_PBR_BRDF" => 11, "_aiShadingMode_Force32Bit" => 2147483647 }.freeze,
  "aiTextureFlags" => { "aiTextureFlags_Invert" => 1, "aiTextureFlags_UseAlpha" => 2, "aiTextureFlags_IgnoreAlpha" => 4, "_aiTextureFlags_Force32Bit" => 2147483647 }.freeze,
  "aiTextureMapMode" => { "aiTextureMapMode_Wrap" => 0, "aiTextureMapMode_Clamp" => 1, "aiTextureMapMode_Decal" => 3, "aiTextureMapMode_Mirror" => 2, "_aiTextureMapMode_Force32Bit" => 2147483647 }.freeze,
  "aiTextureMapping" => { "aiTextureMapping_UV" => 0, "aiTextureMapping_SPHERE" => 1, "aiTextureMapping_CYLINDER" => 2, "aiTextureMapping_BOX" => 3, "aiTextureMapping_PLANE" => 4, "aiTextureMapping_OTHER" => 5, "_aiTextureMapping_Force32Bit" => 2147483647 }.freeze,
  "aiTextureOp" => { "aiTextureOp_Multiply" => 0, "aiTextureOp_Add" => 1, "aiTextureOp_Subtract" => 2, "aiTextureOp_Divide" => 3, "aiTextureOp_SmoothAdd" => 4, "aiTextureOp_SignedAdd" => 5, "_aiTextureOp_Force32Bit" => 2147483647 }.freeze,
  "aiTextureType" => { "aiTextureType_NONE" => 0, "aiTextureType_DIFFUSE" => 1, "aiTextureType_SPECULAR" => 2, "aiTextureType_AMBIENT" => 3, "aiTextureType_EMISSIVE" => 4, "aiTextureType_HEIGHT" => 5, "aiTextureType_NORMALS" => 6, "aiTextureType_SHININESS" => 7, "aiTextureType_OPACITY" => 8, "aiTextureType_DISPLACEMENT" => 9, "aiTextureType_LIGHTMAP" => 10, "aiTextureType_REFLECTION" => 11, "aiTextureType_BASE_COLOR" => 12, "aiTextureType_NORMAL_CAMERA" => 13, "aiTextureType_EMISSION_COLOR" => 14, "aiTextureType_METALNESS" => 15, "aiTextureType_DIFFUSE_ROUGHNESS" => 16, "aiTextureType_AMBIENT_OCCLUSION" => 17, "aiTextureType_UNKNOWN" => 18, "aiTextureType_SHEEN" => 19, "aiTextureType_CLEARCOAT" => 20, "aiTextureType_TRANSMISSION" => 21, "aiTextureType_MAYA_BASE" => 22, "aiTextureType_MAYA_SPECULAR" => 23, "aiTextureType_MAYA_SPECULAR_COLOR" => 24, "aiTextureType_MAYA_SPECULAR_ROUGHNESS" => 25, "_aiTextureType_Force32Bit" => 2147483647 }.freeze,
}.freeze
POST_PROCESS =
{
  calc_tangent_space: 1,
  join_identical_vertices: 2,
  make_left_handed: 4,
  triangulate: 8,
  remove_component: 0x10,
  gen_normals: 0x20,
  gen_smooth_normals: 0x40,
  split_large_meshes: 0x80,
  pre_transform_vertices: 0x100,
  limit_bone_weights: 0x200,
  validate_data_structure: 0x400,
  improve_cache_locality: 0x800,
  remove_redundant_materials: 0x1000,
  fix_infacing_normals: 0x2000,
  populate_armature_data: 0x4000,
  sort_by_p_type: 0x8000,
  find_degenerates: 0x1_0000,
  find_invalid_data: 0x2_0000,
  gen_uv_coords: 0x4_0000,
  transform_uv_coords: 0x8_0000,
  find_instances: 0x10_0000,
  optimize_meshes: 0x20_0000,
  optimize_graph: 0x40_0000,
  flip_uvs: 0x80_0000,
  flip_winding_order: 0x100_0000,
  split_by_bone_count: 0x200_0000,
  debone: 0x400_0000,
  global_scale: 0x800_0000,
  embed_textures: 0x1000_0000,
  force_gen_normals: 0x2000_0000,
  drop_normals: 0x4000_0000,
  gen_bounding_boxes: 0x8000_0000,
}.freeze
HEADER_LAYOUTS =
{
  "aiBuffer" => [16, { data: 0, end: 8 }.freeze],
  "aiColor3D" => [12, { r: 0, g: 4, b: 8 }.freeze],
  "aiColor4D" => [16, { r: 0, g: 4, b: 8, a: 12 }.freeze],
  "aiFace" => [16, { num_indices: 0, indices: 8 }.freeze],
  "aiImporterDesc" => [64, { name: 0, author: 8, maintainer: 16, comments: 24, flags: 32, min_major: 36, min_minor: 40, max_major: 44, max_minor: 48, file_extensions: 56 }.freeze],
  "aiLogStream" => [16, { callback: 0, user: 8 }.freeze],
  "aiMaterial" => [16, { properties: 0, num_properties: 8, num_allocated: 12 }.freeze],
  "aiMatrix3x3" => [36, { a1: 0, a2: 4, a3: 8, b1: 12, b2: 16, b3: 20, c1: 24, c2: 28, c3: 32 }.freeze],
  "aiMatrix4x4" => [64, { a1: 0, a2: 4, a3: 8, a4: 12, b1: 16, b2: 20, b3: 24, b4: 28, c1: 32, c2: 36, c3: 40, c4: 44, d1: 48, d2: 52, d3: 56, d4: 60 }.freeze],
  "aiMemoryInfo" => [32, { textures: 0, materials: 4, meshes: 8, nodes: 12, animations: 16, cameras: 20, lights: 24, total: 28 }.freeze],
  "aiMeshKey" => [16, { time: 0, value: 8 }.freeze],
  "aiMeshMorphKey" => [32, { time: 0, values: 8, weights: 16, num_values_and_weights: 24 }.freeze],
  "aiMetadata" => [24, { num_properties: 0, keys: 8, values: 16 }.freeze],
  "aiMetadataEntry" => [16, { type: 0, data: 8 }.freeze],
  "aiPlane" => [16, { a: 0, b: 4, c: 8, d: 12 }.freeze],
  "aiPropertyStore" => [1, { sentinel: 0 }.freeze],
  "aiQuaternion" => [16, { w: 0, x: 4, y: 8, z: 12 }.freeze],
  "aiString" => [1028, { length: 0, data: 4 }.freeze],
  "aiTexel" => [4, { b: 0, g: 1, r: 2, a: 3 }.freeze],
  "aiVector2D" => [8, { x: 0, y: 4 }.freeze],
  "aiVector3D" => [12, { x: 0, y: 4, z: 8 }.freeze],
  "aiVertexWeight" => [8, { vertex_id: 0, weight: 4 }.freeze],
  "aiAABB" => [24, { min: 0, max: 12 }.freeze],
  "aiAnimMesh" => [1200, { name: 0, vertices: 1032, normals: 1040, tangents: 1048, bitangents: 1056, colors: 1064, texture_coords: 1128, num_vertices: 1192, weight: 1196 }.freeze],
  "aiAnimation" => [1096, { name: 0, duration: 1032, ticks_per_second: 1040, num_channels: 1048, channels: 1056, num_mesh_channels: 1064, mesh_channels: 1072, num_morph_mesh_channels: 1080, morph_mesh_channels: 1088 }.freeze],
  "aiBone" => [1120, { name: 0, num_weights: 1028, armature: 1032, node: 1040, weights: 1048, offset_matrix: 1056 }.freeze],
  "aiCamera" => [1084, { name: 0, position: 1028, up: 1040, look_at: 1052, horizontal_fov: 1064, clip_plane_near: 1068, clip_plane_far: 1072, aspect: 1076, orthographic_width: 1080 }.freeze],
  "aiLight" => [1132, { name: 0, type: 1028, position: 1032, direction: 1044, up: 1056, attenuation_constant: 1068, attenuation_linear: 1072, attenuation_quadratic: 1076, color_diffuse: 1080, color_specular: 1092, color_ambient: 1104, angle_inner_cone: 1116, angle_outer_cone: 1120, size: 1124 }.freeze],
  "aiMaterialProperty" => [1056, { key: 0, semantic: 1028, index: 1032, data_length: 1036, type: 1040, data: 1048 }.freeze],
  "aiMeshAnim" => [1040, { name: 0, num_keys: 1028, keys: 1032 }.freeze],
  "aiMeshMorphAnim" => [1040, { name: 0, num_keys: 1028, keys: 1032 }.freeze],
  "aiNode" => [1144, { name: 0, transformation: 1028, parent: 1096, num_children: 1104, children: 1112, num_meshes: 1120, meshes: 1128, meta_data: 1136 }.freeze],
  "aiNodeAnim" => [1080, { node_name: 0, num_position_keys: 1028, position_keys: 1032, num_rotation_keys: 1040, rotation_keys: 1048, num_scaling_keys: 1056, scaling_keys: 1064, pre_state: 1072, post_state: 1076 }.freeze],
  "aiQuatKey" => [32, { time: 0, value: 8, interpolation: 24 }.freeze],
  "aiRay" => [24, { pos: 0, dir: 12 }.freeze],
  "aiScene" => [1168, { flags: 0, root_node: 8, num_meshes: 16, meshes: 24, num_materials: 32, materials: 40, num_animations: 48, animations: 56, num_textures: 64, textures: 72, num_lights: 80, lights: 88, num_cameras: 96, cameras: 104, meta_data: 112, name: 120, num_skeletons: 1148, skeletons: 1152, private: 1160 }.freeze],
  "aiSkeleton" => [1040, { name: 0, num_bones: 1028, bones: 1032 }.freeze],
  "aiSkeletonBone" => [176, { parent: 0, armature: 8, node: 16, numn_weights: 24, mesh_id: 32, weights: 40, offset_matrix: 48, local_matrix: 112 }.freeze],
  "aiTexture" => [1064, { width: 0, height: 4, format_hint: 8, data: 24, filename: 32 }.freeze],
  "aiUVTransform" => [20, { translation: 0, scaling: 8, rotation: 16 }.freeze],
  "aiVectorKey" => [24, { time: 0, value: 8, interpolation: 20 }.freeze],
  "aiMesh" => [1320, { primitive_types: 0, num_vertices: 4, num_faces: 8, vertices: 16, normals: 24, tangents: 32, bitangents: 40, colors: 48, texture_coords: 112, num_uv_components: 176, faces: 208, num_bones: 216, bones: 224, material_index: 232, name: 236, num_anim_meshes: 1264, anim_meshes: 1272, method: 1280, aabb: 1284, texture_coords_names: 1312 }.freeze],
}.freeze

Class Method Summary collapse

Class Method Details

.extension_listObject



53
54
55
56
57
58
# File 'lib/assimp/native.rb', line 53

def extension_list
  load!
  output = StringValue.new
  aiGetExtensionList(output)
  output.to_s.split(";").map { |extension| extension.delete_prefix("*.") }.freeze
end

.library_candidatesObject



60
61
62
63
64
65
66
# File 'lib/assimp/native.rb', line 60

def library_candidates
  explicit = ENV[ENVIRONMENT_KEY]
  return [File.expand_path(explicit)] if explicit && !explicit.empty?

  packaged = packaged_library_candidates.select { |path| File.file?(path) }
  packaged + platform_library_names
end

.load!Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/assimp/native.rb', line 18

def load!
  return self if @loaded

  LOAD_MUTEX.synchronize do
    return self if @loaded

    ffi_lib(resolve_library)
    attach_api
    verify_version!
    @loaded = true
  end
  self
rescue FFI::NotFoundError, LoadError => e
  raise LibraryError, "could not load Assimp 5.x: #{e.message}"
end

.loaded?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/assimp/native.rb', line 34

def loaded?
  @loaded == true
end

.revisionObject



43
44
45
46
# File 'lib/assimp/native.rb', line 43

def revision
  load!
  aiGetVersionRevision
end

.supports_extension?(extension) ⇒ Boolean

Returns:

  • (Boolean)


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

def supports_extension?(extension)
  load!
  aiIsExtensionSupported(normalize_extension(extension)) != 0
end

.versionObject



38
39
40
41
# File 'lib/assimp/native.rb', line 38

def version
  load!
  [aiGetVersionMajor, aiGetVersionMinor, @version_patch ? aiGetVersionPatch : 0]
end