@@ -424,104 +424,134 @@ void OpenXRFbPassthroughExtensionWrapper::stop_passthrough() {
424
424
}
425
425
426
426
XrGeometryInstanceFB OpenXRFbPassthroughExtensionWrapper::create_geometry_instance (const Ref<Mesh> &p_mesh, const Transform3D &p_transform) {
427
- ERR_FAIL_COND_V (p_mesh.is_null (), XR_NULL_HANDLE);
428
-
429
- if (!is_passthrough_started ()) {
430
- UtilityFunctions::print (" Tried to create geometry instance, but passthrough isn't started!" );
431
- return XR_NULL_HANDLE;
432
- }
433
-
434
- Array surface_arrays = p_mesh->surface_get_arrays (0 );
435
-
436
- Array vertex_array = surface_arrays[Mesh::ARRAY_VERTEX];
437
- LocalVector<XrVector3f> vertices;
438
- vertices.resize (vertex_array.size ());
439
- for (int j = 0 ; j < vertex_array.size (); j++) {
440
- Vector3 vertex = vertex_array[j];
441
- vertices[j] = { vertex.x , vertex.y , vertex.z };
442
- }
443
-
444
- Array index_array = surface_arrays[Mesh::ARRAY_INDEX];
445
- LocalVector<uint32_t > indices;
446
- indices.resize (index_array.size ());
447
- for (int j = 0 ; j < index_array.size (); j++) {
448
- indices[j] = index_array[j];
449
- }
450
-
451
- XrTriangleMeshFB mesh = XR_NULL_HANDLE;
452
- XrTriangleMeshCreateInfoFB triangle_mesh_info = {
453
- XR_TYPE_TRIANGLE_MESH_CREATE_INFO_FB, // type
454
- nullptr , // next
455
- 0 , // flags
456
- XR_WINDING_ORDER_CW_FB, // windingOrder
457
- (uint32_t )vertex_array.size (), // vertexCount
458
- vertices.ptr (), // vertexBuffer
459
- (uint32_t )index_array.size (), // triangleCount
460
- indices.ptr (), // indexBuffer
461
- };
462
-
463
- XrResult result = xrCreateTriangleMeshFB (SESSION, &triangle_mesh_info, &mesh);
464
- if (XR_FAILED (result)) {
465
- UtilityFunctions::print (" Failed to create triangle mesh, error code: " , result);
466
- return XR_NULL_HANDLE;
467
- }
468
-
469
- Transform3D reference_frame = XRServer::get_singleton ()->get_reference_frame ();
470
- Transform3D transform = reference_frame.inverse () * p_transform;
471
-
472
- Quaternion quat = transform.basis .get_rotation_quaternion ();
473
- Vector3 scale = transform.basis .get_scale ();
474
-
475
- XrQuaternionf xr_orientation = { quat.x , quat.y , quat.z , quat.w };
476
- XrVector3f xr_position = { transform.origin .x , transform.origin .y , transform.origin .z };
477
- XrPosef xr_pose = { xr_orientation, xr_position };
478
- XrVector3f xr_scale = { scale.x , scale.y , scale.z };
479
-
480
- XrGeometryInstanceFB geometry_instance = XR_NULL_HANDLE;
481
- XrGeometryInstanceCreateInfoFB geometry_instance_info = {
482
- XR_TYPE_GEOMETRY_INSTANCE_CREATE_INFO_FB, // type
483
- nullptr , // next
484
- passthrough_layer[LAYER_PURPOSE_PROJECTED], // layer
485
- mesh, // mesh
486
- (XrSpace)get_openxr_api ()->get_play_space (), // baseSpace
487
- xr_pose, // pose
488
- xr_scale, // scale
489
- };
490
-
491
- result = xrCreateGeometryInstanceFB (SESSION, &geometry_instance_info, &geometry_instance);
492
- if (XR_FAILED (result)) {
493
- UtilityFunctions::print (" Failed to create geometry instance, error code: " , result);
494
- return XR_NULL_HANDLE;
495
- }
496
-
497
- return geometry_instance;
427
+ ERR_FAIL_COND_V (p_mesh.is_null (), XR_NULL_HANDLE);
428
+
429
+ if (!is_passthrough_started ()) {
430
+ UtilityFunctions::print (" Tried to create geometry instance, but passthrough isn't started!" );
431
+ return XR_NULL_HANDLE;
432
+ }
433
+
434
+ Array surface_arrays = p_mesh->surface_get_arrays (0 );
435
+
436
+ Array vertex_array = surface_arrays[Mesh::ARRAY_VERTEX];
437
+ LocalVector<XrVector3f> vertices;
438
+ vertices.resize (vertex_array.size ());
439
+ for (int j = 0 ; j < vertex_array.size (); j++) {
440
+ Vector3 vertex = vertex_array[j];
441
+ vertices[j] = {
442
+ static_cast <float >(vertex.x ),
443
+ static_cast <float >(vertex.y ),
444
+ static_cast <float >(vertex.z )
445
+ };
446
+ }
447
+
448
+ Array index_array = surface_arrays[Mesh::ARRAY_INDEX];
449
+ LocalVector<uint32_t > indices;
450
+ indices.resize (index_array.size ());
451
+ for (int j = 0 ; j < index_array.size (); j++) {
452
+ indices[j] = index_array[j];
453
+ }
454
+
455
+ XrTriangleMeshFB mesh = XR_NULL_HANDLE;
456
+ XrTriangleMeshCreateInfoFB triangle_mesh_info = {
457
+ XR_TYPE_TRIANGLE_MESH_CREATE_INFO_FB, // type
458
+ nullptr , // next
459
+ 0 , // flags
460
+ XR_WINDING_ORDER_CW_FB, // windingOrder
461
+ static_cast <uint32_t >(vertex_array.size ()), // vertexCount
462
+ vertices.ptr (), // vertexBuffer
463
+ static_cast <uint32_t >(index_array.size ()), // triangleCount
464
+ indices.ptr (), // indexBuffer
465
+ };
466
+
467
+ XrResult result = xrCreateTriangleMeshFB (SESSION, &triangle_mesh_info, &mesh);
468
+ if (XR_FAILED (result)) {
469
+ UtilityFunctions::print (" Failed to create triangle mesh, error code: " , result);
470
+ return XR_NULL_HANDLE;
471
+ }
472
+
473
+ Transform3D reference_frame = XRServer::get_singleton ()->get_reference_frame ();
474
+ Transform3D transform = reference_frame.inverse () * p_transform;
475
+
476
+ Quaternion quat = transform.basis .get_rotation_quaternion ();
477
+ Vector3 scale = transform.basis .get_scale ();
478
+
479
+ XrQuaternionf xr_orientation = {
480
+ static_cast <float >(quat.x ),
481
+ static_cast <float >(quat.y ),
482
+ static_cast <float >(quat.z ),
483
+ static_cast <float >(quat.w )
484
+ };
485
+ XrVector3f xr_position = {
486
+ static_cast <float >(transform.origin .x ),
487
+ static_cast <float >(transform.origin .y ),
488
+ static_cast <float >(transform.origin .z )
489
+ };
490
+ XrPosef xr_pose = { xr_orientation, xr_position };
491
+ XrVector3f xr_scale = {
492
+ static_cast <float >(scale.x ),
493
+ static_cast <float >(scale.y ),
494
+ static_cast <float >(scale.z )
495
+ };
496
+
497
+ XrGeometryInstanceFB geometry_instance = XR_NULL_HANDLE;
498
+ XrGeometryInstanceCreateInfoFB geometry_instance_info = {
499
+ XR_TYPE_GEOMETRY_INSTANCE_CREATE_INFO_FB, // type
500
+ nullptr , // next
501
+ passthrough_layer[LAYER_PURPOSE_PROJECTED], // layer
502
+ mesh, // mesh
503
+ reinterpret_cast <XrSpace>(get_openxr_api ()->get_play_space ()), // baseSpace
504
+ xr_pose, // pose
505
+ xr_scale, // scale
506
+ };
507
+
508
+ result = xrCreateGeometryInstanceFB (SESSION, &geometry_instance_info, &geometry_instance);
509
+ if (XR_FAILED (result)) {
510
+ UtilityFunctions::print (" Failed to create geometry instance, error code: " , result);
511
+ return XR_NULL_HANDLE;
512
+ }
513
+
514
+ return geometry_instance;
498
515
}
499
516
500
517
void OpenXRFbPassthroughExtensionWrapper::set_geometry_instance_transform (XrGeometryInstanceFB p_geometry_instance, const Transform3D &p_transform) {
501
- Transform3D reference_frame = XRServer::get_singleton ()->get_reference_frame ();
502
- Transform3D transform = reference_frame.inverse () * p_transform;
503
-
504
- Quaternion quat = transform.basis .get_rotation_quaternion ();
505
- Vector3 scale = transform.basis .get_scale ();
506
-
507
- XrQuaternionf xr_orientation = { quat.x , quat.y , quat.z , quat.w };
508
- XrVector3f xr_position = { transform.origin .x , transform.origin .y , transform.origin .z };
509
- XrPosef xr_pose = { xr_orientation, xr_position };
510
- XrVector3f xr_scale = { scale.x , scale.y , scale.z };
511
-
512
- XrGeometryInstanceTransformFB xr_transform = {
513
- XR_TYPE_GEOMETRY_INSTANCE_TRANSFORM_FB, // type
514
- nullptr , // next
515
- (XrSpace)get_openxr_api ()->get_play_space (), // baseSpace
516
- (XrTime)get_openxr_api ()->get_predicted_display_time (), // time
517
- xr_pose, // pose
518
- xr_scale, // scale
519
- };
520
-
521
- XrResult result = xrGeometryInstanceSetTransformFB (p_geometry_instance, &xr_transform);
522
- if (XR_FAILED (result)) {
523
- UtilityFunctions::print (" Failed to set geometry instance transform, error code: " , result);
524
- }
518
+ Transform3D reference_frame = XRServer::get_singleton ()->get_reference_frame ();
519
+ Transform3D transform = reference_frame.inverse () * p_transform;
520
+
521
+ Quaternion quat = transform.basis .get_rotation_quaternion ();
522
+ Vector3 scale = transform.basis .get_scale ();
523
+
524
+ XrQuaternionf xr_orientation = {
525
+ static_cast <float >(quat.x ),
526
+ static_cast <float >(quat.y ),
527
+ static_cast <float >(quat.z ),
528
+ static_cast <float >(quat.w )
529
+ };
530
+ XrVector3f xr_position = {
531
+ static_cast <float >(transform.origin .x ),
532
+ static_cast <float >(transform.origin .y ),
533
+ static_cast <float >(transform.origin .z )
534
+ };
535
+ XrPosef xr_pose = { xr_orientation, xr_position };
536
+ XrVector3f xr_scale = {
537
+ static_cast <float >(scale.x ),
538
+ static_cast <float >(scale.y ),
539
+ static_cast <float >(scale.z )
540
+ };
541
+
542
+ XrGeometryInstanceTransformFB xr_transform = {
543
+ XR_TYPE_GEOMETRY_INSTANCE_TRANSFORM_FB, // type
544
+ nullptr , // next
545
+ reinterpret_cast <XrSpace>(get_openxr_api ()->get_play_space ()), // baseSpace (safer cast)
546
+ static_cast <XrTime>(get_openxr_api ()->get_predicted_display_time ()), // time
547
+ xr_pose, // pose
548
+ xr_scale, // scale
549
+ };
550
+
551
+ XrResult result = xrGeometryInstanceSetTransformFB (p_geometry_instance, &xr_transform);
552
+ if (XR_FAILED (result)) {
553
+ UtilityFunctions::print (" Failed to set geometry instance transform, error code: " , result);
554
+ }
525
555
}
526
556
527
557
void OpenXRFbPassthroughExtensionWrapper::destroy_geometry_instance (XrGeometryInstanceFB p_geometry_instance) {
0 commit comments