1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
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::Value;
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 crate::FFIResult;
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,
}
}
}
#[deprecated(note = "Use EntityLocalTransformConformal3 instead")] #[derive(Clone, Copy, Debug, Pod, Zeroable)]
#[repr(C)]
pub struct EntityTransform {
pub translation: [f32; 3],
pub rotation: [f32; 4],
pub scale: [f32; 3],
}
#[deprecated(note = "Use EntityLocalTransformConformal3 instead")] #[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 EntityTransformConformal3 {
pub translation_and_scale: [f32; 4],
pub rotation: [f32; 4],
}
#[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 {
#[deprecated(note = "Use EntityLocalTransformConformal3 instead")] EntityLocalTransform = 0,
EntityRenderTint = 1,
EntityRenderEnable = 2,
#[deprecated(note = "Use EntityWorldTransformConformal3 instead")] EntityWorldTransform = 3,
EntityLocalBounds = 4,
EntityPhysicsVelocity = 5,
EntityStateFlags = 6,
#[deprecated(note = "Use EntityWorldTransformConformal3 instead")] EntityWorldTransformAffine3 = 7,
EntityLocalTransformConformal3 = 8,
EntityWorldTransformConformal3 = 9,
}
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>(),
Self::EntityLocalTransformConformal3 | Self::EntityWorldTransformConformal3 => {
std::mem::size_of::<EntityTransformConformal3>()
}
};
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,
}
#[derive(Default, Copy, Clone, Debug, PartialEq)]
#[non_exhaustive]
#[repr(u32)]
pub enum EntityValueError {
#[default]
Undefined = 0,
NanValue = 1,
InfiniteParamValue = 2,
InvalidComponentType = 3,
InvalidComponentParameterId = 4,
InvalidComponent = 5,
InvalidEntityKey = 6,
InvalidParentOfParent = 7,
IncompatibleValueType = 8,
IncompatibleValue = 9,
Unsettable = 10,
Ungettable = 11,
NotAvailable = 12,
UnnormalizedRotation = 13,
}
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 try_set_entity_value(
entity: EntityHandle,
component_type: u64,
component_param_id: u32,
new_component_value: &Value,
out_error_info: &mut EntityValueError,
) -> FFIResult<()>;
pub fn try_get_entity_value(
entity: EntityHandle,
component_type: u64,
component_param_id: u32,
out_component_value: &mut Value,
out_error_info: &mut EntityValueError,
) -> FFIResult<()>;
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::*;