Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OpenXR extension wrappers for fb_scene, fb_spatial_entity, fb_spatial_entity_query, fb_spatial_entity_container #66

Merged
merged 5 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ This plugin has been developed by or received contributions from:
- [Daniel Castellanos](https://github.com/decacis)
- [Rodolphe Houdas](https://github.com/rodolpheh)
- [Tiago Zaccaro](https://github.com/tiagozaccaro)
- [Mauricio Narvaez](https://github.com/maunvz)
2 changes: 2 additions & 0 deletions common/src/main/cpp/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,6 @@
return (*func_name##_ptr)(p_##arg1, p_##arg2, p_##arg3, p_##arg4, p_##arg5, p_##arg6); \
}

#define SESSION (XrSession) get_openxr_api()->get_session()

#endif // UTIL_H
21 changes: 21 additions & 0 deletions godotopenxrmeta/src/main/cpp/export/meta_export_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ MetaEditorExportPlugin::MetaEditorExportPlugin() {
false,
false
);
_use_scene_api_option = _generate_export_option(
"meta_xr_features/use_scene_api",
"",
Variant::Type::BOOL,
PROPERTY_HINT_NONE,
"",
PROPERTY_USAGE_DEFAULT,
false,
false
);
_support_quest_1_option = _generate_export_option(
"meta_xr_features/quest_1_support",
"",
Expand Down Expand Up @@ -160,6 +170,7 @@ TypedArray<Dictionary> MetaEditorExportPlugin::_get_export_options(const Ref<Edi
export_options.append(_hand_tracking_frequency_option);
export_options.append(_passthrough_option);
export_options.append(_use_anchor_api_option);
export_options.append(_use_scene_api_option);
export_options.append(_support_quest_1_option);
export_options.append(_support_quest_2_option);
export_options.append(_support_quest_3_option);
Expand Down Expand Up @@ -238,6 +249,10 @@ String MetaEditorExportPlugin::_get_export_option_warning(const Ref<EditorExport
if (!openxr_enabled && _get_bool_option(option)) {
return "\"Use anchor API\" is only valid when \"XR Mode\" is \"OpenXR\".\n";
}
} else if (option == "meta_xr_features/use_scene_api") {
if (!openxr_enabled && _get_bool_option(option)) {
return "\"Use scene API\" is only valid when \"XR Mode\" is \"OpenXR\".\n";
}
}

return OpenXREditorExportPlugin::_get_export_option_warning(platform, option);
Expand Down Expand Up @@ -287,6 +302,12 @@ String MetaEditorExportPlugin::_get_android_manifest_element_contents(const Ref<
contents += " <uses-permission android:name=\"com.oculus.permission.USE_ANCHOR_API\" />\n";
}

// Check for scene api
bool use_scene_api = _get_bool_option("meta_xr_features/use_scene_api");
if (use_scene_api) {
contents += " <uses-permission android:name=\"com.oculus.permission.USE_SCENE\" />\n";
}

return contents;
}

Expand Down
1 change: 1 addition & 0 deletions godotopenxrmeta/src/main/cpp/export/meta_export_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class MetaEditorExportPlugin : public OpenXREditorExportPlugin {
Dictionary _hand_tracking_frequency_option;
Dictionary _passthrough_option;
Dictionary _use_anchor_api_option;
Dictionary _use_scene_api_option;
Dictionary _support_quest_1_option;
Dictionary _support_quest_2_option;
Dictionary _support_quest_3_option;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/**************************************************************************/
/* openxr_fb_scene_extension_wrapper.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT XR */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2022-present Godot XR contributors (see CONTRIBUTORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#pragma once

#include <godot_cpp/classes/open_xr_extension_wrapper_extension.hpp>
#include <openxr/openxr.h>
#include <openxr/fb_scene.h>
#include <godot_cpp/templates/hash_map.hpp>
#include <godot_cpp/templates/vector.hpp>
#include <godot_cpp/variant/utility_functions.hpp>

#include "util.h"

#include <optional>
#include <map>

using namespace godot;

struct XrSceneObjectInternal {
XrUuidEXT uuid;
XrSpace space;
std::optional<String> label;

// Vertices and lines on a plane, probably use this for a floor / ceiling as they are irregularly shaped
// We store a std::vector instead of XrBoundary2DFB to own the vertex memory
std::optional<Vector<XrVector2f>> boundary2D;
// A rectangle containing the whole thing, perfect for desks / tables / play surfaces
std::optional<XrRect2Df> boundingBox2D;
// 3D box for the whole thing, better for obstacles and other objects not used as a surface
std::optional<XrRect3DfFB> boundingBox3D;
};

// Wrapper for the set of Facebook XR scene extension.
class OpenXRFbSceneExtensionWrapper : public OpenXRExtensionWrapperExtension {
GDCLASS(OpenXRFbSceneExtensionWrapper, OpenXRExtensionWrapperExtension);

public:
Dictionary _get_requested_extensions() override;

void _on_instance_created(uint64_t instance) override;

void _on_instance_destroyed() override;

bool is_scene_supported() {
return fb_scene_ext;
}

static OpenXRFbSceneExtensionWrapper *get_singleton();

OpenXRFbSceneExtensionWrapper();
~OpenXRFbSceneExtensionWrapper();

std::optional<String> get_semantic_labels(const XrSpace& space);
void get_shapes(const XrSpace& space, XrSceneObjectInternal& object);

protected:
static void _bind_methods();

private:
EXT_PROTO_XRRESULT_FUNC3(xrGetSpaceBoundingBox2DFB,
(XrSession), session,
(XrSpace), space,
(XrRect2Df *), boundingBox2DOutput)

EXT_PROTO_XRRESULT_FUNC3(xrGetSpaceBoundingBox3DFB,
(XrSession), session,
(XrSpace), space,
(XrRect3DfFB *), boundingBox3DOutput)

EXT_PROTO_XRRESULT_FUNC3(xrGetSpaceSemanticLabelsFB,
(XrSession), session,
(XrSpace), space,
(XrSemanticLabelsFB *), semanticLabelsOutput)

EXT_PROTO_XRRESULT_FUNC3(xrGetSpaceBoundary2DFB,
(XrSession), session,
(XrSpace), space,
(XrBoundary2DFB *), boundary2DOutput)

EXT_PROTO_XRRESULT_FUNC3(xrGetSpaceRoomLayoutFB,
(XrSession), session,
(XrSpace), space,
(XrRoomLayoutFB *), roomLayoutOutput)

bool initialize_fb_scene_extension(const XrInstance instance);

HashMap<String, bool *> request_extensions;

void cleanup();

static OpenXRFbSceneExtensionWrapper *singleton;

bool fb_scene_ext = false;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**************************************************************************/
/* openxr_fb_spatial_entity_container_extension_wrapper.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT XR */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2022-present Godot XR contributors (see CONTRIBUTORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#pragma once

#include <godot_cpp/classes/open_xr_extension_wrapper_extension.hpp>
#include <openxr/openxr.h>
#include <openxr/fb_spatial_entity_container.h>
#include <godot_cpp/templates/hash_map.hpp>
#include <godot_cpp/templates/vector.hpp>
#include <godot_cpp/variant/utility_functions.hpp>

#include "util.h"

#include <functional>
#include <map>

using namespace godot;

// Wrapper for the set of Facebook XR spatial entity container extension.
class OpenXRFbSpatialEntityContainerExtensionWrapper : public OpenXRExtensionWrapperExtension {
GDCLASS(OpenXRFbSpatialEntityContainerExtensionWrapper, OpenXRExtensionWrapperExtension);

public:
Dictionary _get_requested_extensions() override;

void _on_instance_created(uint64_t instance) override;

void _on_instance_destroyed() override;

bool is_spatial_entity_container_supported() {
return fb_spatial_entity_container_ext;
}

static OpenXRFbSpatialEntityContainerExtensionWrapper *get_singleton();

Vector<XrUuidEXT> get_contained_uuids(const XrSpace& space);

OpenXRFbSpatialEntityContainerExtensionWrapper();
~OpenXRFbSpatialEntityContainerExtensionWrapper();

protected:
static void _bind_methods();

private:
EXT_PROTO_XRRESULT_FUNC3(xrGetSpaceContainerFB,
(XrSession), session,
(XrSpace), space,
(XrSpaceContainerFB *), spaceContainerOutput)

bool initialize_fb_spatial_entity_container_extension(const XrInstance& instance);

HashMap<String, bool *> request_extensions;

void cleanup();

static OpenXRFbSpatialEntityContainerExtensionWrapper *singleton;

bool fb_spatial_entity_container_ext = false;
};
Loading