ark_api_ffi/ffi/
world_v3.rs

1define_api_id!(0x1d69_ec55_ed04_461d, "world-v3");
2
3pub use crate::world_v0::BoneWeightFlags;
4pub use crate::world_v0::EntityHandle;
5pub use crate::world_v0::MeshHandle;
6pub use crate::world_v0::Ray;
7pub use crate::world_v0::ENTITY_HANDLE_INVALID;
8use crate::FFIResult;
9use bytemuck::Pod;
10use bytemuck::Zeroable;
11
12#[ark_api_macros::ark_bindgen(imports = "ark-world-v3")]
13mod world {
14    use super::*;
15
16    #[derive(Copy, Clone, Default, Debug, Pod, Zeroable)]
17    #[repr(C)]
18    pub struct RaycastQuery {
19        pub ray: Ray,
20        pub layer_mask: u64,
21        pub ignore_entity: EntityHandle,
22        pub max_distance: f32,
23        pub _pad: u32,
24    }
25
26    #[derive(Copy, Clone, Default, Debug, Pod, Zeroable)]
27    #[repr(C)]
28    pub struct RaycastHit {
29        pub point: [f32; 3],
30
31        pub normal: [f32; 3],
32
33        /// Entity that was hit.
34        /// If nothing was hit then EntityHandle will be invalid
35        pub entity: EntityHandle,
36
37        /// The distance along the ray.
38        ///
39        /// The hits are sorted by this distance when returned from raycast and spherecast queries.
40        /// In a raycast this is equal to `ray.origin.distance(hit.position)`,
41        /// but in a spherecast it can be different.
42        pub distance: f32,
43        pub _pad: u32,
44    }
45
46    impl RaycastHit {
47        pub fn invalid() -> Self {
48            Self {
49                point: [std::f32::NAN; 3],
50                normal: [std::f32::NAN; 3],
51                entity: ENTITY_HANDLE_INVALID,
52                distance: std::f32::NAN,
53                _pad: 0,
54            }
55        }
56    }
57
58    /// Describes the transform of a bone. More compact and more defined than a Mat4.
59    ///
60    /// Currently uses a pos + quat representation, although this may changed in the future.
61    /// Aligned to 16 bytes to be able to copy these directly to GPU.
62    #[derive(Copy, Clone, Debug, Pod, Zeroable)]
63    #[repr(C, align(16))]
64    pub struct BoneTransform {
65        pub rot: [f32; 4],
66        pub pos: [f32; 3],
67        pub _pad: u32,
68    }
69
70    /// WorldData description type used when initializing an SdfProgram WorldData
71    #[derive(Debug, Copy, Clone, Pod, Zeroable)]
72    #[repr(C)]
73    pub struct SdfProgramDesc {
74        pub num_opcodes: u32,
75        pub opcodes_ptr: u32,
76        pub num_constants: u32,
77        pub constants_ptr: u32,
78    }
79
80    /// WorldData description type used when initializing an SdfSkin WorldData
81    #[derive(Debug, Copy, Clone, Pod, Zeroable)]
82    #[repr(C)]
83    pub struct SdfSkinDesc {
84        pub base_sdf_entity: EntityHandle,
85        pub num_bone_entities: u32,
86        pub bone_entities_ptr: u32,
87        pub num_rest_from_shape: u32,
88        pub rest_from_shape_ptr: u32,
89    }
90
91    /// WorldData description type used when initializing an SdfSkin WorldData.
92    /// With an extra field for mesh replacement.
93    #[derive(Debug, Copy, Clone, Pod, Zeroable)]
94    #[repr(C)]
95    pub struct SdfSkinDesc2 {
96        pub base_sdf_entity: EntityHandle,
97        pub num_bone_entities: u32,
98        pub bone_entities_ptr: u32,
99        pub num_rest_from_shape: u32,
100        pub rest_from_shape_ptr: u32,
101        pub replacement_mesh: MeshHandle,
102        pub bone_weight_flags: BoneWeightFlags,
103        pub bone_weight_bias: f32,
104        pub bone_weight_falloff: f32,
105        pub reserved0: u32,
106    }
107
108    #[derive(Debug, Copy, Clone, Pod, Zeroable)]
109    #[repr(C)]
110    pub struct MorphTargetDesc {
111        pub num_weights: u32,
112        pub weights_ptr: u32,
113        pub names_ptr: u32,
114    }
115
116    #[derive(Debug, Copy, Clone, Pod, Zeroable)]
117    #[repr(C)]
118    pub struct WorldMaterialsDesc {
119        pub materials_len: u32,
120        pub materials_ptr: u32,
121    }
122
123    extern "C" {
124        /// Returns whether the entity `a` is physically in contact with the entity `b`.
125        ///
126        /// If b is invalid, checks whether `a` is in contact with any other handle.
127        #[deprecated_infallible]
128        pub fn entities_in_contact(a: EntityHandle, b: EntityHandle) -> bool;
129
130        /// Returns the number of entities the entity `a` is in contact with.
131        #[deprecated_infallible]
132        pub fn entity_contact_count(a: EntityHandle) -> u32;
133
134        /// Writes the entities in contact to the provided array. The actual count is returned.
135        #[deprecated_infallible]
136        pub fn retrieve_entities_in_contact(a: EntityHandle, entities: &mut [EntityHandle]) -> u32;
137
138        #[deprecated_infallible]
139        pub fn raycast(raycast: &RaycastQuery) -> RaycastHit;
140
141        #[deprecated_infallible]
142        pub fn raycast_batched(raycasts: &[RaycastQuery], hits: &mut [RaycastHit]);
143
144        /// Makes it possible to create rigid bodies in the middle of a frame.
145
146        /// Will use all the parameters already set up on the Physics component, just like the
147        /// "old" way.
148        #[deprecated_infallible]
149        pub fn create_body_immediate(e: EntityHandle);
150
151        /// Writes directly to the collision matrix.
152        #[deprecated_infallible]
153        pub fn set_collision_matrix_rows(first_row: u32, rows: &[u64]);
154
155        /// Creates a mesh from an included GLTF file, from the module directory.
156        #[deprecated(note = "use `create_data` instead")] // since 2021-10-30
157        pub fn create_mesh_from_gltf(gltf_data: &[u8], buffer_data: &[u8])
158            -> FFIResult<MeshHandle>;
159    }
160}
161
162pub use world::*;