diff --git a/demo/magicleap/Cargo.toml b/demo/magicleap/Cargo.toml index 75d5c6e1..ea310522 100644 --- a/demo/magicleap/Cargo.toml +++ b/demo/magicleap/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "pathfinder_immersive_demo" +name = "pathfinder_magicleap_demo" version = "0.1.0" edition = "2018" authors = ["Alan Jeffrey "] diff --git a/demo/magicleap/PathfinderDemo.package b/demo/magicleap/PathfinderDemo.package index de059c08..b0f672c6 100644 --- a/demo/magicleap/PathfinderDemo.package +++ b/demo/magicleap/PathfinderDemo.package @@ -1,2 +1,3 @@ -REFS = PathfinderDemo +USES = "lre/scenes" +REFS = PathfinderImmersiveDemo PathfinderLandscapeDemo OPTIONS=package/debuggable/on diff --git a/demo/magicleap/PathfinderImmersiveDemo.mabu b/demo/magicleap/PathfinderImmersiveDemo.mabu new file mode 100644 index 00000000..90209f53 --- /dev/null +++ b/demo/magicleap/PathfinderImmersiveDemo.mabu @@ -0,0 +1,19 @@ +KIND = program +SRCS = src/main.cpp + +LIBPATHS.debug = \ + ../../target/aarch64-linux-android/debug + +LIBPATHS.release = \ + ../../target/aarch64-linux-android/release + +USES = ml_sdk OpenGL stdc++ + +STLIBS = \ + pathfinder_magicleap_demo + +SHLIBS = \ + ml_privileges + +DATAS = \ + ../../resources/** : resources/ diff --git a/demo/magicleap/PathfinderLandscapeDemo.mabu b/demo/magicleap/PathfinderLandscapeDemo.mabu new file mode 100644 index 00000000..be11ba0e --- /dev/null +++ b/demo/magicleap/PathfinderLandscapeDemo.mabu @@ -0,0 +1,19 @@ +KIND = program +SRCS = src/landscape.cpp + +LIBPATHS.debug = \ + ../../target/aarch64-linux-android/debug + +LIBPATHS.release = \ + ../../target/aarch64-linux-android/release + +INCS = \ + src/ \ + lre/code/inc/gen/ + +USES = \ + lumin_runtime \ + lre/code/srcs + +STLIBS = \ + pathfinder_magicleap_demo diff --git a/demo/magicleap/lre/.gitignore b/demo/magicleap/lre/.gitignore new file mode 100644 index 00000000..7eae926b --- /dev/null +++ b/demo/magicleap/lre/.gitignore @@ -0,0 +1,12 @@ +.DS_Store +*.log +*.json.dirty +*.json.lock +*.pyc +*.sln +*.vcxproj* + +pipeline/cache/intermediate/ +.out/ +.vscode/ +.vs/ diff --git a/demo/magicleap/lre/PathfinderDemo.draft b/demo/magicleap/lre/PathfinderDemo.draft new file mode 100644 index 00000000..4df9e299 --- /dev/null +++ b/demo/magicleap/lre/PathfinderDemo.draft @@ -0,0 +1,183 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/demo/magicleap/lre/PathfinderDemo.mabu b/demo/magicleap/lre/PathfinderDemo.mabu new file mode 100644 index 00000000..92bb5f7d --- /dev/null +++ b/demo/magicleap/lre/PathfinderDemo.mabu @@ -0,0 +1,13 @@ +KIND = program + +INCS = \ + code/inc/ \ + code/inc/gen/ + +SRCS = \ + code/src/main.cpp \ + code/src/PathfinderDemo.cpp + +USES = \ + lumin_runtime \ + code/srcs diff --git a/demo/magicleap/lre/PathfinderDemo.mlproject b/demo/magicleap/lre/PathfinderDemo.mlproject new file mode 100644 index 00000000..60d8ace3 --- /dev/null +++ b/demo/magicleap/lre/PathfinderDemo.mlproject @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/demo/magicleap/lre/PathfinderDemo.package b/demo/magicleap/lre/PathfinderDemo.package new file mode 100644 index 00000000..49a402ec --- /dev/null +++ b/demo/magicleap/lre/PathfinderDemo.package @@ -0,0 +1,3 @@ + +USES = "scenes" "pipeline/cache/AssetManifest" +REFS = PathfinderDemo \ No newline at end of file diff --git a/demo/magicleap/lre/code/inc/PathfinderDemo.h b/demo/magicleap/lre/code/inc/PathfinderDemo.h new file mode 100644 index 00000000..0cbefd4a --- /dev/null +++ b/demo/magicleap/lre/code/inc/PathfinderDemo.h @@ -0,0 +1,99 @@ +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#include +#include +#include +#include +#include + +/** + * PathfinderDemo Landscape Application + */ +class PathfinderDemo : public lumin::LandscapeApp { +public: + /** + * Constructs the Landscape Application. + */ + PathfinderDemo(); + + /** + * Destroys the Landscape Application. + */ + virtual ~PathfinderDemo(); + + /** + * Disallows the copy constructor. + */ + PathfinderDemo(const PathfinderDemo&) = delete; + + /** + * Disallows the move constructor. + */ + PathfinderDemo(PathfinderDemo&&) = delete; + + /** + * Disallows the copy assignment operator. + */ + PathfinderDemo& operator=(const PathfinderDemo&) = delete; + + /** + * Disallows the move assignment operator. + */ + PathfinderDemo& operator=(PathfinderDemo&&) = delete; + +protected: + /** + * Initializes the Landscape Application. + * @return - 0 on success, error code on failure. + */ + int init() override; + + /** + * Deinitializes the Landscape Application. + * @return - 0 on success, error code on failure. + */ + int deInit() override; + + /** + * Returns the initial size of the Prism + * Used in createPrism(). + */ + const glm::vec3 getInitialPrismSize() const; + + /** + * Creates the prism, updates the private variable prism_ with the created prism. + */ + void createInitialPrism(); + + /** + * Initializes and creates the scene of all scenes marked as initially instanced + */ + void spawnInitialScenes(); + + /** + * Run application login + */ + virtual bool updateLoop(float fDelta) override; + + /** + * Handle events from the server + */ + virtual bool eventListener(lumin::ServerEvent* event) override; + +private: + lumin::Prism* prism_ = nullptr; // represents the bounded space where the App renders. + PrismSceneManager* prismSceneManager_ = nullptr; +}; + diff --git a/demo/magicleap/lre/code/inc/gen/PathfinderDemo/PathfinderDemo.h b/demo/magicleap/lre/code/inc/gen/PathfinderDemo/PathfinderDemo.h new file mode 100644 index 00000000..e408f388 --- /dev/null +++ b/demo/magicleap/lre/code/inc/gen/PathfinderDemo/PathfinderDemo.h @@ -0,0 +1,45 @@ +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- +// +// THE CONTENTS OF THIS FILE IS GENERATED BY CODE AND +// ANY MODIFICATIONS WILL BE OVERWRITTEN +// +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- + +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#pragma once + +#include +#include + +namespace scenes { + + namespace PathfinderDemo { + + namespace externalNodes { + } + + struct SpawnedScene : public SpawnedSceneBase { + SpawnedScene(const SceneDescriptor& sceneDescriptor, lumin::Node* root); + ~SpawnedScene(); + }; + + SpawnedSceneBase* createSpawnedScene(const SceneDescriptor& sceneDescriptor, lumin::Node* root); + SpawnedSceneHandlers* createSpawnedSceneHandlers(SpawnedSceneBase& spawnedScene); + + extern const SceneDescriptor descriptor; + } +} + diff --git a/demo/magicleap/lre/code/inc/gen/PrismSceneManager.h b/demo/magicleap/lre/code/inc/gen/PrismSceneManager.h new file mode 100644 index 00000000..82d43212 --- /dev/null +++ b/demo/magicleap/lre/code/inc/gen/PrismSceneManager.h @@ -0,0 +1,74 @@ +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- +// +// THE CONTENTS OF THIS FILE IS GENERATED BY CODE AND +// ANY MODIFICATIONS WILL BE OVERWRITTEN +// +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- + +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#pragma once + +#include +#include + +#include +#include +#include +#include + +class PrismSceneManager { + public: + + typedef std::function (*CreateSpawnedSceneUserData); + static void setUserDataCreator(const SceneDescriptor & sceneDescriptor, CreateSpawnedSceneUserData createSpawnedSceneUserData); + + public: + + PrismSceneManager(lumin::Prism* prism); + + enum class SceneState { + Unloaded, + ResourceModelLoaded, + ResourceAndObjectModelLoaded, + }; + + void setSceneState(const SceneDescriptor & sceneDescriptor, SceneState sceneState); + SceneState getSceneState(const SceneDescriptor & sceneDescriptor, SceneState sceneState) const; + + SpawnedSceneBase* spawnScene(const SceneDescriptor & sceneDescriptor); + lumin::Node* spawn(const SceneDescriptor & sceneDescriptor); + + private: + + typedef SpawnedSceneBase* (*CreateSpawnedScene)(const SceneDescriptor& sceneDescriptor, lumin::Node* root); + static const CreateSpawnedScene createSpawnedScene[scenes::numberOfExternalScenes]; + + typedef SpawnedSceneHandlers* (*CreateSpawnedSceneHandlers)(SpawnedSceneBase& spawnedScene); + static const CreateSpawnedSceneHandlers createSpawnedSceneHandlers[scenes::numberOfExternalScenes]; + + static CreateSpawnedSceneUserData createSpawnedSceneUserData[scenes::numberOfExternalScenes]; + + private: + + lumin::Node* createNodeTree(const SceneDescriptor & sceneDescriptor); + + private: + + lumin::Prism* prism_; + SceneState sceneStates_[scenes::numberOfExternalScenes]; + std::string objectModelNames_[scenes::numberOfExternalScenes]; +}; + diff --git a/demo/magicleap/lre/code/inc/gen/SceneDescriptor.h b/demo/magicleap/lre/code/inc/gen/SceneDescriptor.h new file mode 100644 index 00000000..c1b42119 --- /dev/null +++ b/demo/magicleap/lre/code/inc/gen/SceneDescriptor.h @@ -0,0 +1,58 @@ +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- +// +// THE CONTENTS OF THIS FILE IS GENERATED BY CODE AND +// ANY MODIFICATIONS WILL BE OVERWRITTEN +// +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- + +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#pragma once + +#include +#include + +// data class +class SceneDescriptor { + public: + + typedef std::map ExternalNodeReferences; + + SceneDescriptor(int index, const char* externalName, const char* id, const char* sceneGraphFilePath, const char* resourceModelFilePath, const ExternalNodeReferences& externalNodeReferences, bool initiallySpawned); + const std::string& getExternalName() const; + const std::string& getId() const; + const std::string& getSceneGraphPath() const; + const std::string& getResourceModelPath() const; + const ExternalNodeReferences & getExternalNodeReferences() const; + bool getInitiallySpawned() const; + + private: + + friend class PrismSceneManager; + int getIndex() const; + + private: + + int index_; + std::string externalName_; + std::string id_; + std::string sceneGraphPath_; + std::string resourceModelPath_; + const ExternalNodeReferences& externalNodeReferences_; + bool initiallySpawned_; +}; + +bool operator<(const SceneDescriptor& a, const SceneDescriptor& b); + diff --git a/demo/magicleap/lre/code/inc/gen/SpawnedSceneBase.h b/demo/magicleap/lre/code/inc/gen/SpawnedSceneBase.h new file mode 100644 index 00000000..4b597bfd --- /dev/null +++ b/demo/magicleap/lre/code/inc/gen/SpawnedSceneBase.h @@ -0,0 +1,43 @@ +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- +// +// THE CONTENTS OF THIS FILE IS GENERATED BY CODE AND +// ANY MODIFICATIONS WILL BE OVERWRITTEN +// +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- + +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#pragma once + +#include + +class SceneDescriptor; +class SpawnedSceneHandlers; +struct SpawnedSceneUserData; + +struct SpawnedSceneBase { + SpawnedSceneBase(const SceneDescriptor &sd, lumin::Node* rt); + virtual ~SpawnedSceneBase(); + + SpawnedSceneBase() = delete; + SpawnedSceneBase(const SpawnedSceneBase&) = delete; + SpawnedSceneBase(const SpawnedSceneBase&&) = delete; + + const SceneDescriptor& sceneDescriptor; + lumin::Node* root = nullptr; + SpawnedSceneHandlers* handlers = nullptr; + SpawnedSceneUserData* userData = nullptr; +}; + diff --git a/demo/magicleap/lre/code/inc/gen/SpawnedSceneHandlers.h b/demo/magicleap/lre/code/inc/gen/SpawnedSceneHandlers.h new file mode 100644 index 00000000..071a9c9b --- /dev/null +++ b/demo/magicleap/lre/code/inc/gen/SpawnedSceneHandlers.h @@ -0,0 +1,31 @@ +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- +// +// THE CONTENTS OF THIS FILE IS GENERATED BY CODE AND +// ANY MODIFICATIONS WILL BE OVERWRITTEN +// +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- + +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#pragma once + +struct SpawnedSceneBase; + +class SpawnedSceneHandlers { +public: + SpawnedSceneHandlers(SpawnedSceneBase& ssb); + virtual ~SpawnedSceneHandlers(); +}; + diff --git a/demo/magicleap/lre/code/inc/gen/SpawnedSceneUserData.h b/demo/magicleap/lre/code/inc/gen/SpawnedSceneUserData.h new file mode 100644 index 00000000..936efea6 --- /dev/null +++ b/demo/magicleap/lre/code/inc/gen/SpawnedSceneUserData.h @@ -0,0 +1,27 @@ +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- +// +// THE CONTENTS OF THIS FILE IS GENERATED BY CODE AND +// ANY MODIFICATIONS WILL BE OVERWRITTEN +// +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- + +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#pragma once + +struct SpawnedSceneUserData { + virtual ~SpawnedSceneUserData(); +}; + diff --git a/demo/magicleap/lre/code/inc/gen/scenes.h b/demo/magicleap/lre/code/inc/gen/scenes.h new file mode 100644 index 00000000..73f00a03 --- /dev/null +++ b/demo/magicleap/lre/code/inc/gen/scenes.h @@ -0,0 +1,33 @@ +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- +// +// THE CONTENTS OF THIS FILE IS GENERATED BY CODE AND +// ANY MODIFICATIONS WILL BE OVERWRITTEN +// +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- + +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#pragma once + +#include +#include + +namespace scenes { + const int numberOfExternalScenes = 1; + + typedef std::map SceneDescriptorReferences; + extern const SceneDescriptorReferences externalScenes; +} + diff --git a/demo/magicleap/lre/code/src/PathfinderDemo.cpp b/demo/magicleap/lre/code/src/PathfinderDemo.cpp new file mode 100644 index 00000000..fb8d1651 --- /dev/null +++ b/demo/magicleap/lre/code/src/PathfinderDemo.cpp @@ -0,0 +1,102 @@ +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#include +#include +#include +#include +#include +#include + +PathfinderDemo::PathfinderDemo() { + ML_LOG(Debug, "PathfinderDemo Constructor."); + + // Place your constructor implementation here. +} + +PathfinderDemo::~PathfinderDemo() { + ML_LOG(Debug, "PathfinderDemo Destructor."); + + // Place your destructor implementation here. +} + +const glm::vec3 PathfinderDemo::getInitialPrismSize() const { + return glm::vec3(2.0f, 2.0f, 2.0f); +} + +void PathfinderDemo::createInitialPrism() { + prism_ = requestNewPrism(getInitialPrismSize()); + if (!prism_) { + ML_LOG(Error, "PathfinderDemo Error creating default prism."); + abort(); + } + prismSceneManager_ = new PrismSceneManager(prism_); +} + +int PathfinderDemo::init() { + + ML_LOG(Debug, "PathfinderDemo Initializing."); + + createInitialPrism(); + lumin::ui::Cursor::SetScale(prism_, 0.03f); + spawnInitialScenes(); + + // Place your initialization here. + + return 0; +} + +int PathfinderDemo::deInit() { + ML_LOG(Debug, "PathfinderDemo Deinitializing."); + + // Place your deinitialization here. + + return 0; +} + +void PathfinderDemo::spawnInitialScenes() { + + // Iterate over all the exported scenes + for (auto& exportedSceneEntry : scenes::externalScenes ) { + + // If this scene was marked to be instanced at app initialization, do it + const SceneDescriptor &sd = exportedSceneEntry.second; + if (sd.getInitiallySpawned()) { + lumin::Node* const spawnedRoot = prismSceneManager_->spawn(sd); + if (spawnedRoot) { + if (!prism_->getRootNode()->addChild(spawnedRoot)) { + ML_LOG(Error, "PathfinderDemo Failed to add spawnedRoot to the prism root node"); + abort(); + } + } + } + } +} + +bool PathfinderDemo::updateLoop(float fDelta) { + + // Place your update here. + + // Return true for your app to continue running, false to terminate the app. + return true; +} + +bool PathfinderDemo::eventListener(lumin::ServerEvent* event) { + + // Place your event handling here. + + // Return true if the event is consumed. + return false; +} + diff --git a/demo/magicleap/lre/code/src/gen/PathfinderDemo/PathfinderDemo.cpp b/demo/magicleap/lre/code/src/gen/PathfinderDemo/PathfinderDemo.cpp new file mode 100644 index 00000000..9d63c0d7 --- /dev/null +++ b/demo/magicleap/lre/code/src/gen/PathfinderDemo/PathfinderDemo.cpp @@ -0,0 +1,63 @@ +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- +// +// THE CONTENTS OF THIS FILE IS GENERATED BY CODE AND +// ANY MODIFICATIONS WILL BE OVERWRITTEN +// +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- + +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#include +#include +#include + +namespace scenes { + + namespace PathfinderDemo { + + SpawnedScene::SpawnedScene(const SceneDescriptor& sceneDescriptor, lumin::Node* root) + : SpawnedSceneBase(sceneDescriptor, root) { + } + + SpawnedScene::~SpawnedScene() { + } + + SpawnedSceneBase* createSpawnedScene(const SceneDescriptor& sceneDescriptor, lumin::Node* root) { + using namespace externalNodes; + SpawnedScene* spawnedScene = new SpawnedScene(sceneDescriptor, root); + return spawnedScene; + } + + class Handlers : public SpawnedSceneHandlers + { + public: + Handlers(SpawnedScene& ss); + + private: + + }; + + + Handlers::Handlers(SpawnedScene& ss) + : SpawnedSceneHandlers(ss) + { + } + + SpawnedSceneHandlers* createSpawnedSceneHandlers(SpawnedSceneBase& ssb) { + return new Handlers(static_cast(ssb)); + } + } +} + diff --git a/demo/magicleap/lre/code/src/gen/PrismSceneManager.cpp b/demo/magicleap/lre/code/src/gen/PrismSceneManager.cpp new file mode 100644 index 00000000..7a8aee9f --- /dev/null +++ b/demo/magicleap/lre/code/src/gen/PrismSceneManager.cpp @@ -0,0 +1,124 @@ +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- +// +// THE CONTENTS OF THIS FILE IS GENERATED BY CODE AND +// ANY MODIFICATIONS WILL BE OVERWRITTEN +// +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- + +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#include + +#include + +PrismSceneManager::CreateSpawnedSceneUserData PrismSceneManager::createSpawnedSceneUserData[scenes::numberOfExternalScenes]; + +PrismSceneManager::PrismSceneManager(lumin::Prism* prism) +: prism_(prism) { + + if (!prism_) { + ML_LOG(Error, "PrismSceneManager nullptr prism"); + abort(); + } + + for (int i = 0; i < sizeof(sceneStates_)/sizeof(sceneStates_[0]); ++i) { + sceneStates_[i] = SceneState::Unloaded; + } +} + +void PrismSceneManager::setSceneState(const SceneDescriptor & sceneDescriptor, SceneState newState) { + + const int sceneIndex = sceneDescriptor.getIndex(); + SceneState& sceneState = sceneStates_[sceneIndex]; + std::string& objectModelName = objectModelNames_[sceneIndex]; + + if (sceneState == SceneState::Unloaded && (newState == SceneState::ResourceModelLoaded || newState == SceneState::ResourceAndObjectModelLoaded)) { + if (!prism_->loadResourceModel(sceneDescriptor.getResourceModelPath())) { + ML_LOG(Error, "PrismSceneManager failed to load resource model"); + abort(); + } + sceneState = SceneState::ResourceModelLoaded; + } + + if (sceneState == SceneState::ResourceModelLoaded && newState == SceneState::ResourceAndObjectModelLoaded) { + std::string& objectModelName = objectModelNames_[sceneIndex]; + if (!prism_->loadObjectModel(sceneDescriptor.getSceneGraphPath(), objectModelName)) { + ML_LOG(Error, "PrismSceneManager failed to load object model"); + abort(); + } + sceneState = SceneState::ResourceAndObjectModelLoaded; + } + + if (sceneState == SceneState::ResourceAndObjectModelLoaded && (newState == SceneState::ResourceModelLoaded || newState == SceneState::Unloaded)) { + if (!prism_->unloadObjectModel(objectModelName)) { + ML_LOG(Error, "PrismSceneManager failed to unload object model"); + abort(); + } + sceneState = SceneState::ResourceModelLoaded; + objectModelName.clear(); + } + + // Currently there is no effective way to unload the resource model +} + +SpawnedSceneBase* PrismSceneManager::spawnScene(const SceneDescriptor & sceneDescriptor) { + + lumin::Node* root = createNodeTree(sceneDescriptor); + if (!root) { + return nullptr; + } + + const int index = sceneDescriptor.getIndex(); + CreateSpawnedScene css = createSpawnedScene[index]; + SpawnedSceneBase* const spawnedScene = (*css)(sceneDescriptor, root); + + CreateSpawnedSceneHandlers ch = createSpawnedSceneHandlers[index]; + SpawnedSceneHandlers* const handlers = (*ch)(*spawnedScene); + spawnedScene->handlers = handlers; + + CreateSpawnedSceneUserData cssud = createSpawnedSceneUserData[sceneDescriptor.getIndex()]; + if (cssud) { + spawnedScene->userData = (*cssud)(*spawnedScene); + } + return spawnedScene; +} + +lumin::Node* PrismSceneManager::spawn(const SceneDescriptor & sceneDescriptor) { + SpawnedSceneBase* spawnedSceneBase = spawnScene(sceneDescriptor); + if (!spawnedSceneBase) { + return nullptr; + } + lumin::Node* root = spawnedSceneBase->root; + return root; +} + +lumin::Node* PrismSceneManager::createNodeTree(const SceneDescriptor & sceneDescriptor) { + setSceneState(sceneDescriptor, SceneState::ResourceAndObjectModelLoaded); + const int sceneIndex = sceneDescriptor.getIndex(); + std::string& objectModelName = objectModelNames_[sceneIndex]; + + lumin::Node* root = prism_->createAll(objectModelName); + if (!root) { + ML_LOG(Error, "PrismSceneManager failed to create the scene. Is the scene empty?"); + return nullptr; + } + + return root; +} + +void PrismSceneManager::setUserDataCreator(const SceneDescriptor & sceneDescriptor, CreateSpawnedSceneUserData cssud) { + createSpawnedSceneUserData[sceneDescriptor.getIndex()] = cssud ; +} + diff --git a/demo/magicleap/lre/code/src/gen/SceneDescriptor.cpp b/demo/magicleap/lre/code/src/gen/SceneDescriptor.cpp new file mode 100644 index 00000000..92673e33 --- /dev/null +++ b/demo/magicleap/lre/code/src/gen/SceneDescriptor.cpp @@ -0,0 +1,66 @@ +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- +// +// THE CONTENTS OF THIS FILE IS GENERATED BY CODE AND +// ANY MODIFICATIONS WILL BE OVERWRITTEN +// +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- + +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#include + +SceneDescriptor::SceneDescriptor(int index, const char * externalName, const char * id, const char * sceneGraphPath, const char * resourceModelPath, const ExternalNodeReferences& externalNodeReferences, bool initiallySpawned) +: + index_(index), + externalName_(externalName), + id_(id), + sceneGraphPath_(sceneGraphPath), + resourceModelPath_(resourceModelPath), + externalNodeReferences_(externalNodeReferences), + initiallySpawned_(initiallySpawned) { +} + +int SceneDescriptor::getIndex() const { + return index_; +} + +const std::string & SceneDescriptor::getExternalName() const { + return externalName_; +} + +const std::string & SceneDescriptor::getId() const { + return id_; +} + +const std::string & SceneDescriptor::getSceneGraphPath() const { + return sceneGraphPath_; +} + +const std::string & SceneDescriptor::getResourceModelPath() const { + return resourceModelPath_; +} + +const SceneDescriptor::ExternalNodeReferences & SceneDescriptor::getExternalNodeReferences() const { + return externalNodeReferences_; +} + +bool SceneDescriptor::getInitiallySpawned() const { + return initiallySpawned_; +} + +bool operator<(const SceneDescriptor& a, const SceneDescriptor& b) { + return a.getExternalName() < b.getExternalName(); +} + diff --git a/demo/magicleap/lre/code/src/gen/SpawnedSceneBase.cpp b/demo/magicleap/lre/code/src/gen/SpawnedSceneBase.cpp new file mode 100644 index 00000000..51cc3aa7 --- /dev/null +++ b/demo/magicleap/lre/code/src/gen/SpawnedSceneBase.cpp @@ -0,0 +1,35 @@ +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- +// +// THE CONTENTS OF THIS FILE IS GENERATED BY CODE AND +// ANY MODIFICATIONS WILL BE OVERWRITTEN +// +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- + +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#include +#include +#include + +SpawnedSceneBase::SpawnedSceneBase(const SceneDescriptor &sd, lumin::Node* rt) +: sceneDescriptor(sd), + root(rt) { +} + +SpawnedSceneBase::~SpawnedSceneBase() { + delete handlers; + delete userData; +} + diff --git a/demo/magicleap/lre/code/src/gen/SpawnedSceneHandlers.cpp b/demo/magicleap/lre/code/src/gen/SpawnedSceneHandlers.cpp new file mode 100644 index 00000000..6aa30422 --- /dev/null +++ b/demo/magicleap/lre/code/src/gen/SpawnedSceneHandlers.cpp @@ -0,0 +1,29 @@ +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- +// +// THE CONTENTS OF THIS FILE IS GENERATED BY CODE AND +// ANY MODIFICATIONS WILL BE OVERWRITTEN +// +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- + +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#include + +SpawnedSceneHandlers::SpawnedSceneHandlers(SpawnedSceneBase& ssb) { +} + +SpawnedSceneHandlers::~SpawnedSceneHandlers() { +} + diff --git a/demo/magicleap/lre/code/src/gen/SpawnedSceneUserData.cpp b/demo/magicleap/lre/code/src/gen/SpawnedSceneUserData.cpp new file mode 100644 index 00000000..777f0ed6 --- /dev/null +++ b/demo/magicleap/lre/code/src/gen/SpawnedSceneUserData.cpp @@ -0,0 +1,26 @@ +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- +// +// THE CONTENTS OF THIS FILE IS GENERATED BY CODE AND +// ANY MODIFICATIONS WILL BE OVERWRITTEN +// +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- + +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#include + +SpawnedSceneUserData::~SpawnedSceneUserData() { +} + diff --git a/demo/magicleap/lre/code/src/gen/scenes.cpp b/demo/magicleap/lre/code/src/gen/scenes.cpp new file mode 100644 index 00000000..d62a26ba --- /dev/null +++ b/demo/magicleap/lre/code/src/gen/scenes.cpp @@ -0,0 +1,64 @@ +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- +// +// THE CONTENTS OF THIS FILE IS GENERATED BY CODE AND +// ANY MODIFICATIONS WILL BE OVERWRITTEN +// +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- + +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#include +#include +#include + +namespace scenes { + + namespace PathfinderDemo { + + namespace externalNodes { + } + + const SceneDescriptor::ExternalNodeReferences externalNodesMap = { + }; + + const SceneDescriptor descriptor( + 0, + "PathfinderDemo", + "root", + "/assets/scenes/PathfinderDemo.scene.xml", + "/assets/scenes/PathfinderDemo.scene.res.xml", + externalNodesMap, + true); + } + + const SceneDescriptorReferences externalScenes = { + {PathfinderDemo::descriptor.getExternalName(), PathfinderDemo::descriptor} + }; + + struct VerifyNumberOfExternalScenes { + VerifyNumberOfExternalScenes() { assert(externalScenes.size() == numberOfExternalScenes); } + }; + + VerifyNumberOfExternalScenes verifyNumberOfExternalScenes; +} + +const PrismSceneManager::CreateSpawnedScene PrismSceneManager::createSpawnedScene[scenes::numberOfExternalScenes] = { + ::scenes::PathfinderDemo::createSpawnedScene +}; + +const PrismSceneManager::CreateSpawnedSceneHandlers PrismSceneManager::createSpawnedSceneHandlers[scenes::numberOfExternalScenes] = { + static_cast(::scenes::PathfinderDemo::createSpawnedSceneHandlers) +}; + diff --git a/demo/magicleap/lre/code/src/main.cpp b/demo/magicleap/lre/code/src/main.cpp new file mode 100644 index 00000000..451406a9 --- /dev/null +++ b/demo/magicleap/lre/code/src/main.cpp @@ -0,0 +1,25 @@ +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + + +#include +#include + +int main(int argc, char **argv) +{ + ML_LOG(Debug, "PathfinderDemo Starting."); + PathfinderDemo myApp; + return myApp.run(); +} + diff --git a/demo/magicleap/lre/code/srcs.comp b/demo/magicleap/lre/code/srcs.comp new file mode 100644 index 00000000..36719ea4 --- /dev/null +++ b/demo/magicleap/lre/code/srcs.comp @@ -0,0 +1,8 @@ +SRCS = \ + src/gen/scenes.cpp \ + src/gen/PathfinderDemo/PathfinderDemo.cpp \ + src/gen/PrismSceneManager.cpp \ + src/gen/SceneDescriptor.cpp \ + src/gen/SpawnedSceneBase.cpp \ + src/gen/SpawnedSceneHandlers.cpp \ + src/gen/SpawnedSceneUserData.cpp \ diff --git a/demo/magicleap/lre/manifest.xml b/demo/magicleap/lre/manifest.xml new file mode 100644 index 00000000..587be289 --- /dev/null +++ b/demo/magicleap/lre/manifest.xml @@ -0,0 +1,19 @@ + + + + + + + diff --git a/demo/magicleap/lre/pipeline/cache/AssetManifest.comp b/demo/magicleap/lre/pipeline/cache/AssetManifest.comp new file mode 100644 index 00000000..e69de29b diff --git a/demo/magicleap/lre/pipeline/lap/project.json b/demo/magicleap/lre/pipeline/lap/project.json new file mode 100644 index 00000000..599272b6 --- /dev/null +++ b/demo/magicleap/lre/pipeline/lap/project.json @@ -0,0 +1,47 @@ +{ + "intermediate-storage": { + "path": "cache", + "kind": "in-tree" + }, + "project-schema-version": 4, + "types": { + "assets": [ + "lap/types/asset/audio", + "lap/types/asset/material", + "lap/types/asset/model", + "lap/types/asset/outline-font", + "lap/types/asset/texture" + ], + "files": [ + "lap/types/file/bmp", + "lap/types/file/dds", + "lap/types/file/fbx", + "lap/types/file/files", + "lap/types/file/gltf", + "lap/types/file/jpg", + "lap/types/file/kmat", + "lap/types/file/ogg", + "lap/types/file/otf", + "lap/types/file/png", + "lap/types/file/tga", + "lap/types/file/tiff", + "lap/types/file/wav" + ] + }, + "checkpoint-hash": "0a229200eb36f445371d5eef7cd9afaf76b99c1d2278fbca0497449dfcfd890710c7535ff703844a86fabeb5c268c4f234715814458f635ac70bf3d378499654", + "templates": [ + "lap/template/converted_texture_from_bmp", + "lap/template/converted_texture_from_tga", + "lap/template/converted_texture_from_tiff", + "lap/template/passthru_audio_from_ogg", + "lap/template/passthru_audio_from_wav", + "lap/template/passthru_material_from_kmat", + "lap/template/passthru_model_from_fbx", + "lap/template/passthru_model_from_gltf", + "lap/template/passthru_outline_font_from_otf", + "lap/template/passthru_texture_from_dds", + "lap/template/passthru_texture_from_jpg", + "lap/template/passthru_texture_from_png" + ], + "nodes": {} +} \ No newline at end of file diff --git a/demo/magicleap/lre/scenes.comp b/demo/magicleap/lre/scenes.comp new file mode 100644 index 00000000..ebc999ca --- /dev/null +++ b/demo/magicleap/lre/scenes.comp @@ -0,0 +1,3 @@ +DATAS = \ + scenes/PathfinderDemo.scene.res.xml : assets/scenes/PathfinderDemo.scene.res.xml \ + scenes/PathfinderDemo.scene.xml : assets/scenes/PathfinderDemo.scene.xml diff --git a/demo/magicleap/lre/scenes/PathfinderDemo.design b/demo/magicleap/lre/scenes/PathfinderDemo.design new file mode 100644 index 00000000..4df9e299 --- /dev/null +++ b/demo/magicleap/lre/scenes/PathfinderDemo.design @@ -0,0 +1,183 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/demo/magicleap/lre/scenes/PathfinderDemo.scene.res.xml b/demo/magicleap/lre/scenes/PathfinderDemo.scene.res.xml new file mode 100644 index 00000000..ef5f53f7 --- /dev/null +++ b/demo/magicleap/lre/scenes/PathfinderDemo.scene.res.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/demo/magicleap/lre/scenes/PathfinderDemo.scene.xml b/demo/magicleap/lre/scenes/PathfinderDemo.scene.xml new file mode 100644 index 00000000..10695e5d --- /dev/null +++ b/demo/magicleap/lre/scenes/PathfinderDemo.scene.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/demo/magicleap/manifest.xml b/demo/magicleap/manifest.xml index 3377bed5..80240ff1 100644 --- a/demo/magicleap/manifest.xml +++ b/demo/magicleap/manifest.xml @@ -9,10 +9,20 @@ ml:min_api_level="3"> + + + + diff --git a/demo/magicleap/src/landscape.cpp b/demo/magicleap/src/landscape.cpp new file mode 100644 index 00000000..7b0d52d8 --- /dev/null +++ b/demo/magicleap/src/landscape.cpp @@ -0,0 +1,165 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + ML_LOG(Debug, "PathfinderDemo Starting."); + PathfinderDemo myApp; + return myApp.run(); +} + +const char* QUAD_NAMES[1] = { + "quad1" +}; + +const char* PANEL_NAMES[1] = { + "uiPanel1" +}; + +PathfinderDemo::PathfinderDemo() { + ML_LOG(Debug, "PathfinderDemo Constructor."); + + // Place your constructor implementation here. + svg_filecount_ = magicleap_pathfinder_svg_filecount(); + svg_filenames_ = magicleap_pathfinder_svg_filenames(); +} + +PathfinderDemo::~PathfinderDemo() { + ML_LOG(Debug, "PathfinderDemo Destructor."); + + // Place your destructor implementation here. +} + +const glm::vec3 PathfinderDemo::getInitialPrismSize() const { + return glm::vec3(0.4f, 0.4f, 0.4f); +} + +void PathfinderDemo::createInitialPrism() { + prism_ = requestNewPrism(getInitialPrismSize()); + if (!prism_) { + ML_LOG(Error, "PathfinderDemo Error creating default prism."); + abort(); + } + prismSceneManager_ = new PrismSceneManager(prism_); +} + +int PathfinderDemo::init() { + + ML_LOG(Debug, "PathfinderDemo Initializing."); + + createInitialPrism(); + lumin::ui::Cursor::SetEnabled(prism_, false); + spawnInitialScenes(); + + // Place your initialization here. + if (checkPrivilege(lumin::PrivilegeId::kControllerPose) != lumin::PrivilegeResult::kGranted) { + ML_LOG(Error, "Pathfinder Failed to get controller access"); + abort(); + return 1; + } + + + // Get the root node of the prism + lumin::RootNode* root_node = prism_->getRootNode(); + if (!root_node) { + ML_LOG(Error, "Pathfinder Failed to get root node"); + abort(); + return 1; + } + + // Get the quad + lumin::QuadNode* quad_node = lumin::QuadNode::CastFrom(prism_->findNode(QUAD_NAMES[0], root_node)); + if (!quad_node) { + ML_LOG(Error, "Pathfinder Failed to get quad node"); + abort(); + return 1; + } + + // Create the EGL surface for it to draw to + lumin::ResourceIDType plane_id = prism_->createPlanarEGLResourceId(); + if (!plane_id) { + ML_LOG(Error, "Pathfinder Failed to create EGL resource"); + abort(); + return 1; + } + lumin::PlanarResource* plane = static_cast(prism_->getResource(plane_id)); + if (!plane) { + ML_LOG(Error, "Pathfinder Failed to get plane"); + abort(); + return 1; + } + quad_node->setRenderResource(plane_id); + + return 0; +} + +int PathfinderDemo::deInit() { + ML_LOG(Debug, "PathfinderDemo Deinitializing."); + + // Place your deinitialization here. + + return 0; +} + +void PathfinderDemo::spawnInitialScenes() { + + // Iterate over all the exported scenes + for (auto& exportedSceneEntry : scenes::externalScenes ) { + + // If this scene was marked to be instanced at app initialization, do it + const SceneDescriptor &sd = exportedSceneEntry.second; + if (sd.getInitiallySpawned()) { + lumin::Node* const spawnedRoot = prismSceneManager_->spawn(sd); + if (spawnedRoot) { + if (!prism_->getRootNode()->addChild(spawnedRoot)) { + ML_LOG(Error, "PathfinderDemo Failed to add spawnedRoot to the prism root node"); + abort(); + } + } + } + } +} + +bool PathfinderDemo::updateLoop(float fDelta) { + + // Place your update here. + + // Return true for your app to continue running, false to terminate the app. + return true; +} + +bool PathfinderDemo::eventListener(lumin::ServerEvent* event) { + // Place your event handling here. + lumin::ServerEventType typ = event->getServerEventType(); + switch (typ) { + case lumin::ServerEventType::kControlPose6DofInputEvent: + requestWorldRayCast(getHeadposeWorldPosition(), getHeadposeWorldForwardVector(), 0); + return false; + case lumin::ServerEventType::kRayCastEvent: { + lumin::RayCastEventData* raycast_event = static_cast(event); + std::shared_ptr raycast_result = raycast_event->getHitData(); + switch (raycast_result->getType()) { + case lumin::RaycastResultType::kQuadNode: { + std::shared_ptr quad_result = std::static_pointer_cast(raycast_result); + focus_node = quad_result->getNodeId(); + return false; + } + default: + focus_node = lumin::INVALID_NODE_ID; + return false; + } + } + default: + return false; + } +} + diff --git a/demo/magicleap/src/landscape.h b/demo/magicleap/src/landscape.h new file mode 100644 index 00000000..a4191e32 --- /dev/null +++ b/demo/magicleap/src/landscape.h @@ -0,0 +1,109 @@ +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#include +#include +#include +#include +#include + +/** + * PathfinderDemo Landscape Application + */ +class PathfinderDemo : public lumin::LandscapeApp { +public: + /** + * Constructs the Landscape Application. + */ + PathfinderDemo(); + + /** + * Destroys the Landscape Application. + */ + virtual ~PathfinderDemo(); + + /** + * Disallows the copy constructor. + */ + PathfinderDemo(const PathfinderDemo&) = delete; + + /** + * Disallows the move constructor. + */ + PathfinderDemo(PathfinderDemo&&) = delete; + + /** + * Disallows the copy assignment operator. + */ + PathfinderDemo& operator=(const PathfinderDemo&) = delete; + + /** + * Disallows the move assignment operator. + */ + PathfinderDemo& operator=(PathfinderDemo&&) = delete; + +protected: + /** + * Initializes the Landscape Application. + * @return - 0 on success, error code on failure. + */ + int init() override; + + /** + * Deinitializes the Landscape Application. + * @return - 0 on success, error code on failure. + */ + int deInit() override; + + /** + * Returns the initial size of the Prism + * Used in createPrism(). + */ + const glm::vec3 getInitialPrismSize() const; + + /** + * Creates the prism, updates the private variable prism_ with the created prism. + */ + void createInitialPrism(); + + /** + * Initializes and creates the scene of all scenes marked as initially instanced + */ + void spawnInitialScenes(); + + /** + * Respond to a cube face being activated + */ + void onActivate(int face); + + /** + * Run application login + */ + virtual bool updateLoop(float fDelta) override; + + /** + * Handle events from the server + */ + virtual bool eventListener(lumin::ServerEvent* event) override; + +private: + lumin::Prism* prism_ = nullptr; // represents the bounded space where the App renders. + PrismSceneManager* prismSceneManager_ = nullptr; + uint64_t svg_filecount_ = 0; + char** svg_filenames_ = nullptr; + lumin::NodeIDType focus_node = lumin::INVALID_NODE_ID; +}; + +extern "C" uint64_t magicleap_pathfinder_svg_filecount(); +extern "C" char** magicleap_pathfinder_svg_filenames(); diff --git a/demo/magicleap/src/lib.rs b/demo/magicleap/src/lib.rs index 08513f16..ba49e8ef 100644 --- a/demo/magicleap/src/lib.rs +++ b/demo/magicleap/src/lib.rs @@ -13,6 +13,7 @@ use pathfinder_demo::Options; use pathfinder_demo::window::Mode; use std::ffi::CString; +use std::os::raw::c_char; mod c_api; mod magicleap; @@ -56,4 +57,22 @@ pub extern "C" fn magicleap_pathfinder_demo(egl_display: EGLDisplay, egl_context } app.finish_drawing_frame(); } +} + +const SVG_FILENAMES: &[*const c_char] = &[ + &b"svg/Ghostscript_Tiger.svg\0"[0], + &b"svg/paper.svg\0"[0], + &b"svg/julius-caesar-with-bg.svg\0"[0], + &b"svg/nba-notext.svg\0"[0], + &b"svg/pathfinder_logo.svg\0"[0], +]; + +#[no_mangle] +pub extern "C" fn magicleap_pathfinder_svg_filecount() -> usize { + SVG_FILENAMES.len() +} + +#[no_mangle] +pub extern "C" fn magicleap_pathfinder_svg_filenames() -> *const *const c_char { + &SVG_FILENAMES[0] } \ No newline at end of file