Skip to main content

gltforge_unity/
unity_scene.rs

1use crate::{unity_gltf::UnityGltf, write_name};
2
3/// Return the scene name as UTF-8 bytes (not null-terminated).
4/// Always non-null — unnamed scenes fall back to the source filename.
5/// `out_len` receives the byte length.
6///
7/// # Safety
8/// `ptr` must be a valid, non-null handle. `out_len` may be null.
9#[unsafe(no_mangle)]
10pub unsafe extern "C" fn gltforge_scene_name(
11    ptr: *const UnityGltf,
12    out_len: *mut u32,
13) -> *const u8 {
14    let gltf = unsafe { &*ptr };
15    unsafe { write_name(Some(&gltf.scene_name), out_len) }
16}
17
18/// Return the number of root nodes in the default scene.
19///
20/// # Safety
21/// `ptr` must be a valid, non-null handle.
22#[unsafe(no_mangle)]
23pub unsafe extern "C" fn gltforge_root_node_count(ptr: *const UnityGltf) -> u32 {
24    unsafe { &*ptr }.root_nodes.len() as u32
25}
26
27/// Return the node index of the `slot`-th root node.
28/// Returns `u32::MAX` if `slot` is out of range.
29///
30/// # Safety
31/// `ptr` must be a valid, non-null handle.
32#[unsafe(no_mangle)]
33pub unsafe extern "C" fn gltforge_root_node_index(ptr: *const UnityGltf, slot: u32) -> u32 {
34    unsafe { &*ptr }
35        .root_nodes
36        .get(slot as usize)
37        .copied()
38        .unwrap_or(u32::MAX)
39}