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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
define_api_id!(0x1d69_ec55_ed04_461c, "world-v2");
pub use crate::world_v0::EntityHandle;
pub use crate::world_v0::MeshHandle;
pub use crate::world_v0::MeshProperties;
pub use crate::world_v0::Message;
pub use crate::world_v0::Ray;
pub use crate::world_v0::Value;
pub use crate::world_v1::DataHandle;
use crate::FFIResult;
use bytemuck::CheckedBitPattern;
use bytemuck::NoUninit;
use bytemuck::Pod;
use bytemuck::Zeroable;
pub type ResourceHandleRepr = u32;
pub const INVALID_RESOURCE_HANDLE: u32 = !0u32;
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, NoUninit, CheckedBitPattern)]
#[repr(u32)]
pub enum MeshStreamSemantic {
Indices = 0,
Positions = 1,
Normals = 2,
Colors = 3,
TexCoords = 4,
BoneIndicesWeights = 5, }
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, NoUninit, CheckedBitPattern)]
#[repr(u32)]
pub enum MeshComponentFormat {
Float16 = 0,
Float32 = 1,
UInt8 = 2,
SInt8 = 3,
UInt16 = 4,
SInt16 = 5,
UInt32 = 6,
SInt32 = 7,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, NoUninit, CheckedBitPattern)]
#[repr(C)]
pub struct MeshStreamLayout {
pub semantic: MeshStreamSemantic,
pub component_format: MeshComponentFormat,
pub component_count: u32,
pub buffer_ptr: u32,
pub buffer_size: u32,
}
bitflags::bitflags! {
#[cfg_attr(feature = "with_serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "with_speedy", derive(speedy::Writable, speedy::Readable))]
#[repr(C)]
#[derive(Pod, Zeroable)]
pub struct MeshStyleFlags : u32 {
const LIGHTING = 0b0000_0001;
const ALPHA_BLENDING = 0b0000_0010;
const FLAT_SHADING = 0b0000_0100;
const _LEGACY = 0b0000_1000;
const PREMULTIPLIED_ALPHA = 0b0001_0000;
const BILLBOARD = 0b0010_0000;
const TWO_SIDED = 0b0100_0000;
const OUTLINE = 0b1000_0000;
const OVERLAY = 0b0001_0000_0000;
}
}
impl Default for MeshStyleFlags {
fn default() -> Self {
Self::LIGHTING | Self::ALPHA_BLENDING
}
}
bitflags::bitflags! {
#[cfg_attr(feature = "with_serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "with_speedy", derive(speedy::Writable, speedy::Readable))]
#[repr(C)]
#[derive(Pod, Zeroable)]
pub struct MeshVisibilityFlags : u8 {
const REFLECTIONS = 0b0000_0001; const SHADOWS = 0b0000_0010; const GLOBAL_ILLUMINATION = 0b0000_0100; const PRIMARY = 0b0000_1000; }
}
impl Default for MeshVisibilityFlags {
fn default() -> Self {
Self::REFLECTIONS | Self::SHADOWS | Self::GLOBAL_ILLUMINATION | Self::PRIMARY
}
}
#[allow(clippy::too_many_arguments)]
#[ark_api_macros::ark_bindgen(imports = "ark-world-v2")]
mod world {
use super::*;
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[repr(u32)]
pub enum EntityTemplate {
Empty = 0,
PhysicsObject = 1,
Environment = 2,
MeshStyle = 3,
Camera = 4,
NonPhysicsObject = 5,
}
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[repr(u64)]
#[non_exhaustive]
pub enum ComponentType {
Invalid = 0,
Transform = 1,
Render = 2,
Physics = 3,
Environment = 4,
MeshStyle = 5,
Camera = 6,
Bounds = 9,
Tag = 10,
Layer = 11,
EntityInfo = 13,
D6Joint = 14,
SdfModel = 17,
AudioSource = 19,
}
#[derive(Debug, Copy, Clone, Pod, Zeroable)]
#[repr(C)]
pub struct AudioClipInfo {
pub num_samples: u64,
pub num_channels: u32,
pub sample_rate: u32,
}
impl AudioClipInfo {
pub fn length_in_seconds(&self) -> f32 {
(self.num_samples as f32) / (self.sample_rate as f32)
}
}
#[derive(Debug, Copy, Clone, Pod, Zeroable)]
#[repr(C)]
pub struct SdfSkinInfo {
pub replacement_mesh: DataHandle,
}
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[repr(u32)]
#[non_exhaustive]
pub enum RetrieveDataType {
Output = 1,
Info = 3,
WorldDataType = 4,
}
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[repr(u64)]
#[non_exhaustive]
pub enum CreateDataType {
String = 1, Binary = 2,
ComponentsMetaData = 3, WorldEntityQuery = 4,
CompoundPhysicsShape = 5,
SdfProgram = 6,
#[deprecated(note = "Use `SdfSkin2`")]
SdfSkin = 7,
AudioClipOgg = 8,
AudioClipWav = 9,
MorphTargetData = 10,
#[deprecated(note = "Use `MeshRawWithName`")] MeshRaw = 11,
MeshGltf = 12,
PlayerIdSet = 13,
#[deprecated(note = "Use `MeshRawWithMaterialAndName`")] MeshRawWithMaterial = 14,
WorldMaterial = 15,
SdfSkin2 = 16,
WorldMaterials = 17,
MeshGltfNamed = 18,
MeshSimplified = 19,
MeshRawWithName = 20,
MeshRawWithMaterialAndName = 21,
FormattedText = 22,
RenderModule = 23,
MeshGltfResource = 24,
AudioClipOggResource = 25,
AudioClipWavResource = 26,
AudioModule = 27,
}
impl CreateDataType {
pub fn name(self) -> &'static str {
match self {
Self::String => "String",
Self::Binary => "Binary",
Self::ComponentsMetaData => "ComponentsMetaData",
Self::WorldEntityQuery => "WorldEntityQuery",
Self::CompoundPhysicsShape => "CompoundPhysicsShape",
Self::SdfProgram => "SdfProgram",
Self::SdfSkin => "SdfSkin",
Self::AudioClipOgg => "AudioClipOgg",
Self::AudioClipWav => "AudioClipWav",
Self::MorphTargetData => "MorphTargetData",
Self::MeshRaw => "MeshRaw",
Self::MeshGltf => "MeshGltf",
Self::PlayerIdSet => "PlayerIdSet",
Self::MeshRawWithMaterial => "MeshRawWithMaterial",
Self::WorldMaterial => "WorldMaterial",
Self::SdfSkin2 => "SdfSkin2",
Self::WorldMaterials => "WorldMaterials",
Self::MeshGltfNamed => "MeshGltfNamed",
Self::MeshSimplified => "MeshSimplified",
Self::MeshRawWithName => "MeshRawWithName",
Self::MeshRawWithMaterialAndName => "MeshRawWithMaterialAndName",
Self::FormattedText => "FormattedText",
Self::RenderModule => "RenderModule",
Self::MeshGltfResource => "MeshGltfResource",
Self::AudioClipOggResource => "AudioClipOggResource",
Self::AudioClipWavResource => "AudioClipWavResource",
Self::AudioModule => "AudioModule",
}
}
}
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[repr(u64)]
#[non_exhaustive]
pub enum WorldDataType {
String = 0,
Binary = 1,
ComponentsMetaData = 2,
EntityQuery = 3,
CompoundPhysicsShape = 4,
SdfProgram = 5,
SdfSkin = 6,
AudioClip = 7,
MorphTargetWeights = 8,
Mesh = 9,
WorldMaterial = 10,
WorldMaterials = 11,
PlayerIdSet = 12,
FormattedText = 13,
RenderModule = 14,
}
#[derive(Debug, Copy, Clone, Pod, Zeroable)]
#[repr(C)]
pub struct RawRenderModuleData {
pub module_dependency_name_ptr: u32,
pub module_dependency_name_len: u32,
pub static_data_ptr: u32,
pub static_data_len: u32,
}
#[derive(Debug, Copy, Clone, Pod, Zeroable)]
#[repr(C)]
pub struct RawAudioModuleData {
pub module_dependency_name_ptr: u32,
pub module_dependency_name_len: u32,
pub data_ptr: u32,
pub data_len: u32,
}
#[derive(Copy, Clone, Debug, PartialEq, Pod, Zeroable)]
#[repr(C)]
pub struct MaterialDesc {
pub diffuse_albedo: [f32; 3],
pub alpha: f32,
pub emissive_color: [f32; 3],
pub metallic: f32,
pub perceptual_roughness: f32,
pub reserved: [f32; 16],
}
impl Default for MaterialDesc {
fn default() -> Self {
Self {
diffuse_albedo: [1.0; 3],
alpha: 1.0,
metallic: 0.0,
perceptual_roughness: 0.5,
emissive_color: [0.0; 3],
reserved: [0.0; 16],
}
}
}
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[repr(u32)]
pub enum MeshPrimitiveTopology {
TriangleList = 2,
}
#[deprecated(note = "Use `MeshRawWithName`")] #[derive(Debug, Copy, Clone, NoUninit, CheckedBitPattern)]
#[repr(C)]
pub struct MeshRaw {
pub primitive_topology: MeshPrimitiveTopology,
pub streams_ptr: u32,
pub num_streams: u32,
}
#[derive(Debug, Copy, Clone, NoUninit, CheckedBitPattern)]
#[repr(C)]
pub struct MeshRawWithName {
pub primitive_topology: MeshPrimitiveTopology,
pub streams_ptr: u32,
pub num_streams: u32,
pub debug_name_ptr: u32,
pub debug_name_size: u32,
}
#[deprecated(note = "Use `MeshRawWithMaterialAndName`")] #[derive(Debug, Copy, Clone, NoUninit, CheckedBitPattern)]
#[repr(C)]
pub struct MeshRawWithMaterial {
pub inner: MeshRaw,
pub _pad: u32,
pub material: DataHandle,
}
#[derive(Debug, Copy, Clone, NoUninit, CheckedBitPattern)]
#[repr(C)]
pub struct MeshRawWithMaterialAndName {
pub inner: MeshRawWithName,
pub _pad: u32,
pub material: DataHandle,
}
bitflags::bitflags! {
#[cfg_attr(feature = "with_serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "with_speedy", derive(speedy::Writable, speedy::Readable))]
#[repr(C)]
#[derive(Pod, Zeroable)]
pub struct GltfFlags : u32 {
const VERTEX_COLORS_SRGB = 1;
}
}
#[derive(Debug, Copy, Clone, Pod, Zeroable)]
#[repr(C)]
pub struct MeshGltf {
pub gltf_data_ptr: u32,
pub gltf_data_size: u32,
pub buffer_data_ptr: u32,
pub buffer_data_size: u32,
pub flags: GltfFlags,
}
#[derive(Debug, Copy, Clone, Pod, Zeroable)]
#[repr(C)]
pub struct MeshGltfNamed {
pub debug_name_ptr: u32,
pub debug_name_size: u32,
pub gltf_data_ptr: u32,
pub gltf_data_size: u32,
pub buffer_data_ptr: u32,
pub buffer_data_size: u32,
pub flags: GltfFlags,
}
#[derive(Debug, Copy, Clone, Pod, Zeroable)]
#[repr(C)]
pub struct MeshGltfResource {
pub debug_name_ptr: u32,
pub debug_name_size: u32,
pub gltf_resource: ResourceHandleRepr,
pub buffer_resource: ResourceHandleRepr,
pub flags: GltfFlags,
}
bitflags::bitflags! {
#[cfg_attr(feature = "with_serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "with_speedy", derive(speedy::Writable, speedy::Readable))]
#[repr(C)]
#[derive(Pod, Zeroable)]
pub struct MeshSimplifiedFlags : u32 {
const KEEP_NORMALS = 1;
const KEEP_COLORS = 2;
const KEEP_TEXCOORDS = 4;
const KEEP_BONE_INDICES_WEIGHTS = 8;
const KEEP_ALL_STREAMS = Self::KEEP_NORMALS.bits() | Self::KEEP_COLORS.bits() | Self::KEEP_TEXCOORDS.bits() | Self::KEEP_BONE_INDICES_WEIGHTS.bits();
}
}
#[derive(Debug, Copy, Clone, Pod, Zeroable)]
#[repr(C)]
pub struct MeshSimplified {
pub mesh: DataHandle,
pub threshold: f32,
pub target_error: f32,
pub min_triangle_count: u32,
pub max_triangle_count: u32,
pub flags: MeshSimplifiedFlags,
pub reserved: [f32; 15], }
bitflags::bitflags! {
#[cfg_attr(feature = "with_serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "with_speedy", derive(speedy::Writable, speedy::Readable))]
#[repr(C)]
#[derive(Pod, Zeroable)]
pub struct PlayerIdSetFlags : u32 {
const EXCLUSIVE = 1; }
}
#[derive(Debug, Copy, Clone, Pod, Zeroable)]
#[repr(C)]
pub struct PlayerIdSet {
pub player_ids_ptr: u32,
pub num_player_ids: u32,
pub flags: PlayerIdSetFlags,
pub reserved: [u32; 4],
}
#[derive(Debug, Copy, Clone, Pod, Zeroable)]
#[repr(C)]
pub struct MessageRangeAndReceiver {
pub entity: EntityHandle,
pub start_index: u32,
pub length: u32,
}
extern "C" {
#[deprecated_infallible]
pub fn create_entity(name: &str, entity_type: EntityTemplate) -> EntityHandle;
#[deprecated_infallible]
pub fn add_component(entity: EntityHandle, component_type: ComponentType);
#[deprecated_infallible]
pub fn remove_component(entity: EntityHandle, component_type: ComponentType);
#[deprecated_infallible]
pub fn has_component(entity: EntityHandle, component_type: ComponentType) -> u32;
#[deprecated_infallible]
pub fn destroy_entity(entity: EntityHandle);
#[deprecated_infallible]
pub fn is_valid_entity(entity: EntityHandle) -> u32;
#[deprecated_infallible]
pub fn is_valid_mesh(mesh: MeshHandle) -> u32;
#[deprecated_infallible]
pub fn clone_entities(
name: &str,
entity_dest: &mut [EntityHandle],
entity_src: &[EntityHandle],
);
#[deprecated_infallible]
pub fn copy_component(
entity_dst: EntityHandle,
entity_src: EntityHandle,
component_type: ComponentType,
);
#[deprecated(note = "Use `create_named_mesh_from_streams` instead")] #[with_memory]
pub fn create_mesh_from_streams(
primitive_topology: MeshPrimitiveTopology,
streams: &[MeshStreamLayout],
) -> FFIResult<MeshHandle>;
#[deprecated(note = "Use `create_data` instead")] #[with_memory]
pub fn create_named_mesh_from_streams(
primitive_topology: MeshPrimitiveTopology,
streams: &[MeshStreamLayout],
name: &str,
) -> FFIResult<MeshHandle>;
#[deprecated_infallible]
pub fn get_mesh_properties(handle: MeshHandle) -> MeshProperties;
#[deprecated_infallible]
pub fn get_mesh_morph_target_count(handle: MeshHandle) -> u32;
#[deprecated_infallible]
pub fn get_mesh_morph_target_name_len(handle: MeshHandle, idx: u32) -> u32;
#[deprecated_infallible]
pub fn get_mesh_morph_target_name(handle: MeshHandle, idx: u32, name: &mut [u8]);
#[deprecated_infallible]
pub fn get_mesh_material_count(handle: MeshHandle) -> u64;
#[deprecated_infallible]
pub fn get_mesh_material_desc(handle: MeshHandle, idx: u64) -> MaterialDesc;
#[deprecated_infallible]
pub fn get_mesh_material_name(handle: MeshHandle, idx: u64, out_name: &mut [u8]) -> u64;
#[deprecated_infallible]
pub fn set_mesh_offset(handle: MeshHandle, matrix: &[f32]);
#[deprecated(note = "Use `destroy_data` instead")] #[deprecated_infallible]
pub fn destroy_mesh(handle: MeshHandle);
#[deprecated_infallible]
pub fn set_entity_value_checked(
entity: EntityHandle,
component: ComponentType,
param_id: u32,
value: &Value,
);
#[deprecated_infallible]
pub fn get_entity_value_checked(
entity: EntityHandle,
component: ComponentType,
param_id: u32,
value: &mut Value,
);
#[deprecated_infallible]
pub fn ray_cast(
ray: &Ray,
min_t: f32,
max_t: f32,
any_hit: u32,
hit_t: &mut f32,
exclude_entity: EntityHandle,
) -> EntityHandle;
#[deprecated(note = "Use `send_messages` instead")] #[deprecated_infallible]
pub fn push_message(entity: EntityHandle, message: &Message);
#[deprecated(note = "Use `get_message_counts` instead")] #[deprecated_infallible]
pub fn has_message(entity: EntityHandle) -> u32;
#[deprecated(note = "Use `retrieve_messages` instead")] #[deprecated_infallible]
pub fn pop_message(entity: EntityHandle, msg: &mut Message);
pub fn send_messages(
message_struct_size: u32,
range_and_receiever: &[MessageRangeAndReceiver],
messages: &[Message],
);
pub fn get_message_counts(
message_struct_size: u32,
entities: &[EntityHandle],
out_counts: &mut [u32],
out_total: &mut u32,
);
pub fn retrieve_messages(
message_struct_size: u32,
entities: &[EntityHandle],
out_msgs: &mut [Message],
);
#[deprecated_infallible]
pub fn get_components(entity: EntityHandle, components: &mut [ComponentType]) -> u32;
#[with_memory]
#[deprecated_infallible]
pub fn create_data(create_data_type: CreateDataType, data: &[u8]) -> DataHandle;
#[deprecated_infallible]
pub fn retrieve_data(
data_handle: DataHandle,
retrieve_data_type: RetrieveDataType,
data: &mut [u8],
) -> u32;
#[deprecated_infallible]
pub fn destroy_data(data: DataHandle);
#[deprecated_infallible]
pub fn retain_data(data: DataHandle);
#[deprecated_infallible]
pub fn is_valid_data(data: DataHandle) -> u32;
}
}
pub use world::*;