Skip to main content

gltforge_unity/
lib.rs

1pub mod convert;
2pub mod error;
3pub(crate) mod gltf_primitive_data;
4pub mod unity_game_object;
5pub mod unity_gltf;
6pub mod unity_image;
7pub mod unity_mesh;
8pub mod unity_pbr_metallic_roughness;
9pub mod unity_scene;
10pub mod unity_submesh;
11
12// Re-export the unity_indices module path for code that imports via the old module path.
13pub mod unity_indices {
14    pub use gltforge_unity_core::UnityIndices;
15}
16
17// -------------------------------------------------------------------------- //
18
19pub use gltforge_unity_core::{
20    ALPHA_MODE_BLEND, ALPHA_MODE_MASK, ALPHA_MODE_OPAQUE, IDENTITY, UnityGameObject, UnityImage,
21    UnityIndices, UnityMesh, UnityPbrMetallicRoughness, UnitySubMesh, UnityTransform,
22};
23pub use unity_game_object::{
24    gltforge_game_object_child, gltforge_game_object_child_count, gltforge_game_object_count,
25    gltforge_game_object_mesh_count, gltforge_game_object_mesh_index, gltforge_game_object_name,
26    gltforge_game_object_transform,
27};
28pub use unity_gltf::{UnityGltf, gltforge_load, gltforge_release, gltforge_retain};
29pub use unity_image::{
30    gltforge_image_bytes, gltforge_image_count, gltforge_image_name, gltforge_image_uri,
31};
32pub use unity_mesh::{
33    gltforge_mesh_count, gltforge_mesh_index_format, gltforge_mesh_name, gltforge_mesh_normals,
34    gltforge_mesh_positions, gltforge_mesh_tangents, gltforge_mesh_uv_channel_count,
35    gltforge_mesh_uvs, gltforge_mesh_vertex_count,
36};
37pub use unity_pbr_metallic_roughness::{
38    gltforge_pbr_metallic_roughness_alpha_cutoff, gltforge_pbr_metallic_roughness_alpha_mode,
39    gltforge_pbr_metallic_roughness_base_color_factor,
40    gltforge_pbr_metallic_roughness_base_color_texture, gltforge_pbr_metallic_roughness_count,
41    gltforge_pbr_metallic_roughness_cull, gltforge_pbr_metallic_roughness_emissive_factor,
42    gltforge_pbr_metallic_roughness_emissive_texture,
43    gltforge_pbr_metallic_roughness_metallic_factor,
44    gltforge_pbr_metallic_roughness_metallic_roughness_texture,
45    gltforge_pbr_metallic_roughness_name, gltforge_pbr_metallic_roughness_normal_scale,
46    gltforge_pbr_metallic_roughness_normal_texture,
47    gltforge_pbr_metallic_roughness_occlusion_strength,
48    gltforge_pbr_metallic_roughness_occlusion_texture,
49    gltforge_pbr_metallic_roughness_roughness_factor,
50};
51pub use unity_scene::{
52    gltforge_root_game_object_count, gltforge_root_game_object_index, gltforge_scene_name,
53};
54pub use unity_submesh::{
55    gltforge_mesh_submesh_count, gltforge_mesh_submesh_indices_u16,
56    gltforge_mesh_submesh_indices_u32, gltforge_mesh_submesh_material,
57};
58
59// -------------------------------------------------------------------------- //
60
61/// Returns null + sets `out_len = 0` when a name is absent,
62/// otherwise returns a pointer to the UTF-8 bytes and sets `out_len`.
63unsafe fn write_name(name: Option<&String>, out_len: *mut u32) -> *const u8 {
64    match name {
65        Some(s) => {
66            if !out_len.is_null() {
67                unsafe { *out_len = s.len() as u32 };
68            }
69            s.as_ptr()
70        }
71        None => {
72            if !out_len.is_null() {
73                unsafe { *out_len = 0 };
74            }
75            std::ptr::null()
76        }
77    }
78}