define_api_id!(0x3c5a_8c47_30ab_ec47, "world-v4");
pub use crate::world_v0::EntityHandle;
pub use crate::world_v0::MeshHandle;
pub use crate::world_v0::Ray;
pub use crate::world_v0::ENTITY_HANDLE_INVALID;
pub use crate::world_v2::DataHandle;
pub use crate::world_v2::ResourceHandleRepr;
pub use crate::world_v3::RaycastHit;
use bytemuck::Pod;
use bytemuck::Zeroable;
#[ark_api_macros::ark_bindgen(imports = "ark-world-v4")]
mod world {
use super::*;
bitflags! {
#[repr(C)]
#[derive(Pod, Zeroable)]
pub struct RaycastQueryOptions : u32 {
const IGNORE_INTERIOR_HITS = 0b0010_0000;
}
}
impl Default for RaycastQueryOptions {
fn default() -> Self {
Self::empty()
}
}
#[derive(Copy, Clone, Default, Debug, Pod, Zeroable)]
#[repr(C)]
pub struct RaycastQueryWithOptions {
pub ray: Ray,
pub layer_mask: u64,
pub ignore_entity: EntityHandle,
pub max_distance: f32,
pub options: RaycastQueryOptions,
}
#[derive(Copy, Clone, Default, Debug, Pod, Zeroable)]
#[repr(C)]
pub struct SpherecastQuery {
pub ray: Ray,
pub layer_mask: u64,
pub ignore_entity: EntityHandle,
pub max_distance: f32,
pub options: RaycastQueryOptions,
pub spherecast_radius: f32,
pub _pad: u32,
}
#[derive(Copy, Clone, Debug, Pod, Zeroable)]
#[repr(C)]
pub struct SpatialQueryHit {
pub entity: EntityHandle,
pub point: [f32; 3],
pub distance: f32,
pub normal: [f32; 3],
pub _pad: u32,
}
impl SpatialQueryHit {
pub fn invalid() -> Self {
Self {
entity: ENTITY_HANDLE_INVALID,
point: [f32::NAN; 3],
distance: f32::NAN,
normal: [f32::NAN; 3],
_pad: 0,
}
}
}
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
#[repr(C)]
pub struct EntityTransform {
pub translation: [f32; 3],
pub rotation: [f32; 4],
pub scale: [f32; 3],
}
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
#[repr(C)]
pub struct EntityTransformAffine3 {
pub rotation_scale: [f32; 9],
pub translation: [f32; 3],
}
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
#[repr(C)]
pub struct EntityMeshStyleTint {
pub tint: [f32; 4],
}
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
#[repr(C)]
pub struct EntityRenderEnable {
pub enable: u32,
}
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
#[repr(C)]
pub struct EntityBounds {
pub bounding_box_min: [f32; 3],
pub bounding_box_max: [f32; 3],
pub bounding_sphere_radius: f32,
}
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
#[repr(C)]
pub struct EntityVelocity {
pub positional: [f32; 3],
pub rotational: [f32; 3],
}
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[repr(u32)]
#[non_exhaustive]
pub enum EntityValueType {
EntityLocalTransform = 0,
EntityRenderTint = 1,
EntityRenderEnable = 2,
EntityWorldTransform = 3,
EntityLocalBounds = 4,
EntityPhysicsVelocity = 5,
EntityStateFlags = 6,
EntityWorldTransformAffine3 = 7,
}
impl EntityValueType {
pub fn size_of_element(&self) -> u32 {
let size = match self {
Self::EntityLocalTransform | Self::EntityWorldTransform => {
std::mem::size_of::<EntityTransform>()
}
Self::EntityRenderTint => std::mem::size_of::<EntityMeshStyleTint>(),
Self::EntityRenderEnable => std::mem::size_of::<EntityRenderEnable>(),
Self::EntityLocalBounds => std::mem::size_of::<EntityBounds>(),
Self::EntityPhysicsVelocity => std::mem::size_of::<EntityVelocity>(),
Self::EntityStateFlags => std::mem::size_of::<EntityStateFlags>(),
Self::EntityWorldTransformAffine3 => std::mem::size_of::<EntityTransformAffine3>(),
};
size as u32
}
}
bitflags! {
#[repr(C)]
#[derive(Default, Pod, Zeroable)]
pub struct EntityStateFlags : u32 {
const VALID = 0b0000_0001;
const TRANSFORM_CHANGED = 0b0000_0010;
const PHYSICS_VELOCITY_CHANGED = 0b0000_0100;
const BOUNDS_CHANGED = 0b0000_1000;
}
}
bitflags! {
#[repr(C)]
#[derive(Pod, Zeroable)]
pub struct EntityDebugOptions : u32 {
const PHYSICS_SHAPE_DEBUG_RENDERING_ENABLE = 0b0000_0001;
}
}
#[derive(Debug, Copy, Clone, Pod, Zeroable)]
#[repr(C)]
pub struct MeasuredTextSize {
pub min_x: f32,
pub min_y: f32,
pub width: f32,
pub height: f32,
}
#[derive(Debug, Copy, Clone, Pod, Zeroable)]
#[repr(C)]
pub struct AudioClipResource {
pub handle: ResourceHandleRepr,
}
#[derive(Default, Copy, Clone, Debug, PartialEq, Pod, Zeroable)]
#[repr(C)]
pub struct DominantColorWithArea {
pub color: [u8; 4], pub area: f32,
}
extern "C" {
#[deprecated(note = "use `spherecast` instead")] #[deprecated_infallible]
pub fn raycast(raycast: &RaycastQueryWithOptions) -> RaycastHit;
#[deprecated(note = "use `spherecast_batched` instead")] #[deprecated_infallible]
pub fn raycast_batched(raycasts: &[RaycastQueryWithOptions], hits: &mut [RaycastHit]);
pub fn spherecast(raycast: &SpherecastQuery) -> RaycastHit;
pub fn spherecast_batched(raycasts: &[SpherecastQuery], hits: &mut [RaycastHit]);
#[deprecated_infallible]
pub fn set_data_debug_name(data: DataHandle, name: &str);
pub fn get_data_debug_name(data: DataHandle) -> String;
pub fn set_entity_debug_options(
entities: &[EntityHandle],
debug_options: &EntityDebugOptions,
);
pub fn set_entity_values(
entities: &[EntityHandle],
value_type: EntityValueType,
data: &[u8],
);
pub fn get_entity_values(
entities: &[EntityHandle],
value_type: EntityValueType,
out_data: &mut [u8],
);
pub fn measure_formatted_text(text: DataHandle, size: &mut MeasuredTextSize);
pub fn get_mesh_section_count(handle: MeshHandle) -> u64;
pub fn get_mesh_section_dominant_color(
handle: MeshHandle,
idx: u64,
) -> DominantColorWithArea;
pub fn get_mesh_section_material_index(handle: MeshHandle, idx: u64) -> u64;
}
}
pub use world::*;