├── .github ├── ISSUE_TEMPLATE │ ├── 1_feature_request.yml │ ├── 2_bug_report.yml │ └── config.yml └── workflows │ └── stale_issues.yml ├── .gitignore ├── LICENSE ├── README.md └── Stereolabs ├── Content ├── EnvironmentalLighting │ └── Blueprints │ │ ├── BP_EnvLight_EnvironmentalLightingManager.uasset │ │ └── BP_EnvironmentalLighting_Manager.uasset ├── SpatialMapping │ ├── Blueprints │ │ ├── BP_SpatialMapping_CubemapMananger.uasset │ │ ├── BP_SpatialMapping_Manager.uasset │ │ └── BP_SpatialMapping_Mesh.uasset │ ├── Materials │ │ ├── M_SpatialMapping_PreviewMesh.uasset │ │ ├── M_SpatialMapping_RenderMesh.uasset │ │ └── M_SpatialMapping_RenderMeshCubemap.uasset │ └── Textures │ │ └── RT_SpatialMapping_Cubemap.uasset ├── Stereolabs │ ├── Fonts │ │ ├── FF_coolvetica_rg.uasset │ │ ├── F_Offline_Roboto-Medium_Font.uasset │ │ ├── F_Offline_coolvetica_rg.uasset │ │ ├── F_Runtime_Roboto-Medium.uasset │ │ ├── F_Runtime_coolbetica_rg.uasset │ │ ├── Roboto-Medium.uasset │ │ └── coolvetica rg.ttf │ └── Materials │ │ ├── MF_Sl_DepthOffset.uasset │ │ ├── MF_Sl_InverseTonemaping.uasset │ │ ├── M_SL_RPP.uasset │ │ └── T_SL_Dummy32bit.uasset └── ZED │ ├── Blueprints │ ├── BP_ZED_Initialize.uasset │ ├── BP_ZED_Initializer.uasset │ ├── GameMode │ │ └── BP_ZED_GameMode.uasset │ └── HUD │ │ ├── BP_ZED_Loading.uasset │ │ ├── Error │ │ ├── BP_ZED_Error.uasset │ │ ├── BP_ZED_Loading.uasset │ │ ├── W_ZED_Error.uasset │ │ └── W_ZED_SearchingForCamera.uasset │ │ ├── Loading │ │ ├── BP_ZED_Loading.uasset │ │ ├── W_ZED_Background.uasset │ │ └── W_ZED_Loading.uasset │ │ └── W_ZED_Background.uasset │ ├── Materials │ ├── M_ZED_3DWidgetPassthroughNoDepth.uasset │ ├── M_ZED_Fade.uasset │ ├── M_ZED_GetEyeIndex.uasset │ ├── M_ZED_Mask.uasset │ ├── M_ZED_PostProcess.uasset │ ├── Mono │ │ └── M_ZED_Mono.uasset │ └── Stereo │ │ ├── M_ZED_HMDLeftEye.uasset │ │ ├── M_ZED_HMDRightEye.uasset │ │ ├── M_ZED_LeftEye.uasset │ │ └── M_ZED_RightEye.uasset │ ├── Shapes │ └── SM_Plane_100x100.uasset │ ├── Textures │ ├── RT_ZED_Dummy.uasset │ ├── RT_ZED_DummyGrayscale.uasset │ ├── Stereo_AA.png │ ├── T_ZED_Cubemap.uasset │ ├── T_ZED_Stereo_AA.uasset │ ├── T_ZED_Warning.uasset │ └── Warning.png │ └── Utility │ └── C_Fade.uasset ├── Resources └── Icon128.png ├── Source ├── Devices │ ├── Devices.Build.cs │ ├── Private │ │ ├── Core │ │ │ └── DevicesMotionController.cpp │ │ ├── Devices.cpp │ │ └── DevicesPrivatePCH.h │ └── Public │ │ ├── Core │ │ └── DevicesMotionController.h │ │ └── Devices.h ├── EnvironmentalLighting │ ├── EnvironmentalLighting.Build.cs │ ├── Private │ │ ├── Core │ │ │ └── EnvironmentalLightingManager.cpp │ │ ├── EnvironmentalLighting.cpp │ │ └── EnvironmentalLightingPrivatePCH.h │ └── Public │ │ ├── Core │ │ └── EnvironmentalLightingManager.h │ │ └── EnvironmentalLighting.h ├── SpatialMapping │ ├── Private │ │ ├── Core │ │ │ ├── SpatialMappingCubemapManager.cpp │ │ │ └── SpatialMappingManager.cpp │ │ ├── SpatialMapping.cpp │ │ ├── SpatialMappingPrivatePCH.h │ │ └── Threading │ │ │ ├── SpatialMappingCubemapRunnable.cpp │ │ │ ├── SpatialMappingCubemapRunnable.h │ │ │ ├── SpatialMappingRunnable.cpp │ │ │ └── SpatialMappingRunnable.h │ ├── Public │ │ ├── Core │ │ │ ├── SpatialMappingBaseTypes.h │ │ │ ├── SpatialMappingCubemapManager.h │ │ │ └── SpatialMappingManager.h │ │ └── SpatialMapping.h │ └── SpatialMapping.Build.cs ├── SpatialMappingEditor │ ├── Private │ │ ├── SpatialMappingEditorPlugin.cpp │ │ ├── SpatialMappingEditorPrivatePCH.h │ │ └── SpatialMappingManagerDetails.cpp │ ├── Public │ │ ├── SpatialMappingEditorPlugin.h │ │ └── SpatialMappingManagerDetails.h │ └── SpatialMappingEditor.Build.cs ├── Stereolabs │ ├── Private │ │ ├── Core │ │ │ ├── StereolabsBaseTypes.cpp │ │ │ ├── StereolabsCameraProxy.cpp │ │ │ ├── StereolabsCoreGlobals.cpp │ │ │ ├── StereolabsMesh.cpp │ │ │ ├── StereolabsTexture.cpp │ │ │ └── StereolabsTextureBatch.cpp │ │ ├── Stereolabs.cpp │ │ ├── StereolabsPrivatePCH.h │ │ ├── Threading │ │ │ ├── StereolabsGrabRunnable.cpp │ │ │ ├── StereolabsGrabRunnable.h │ │ │ ├── StereolabsMeasureRunnable.cpp │ │ │ ├── StereolabsMeasureRunnable.h │ │ │ └── StereolabsRunnable.cpp │ │ └── Utilities │ │ │ ├── StereolabsFunctionLibrary.cpp │ │ │ └── StereolabsViewportHelper.cpp │ ├── Public │ │ ├── Core │ │ │ ├── StereolabsBaseTypes.h │ │ │ ├── StereolabsCameraProxy.h │ │ │ ├── StereolabsCoreGlobals.h │ │ │ ├── StereolabsCoreUtilities.h │ │ │ ├── StereolabsMesh.h │ │ │ ├── StereolabsTexture.h │ │ │ └── StereolabsTextureBatch.h │ │ ├── Stereolabs.h │ │ ├── Threading │ │ │ └── StereolabsRunnable.h │ │ └── Utilities │ │ │ ├── StereolabsCriticalSection.h │ │ │ ├── StereolabsFunctionLibrary.h │ │ │ ├── StereolabsMatFunctionLibrary.h │ │ │ ├── StereolabsTimer.h │ │ │ └── StereolabsViewportHelper.h │ └── Stereolabs.Build.cs ├── ThirdParty │ └── MixedReality │ │ ├── MixedReality.build.cs │ │ ├── bin │ │ └── sl_mr_core64.dll │ │ ├── include │ │ └── sl_mr_core │ │ │ ├── AntiDrift.hpp │ │ │ ├── EnvironmentalLighting.hpp │ │ │ ├── Rendering.hpp │ │ │ ├── defines.hpp │ │ │ └── latency.hpp │ │ └── lib │ │ └── sl_mr_core64.lib ├── ZED │ ├── Classes │ │ ├── ZEDGameInstance.h │ │ ├── ZEDGameViewportClient.h │ │ └── ZEDLocalPlayer.h │ ├── Defaults │ │ ├── Camera.ini │ │ ├── DefaultEngine.ini │ │ └── ZED.ini │ ├── Private │ │ ├── Core │ │ │ ├── ZEDBaseTypes.cpp │ │ │ ├── ZEDCamera.cpp │ │ │ ├── ZEDCoreGlobals.cpp │ │ │ ├── ZEDInitializer.cpp │ │ │ ├── ZEDPawn.cpp │ │ │ └── ZEDPlayerController.cpp │ │ ├── Engine │ │ │ ├── ZEDGameInstance.cpp │ │ │ ├── ZEDGameViewportClient.cpp │ │ │ └── ZEDLocalPlayer.cpp │ │ ├── HUD │ │ │ ├── ZEDWidget.cpp │ │ │ └── ZEDWidgetComponent.cpp │ │ ├── Utilities │ │ │ └── ZEDFunctionLibrary.cpp │ │ ├── ZED.cpp │ │ └── ZEDPrivatePCH.h │ ├── Public │ │ ├── Core │ │ │ ├── ZEDBaseTypes.h │ │ │ ├── ZEDCamera.h │ │ │ ├── ZEDCoreGlobals.h │ │ │ ├── ZEDInitializer.h │ │ │ ├── ZEDPawn.h │ │ │ └── ZEDPlayerController.h │ │ ├── HUD │ │ │ ├── ZEDWidget.h │ │ │ └── ZEDWidgetComponent.h │ │ ├── Utilities │ │ │ └── ZEDFunctionLibrary.h │ │ └── ZED.h │ └── ZED.Build.cs └── ZEDEditor │ ├── Private │ ├── ZEDCameraDetails.cpp │ ├── ZEDEditorPlugin.cpp │ ├── ZEDEditorPrivatePCH.h │ └── ZEDInitializerDetails.cpp │ ├── Public │ ├── ZEDCameraDetails.h │ ├── ZEDEditorPlugin.h │ └── ZEDInitializerDetails.h │ └── ZEDEditor.Build.cs └── Stereolabs.uplugin /.github/ISSUE_TEMPLATE/1_feature_request.yml: -------------------------------------------------------------------------------- 1 | name: Feature request 🧭 2 | description: Suggest an idea for this project. 3 | labels: "feature request" 4 | body: 5 | - type: markdown 6 | attributes: 7 | value: | 8 | # Welcome 👋 9 | 10 | Thanks for taking the time to fill out this feature request module. 11 | Please fill out each section below. This info allows Stereolabs developers to correctly evaluate your request. 12 | 13 | Useful Links: 14 | - Documentation: https://www.stereolabs.com/docs/ 15 | - Stereolabs support: https://support.stereolabs.com/hc/en-us/ 16 | - type: checkboxes 17 | attributes: 18 | label: Preliminary Checks 19 | description: Please make sure that you verify each checkbox and follow the instructions for them. 20 | options: 21 | - label: "This issue is not a duplicate. Before opening a new issue, please search existing issues." 22 | required: true 23 | - label: "This issue is not a question, bug report, or anything other than a feature request directly related to this project." 24 | required: true 25 | - type: textarea 26 | attributes: 27 | label: Proposal 28 | description: "What would you like to have as a new feature?" 29 | placeholder: "A clear and concise description of what you want to happen." 30 | validations: 31 | required: true 32 | - type: textarea 33 | attributes: 34 | label: Use-Case 35 | description: "How would this help you?" 36 | placeholder: "Tell us more what you'd like to achieve." 37 | validations: 38 | required: false 39 | - type: textarea 40 | id: anything-else 41 | attributes: 42 | label: Anything else? 43 | description: "Let us know if you have anything else to share" 44 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/2_bug_report.yml: -------------------------------------------------------------------------------- 1 | name: Bug Report 🐛 2 | description: Something isn't working as expected? Report your bugs here. 3 | labels: "bug" 4 | body: 5 | - type: markdown 6 | attributes: 7 | value: | 8 | # Welcome 👋 9 | 10 | Thanks for taking the time to fill out this bug report. 11 | Please fill out each section below. This info allows Stereolabs developers to diagnose (and fix!) your issue as quickly as possible. Otherwise we might need to close the issue without e.g. clear reproduction steps. 12 | 13 | Bug reports also shoulnd't be used for generic questions, please use the [Stereolabs Community forum](https://community.stereolabs.com/) instead. 14 | 15 | Useful Links: 16 | - Documentation: https://www.stereolabs.com/docs/ 17 | - Stereolabs support: https://support.stereolabs.com/hc/en-us/ 18 | - type: checkboxes 19 | attributes: 20 | label: Preliminary Checks 21 | description: Please make sure that you verify each checkbox and follow the instructions for them. 22 | options: 23 | - label: "This issue is not a duplicate. Before opening a new issue, please search existing issues." 24 | required: true 25 | - label: "This issue is not a question, feature request, or anything other than a bug report directly related to this project." 26 | required: true 27 | - type: textarea 28 | attributes: 29 | label: Description 30 | description: Describe the issue that you're seeing. 31 | placeholder: Be as precise as you can. Feel free to share screenshots, videos, or data. The more information you provide the easier will be to provide you with a fast solution. 32 | validations: 33 | required: true 34 | - type: textarea 35 | attributes: 36 | label: Steps to Reproduce 37 | description: Clear steps describing how to reproduce the issue. 38 | value: | 39 | 1. 40 | 2. 41 | 3. 42 | ... 43 | validations: 44 | required: true 45 | - type: textarea 46 | attributes: 47 | label: Expected Result 48 | description: Describe what you expected to happen. 49 | validations: 50 | required: true 51 | - type: textarea 52 | attributes: 53 | label: Actual Result 54 | description: Describe what actually happened. 55 | validations: 56 | required: true 57 | - type: dropdown 58 | attributes: 59 | label: ZED Camera model 60 | description: What model of ZED camera are you using? 61 | options: 62 | - "ZED" 63 | - "ZED Mini" 64 | - "ZED2" 65 | - "ZED2i" 66 | validations: 67 | required: true 68 | - type: textarea 69 | attributes: 70 | label: Environment 71 | render: shell 72 | description: Useful information about your system. 73 | placeholder: | 74 | OS: Operating System 75 | CPU: e.g. ARM 76 | GPU: Nvidia Jetson Xavier NX 77 | ZED SDK version: e.g. v3.5.3 78 | Other info: e.g. ROS Melodic 79 | validations: 80 | required: true 81 | - type: textarea 82 | attributes: 83 | label: Anything else? 84 | description: Please add any other information or comment that you think may be useful for solving the problem 85 | placeholder: 86 | validations: 87 | required: false 88 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Online Documentation 4 | url: https://www.stereolabs.com/docs/ 5 | about: Check out the Stereolabs documentation for answers to common questions. 6 | - name: Stereolabs Community 7 | url: https://community.stereolabs.com/ 8 | about: Ask questions, request features & discuss with other users and developers. 9 | - name: Stereolabs Twitter 10 | url: https://twitter.com/Stereolabs3D 11 | about: The official Stereolabs Twitter account to ask questions, comment our products and share your projects with the ZED community. 12 | 13 | -------------------------------------------------------------------------------- /.github/workflows/stale_issues.yml: -------------------------------------------------------------------------------- 1 | name: 'Stale issue handler' 2 | on: 3 | workflow_dispatch: 4 | schedule: 5 | - cron: '00 00 * * *' 6 | 7 | jobs: 8 | stale: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/stale@main 12 | id: stale 13 | with: 14 | stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment otherwise it will be automatically closed in 5 days' 15 | stale-pr-message: 'This PR is stale because it has been open 30 days with no activity. Remove stale label or comment otherwise it will be automatically closed in 5 days' 16 | days-before-stale: 30 17 | days-before-close: 5 18 | operations-per-run: 1500 19 | exempt-issue-labels: 'feature_request' 20 | exempt-pr-labels: 'feature_request' 21 | enable-statistics: 'true' 22 | close-issue-label: 'closed_for_stale' 23 | close-pr-label: 'closed_for_stale' 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Stereolabs plugins 2 | Stereolabs/Binaries/* 3 | Stereolabs/Intermediate/* 4 | 5 | # Runtime mesh plugin 6 | RuntimeMeshComponent/Binaries/* 7 | RuntimeMeshComponent/Intermediate/* -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Stereolabs 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # **Please update to [our Unreal Engine 5 plugin](https://github.com/stereolabs/zed-UE5) to use the last features of the ZED SDK** 2 | 3 | As of the release of the [ZED SDK 4.0](https://www.stereolabs.com/developers/release/), this sample is deprecated and will not be maintained anymore. 4 | To use the most recent features and capabilities of the ZED SDK, we invite you to use our [Unreal Engine 5 plugin](https://github.com/stereolabs/zed-UE5). 5 | 6 | Thanks for your comprehension. 7 | 8 | -------------------------------------- 9 | 10 | 11 | # ZED Unreal Plugin 12 | 13 | This plugin gives you access to advanced Mixed Reality features to create immersive applications using the ZED. 14 | 15 | ## How to use 16 | 17 | A modified version of the Unreal Engine is required to use this plugin, you can get all the setup instruction in the dedicated __[documentation](https://docs.stereolabs.com/mixed-reality/unreal/getting-started/)__. 18 | 19 | *Note:* This branch is compatible with our custom distribution of Unreal Engine 4.21 ([download here](https://github.com/Stereolabs-Unreal/UnrealEngine/tree/4.21-zed)) with ZED SDK v3.0 installed. See other branches if using another Unreal or ZED SDK version. Plugins are not backwards-compatible. 20 | 21 | ## Support 22 | If you need assistance go to our Community site at https://community.stereolabs.com/ 23 | -------------------------------------------------------------------------------- /Stereolabs/Content/EnvironmentalLighting/Blueprints/BP_EnvLight_EnvironmentalLightingManager.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/EnvironmentalLighting/Blueprints/BP_EnvLight_EnvironmentalLightingManager.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/EnvironmentalLighting/Blueprints/BP_EnvironmentalLighting_Manager.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/EnvironmentalLighting/Blueprints/BP_EnvironmentalLighting_Manager.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/SpatialMapping/Blueprints/BP_SpatialMapping_CubemapMananger.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/SpatialMapping/Blueprints/BP_SpatialMapping_CubemapMananger.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/SpatialMapping/Blueprints/BP_SpatialMapping_Manager.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/SpatialMapping/Blueprints/BP_SpatialMapping_Manager.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/SpatialMapping/Blueprints/BP_SpatialMapping_Mesh.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/SpatialMapping/Blueprints/BP_SpatialMapping_Mesh.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/SpatialMapping/Materials/M_SpatialMapping_PreviewMesh.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/SpatialMapping/Materials/M_SpatialMapping_PreviewMesh.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/SpatialMapping/Materials/M_SpatialMapping_RenderMesh.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/SpatialMapping/Materials/M_SpatialMapping_RenderMesh.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/SpatialMapping/Materials/M_SpatialMapping_RenderMeshCubemap.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/SpatialMapping/Materials/M_SpatialMapping_RenderMeshCubemap.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/SpatialMapping/Textures/RT_SpatialMapping_Cubemap.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/SpatialMapping/Textures/RT_SpatialMapping_Cubemap.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/Stereolabs/Fonts/FF_coolvetica_rg.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/Stereolabs/Fonts/FF_coolvetica_rg.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/Stereolabs/Fonts/F_Offline_Roboto-Medium_Font.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/Stereolabs/Fonts/F_Offline_Roboto-Medium_Font.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/Stereolabs/Fonts/F_Offline_coolvetica_rg.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/Stereolabs/Fonts/F_Offline_coolvetica_rg.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/Stereolabs/Fonts/F_Runtime_Roboto-Medium.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/Stereolabs/Fonts/F_Runtime_Roboto-Medium.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/Stereolabs/Fonts/F_Runtime_coolbetica_rg.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/Stereolabs/Fonts/F_Runtime_coolbetica_rg.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/Stereolabs/Fonts/Roboto-Medium.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/Stereolabs/Fonts/Roboto-Medium.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/Stereolabs/Fonts/coolvetica rg.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/Stereolabs/Fonts/coolvetica rg.ttf -------------------------------------------------------------------------------- /Stereolabs/Content/Stereolabs/Materials/MF_Sl_DepthOffset.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/Stereolabs/Materials/MF_Sl_DepthOffset.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/Stereolabs/Materials/MF_Sl_InverseTonemaping.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/Stereolabs/Materials/MF_Sl_InverseTonemaping.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/Stereolabs/Materials/M_SL_RPP.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/Stereolabs/Materials/M_SL_RPP.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/Stereolabs/Materials/T_SL_Dummy32bit.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/Stereolabs/Materials/T_SL_Dummy32bit.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Blueprints/BP_ZED_Initialize.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Blueprints/BP_ZED_Initialize.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Blueprints/BP_ZED_Initializer.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Blueprints/BP_ZED_Initializer.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Blueprints/GameMode/BP_ZED_GameMode.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Blueprints/GameMode/BP_ZED_GameMode.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Blueprints/HUD/BP_ZED_Loading.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Blueprints/HUD/BP_ZED_Loading.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Blueprints/HUD/Error/BP_ZED_Error.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Blueprints/HUD/Error/BP_ZED_Error.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Blueprints/HUD/Error/BP_ZED_Loading.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Blueprints/HUD/Error/BP_ZED_Loading.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Blueprints/HUD/Error/W_ZED_Error.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Blueprints/HUD/Error/W_ZED_Error.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Blueprints/HUD/Error/W_ZED_SearchingForCamera.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Blueprints/HUD/Error/W_ZED_SearchingForCamera.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Blueprints/HUD/Loading/BP_ZED_Loading.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Blueprints/HUD/Loading/BP_ZED_Loading.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Blueprints/HUD/Loading/W_ZED_Background.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Blueprints/HUD/Loading/W_ZED_Background.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Blueprints/HUD/Loading/W_ZED_Loading.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Blueprints/HUD/Loading/W_ZED_Loading.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Blueprints/HUD/W_ZED_Background.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Blueprints/HUD/W_ZED_Background.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Materials/M_ZED_3DWidgetPassthroughNoDepth.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Materials/M_ZED_3DWidgetPassthroughNoDepth.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Materials/M_ZED_Fade.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Materials/M_ZED_Fade.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Materials/M_ZED_GetEyeIndex.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Materials/M_ZED_GetEyeIndex.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Materials/M_ZED_Mask.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Materials/M_ZED_Mask.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Materials/M_ZED_PostProcess.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Materials/M_ZED_PostProcess.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Materials/Mono/M_ZED_Mono.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Materials/Mono/M_ZED_Mono.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Materials/Stereo/M_ZED_HMDLeftEye.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Materials/Stereo/M_ZED_HMDLeftEye.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Materials/Stereo/M_ZED_HMDRightEye.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Materials/Stereo/M_ZED_HMDRightEye.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Materials/Stereo/M_ZED_LeftEye.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Materials/Stereo/M_ZED_LeftEye.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Materials/Stereo/M_ZED_RightEye.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Materials/Stereo/M_ZED_RightEye.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Shapes/SM_Plane_100x100.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Shapes/SM_Plane_100x100.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Textures/RT_ZED_Dummy.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Textures/RT_ZED_Dummy.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Textures/RT_ZED_DummyGrayscale.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Textures/RT_ZED_DummyGrayscale.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Textures/Stereo_AA.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Textures/Stereo_AA.png -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Textures/T_ZED_Cubemap.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Textures/T_ZED_Cubemap.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Textures/T_ZED_Stereo_AA.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Textures/T_ZED_Stereo_AA.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Textures/T_ZED_Warning.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Textures/T_ZED_Warning.uasset -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Textures/Warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Textures/Warning.png -------------------------------------------------------------------------------- /Stereolabs/Content/ZED/Utility/C_Fade.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Content/ZED/Utility/C_Fade.uasset -------------------------------------------------------------------------------- /Stereolabs/Resources/Icon128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Resources/Icon128.png -------------------------------------------------------------------------------- /Stereolabs/Source/Devices/Devices.Build.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | using UnrealBuildTool; 4 | using System.IO; 5 | using System; 6 | 7 | public class Devices : ModuleRules 8 | { 9 | private string ModulePath 10 | { 11 | get { return ModuleDirectory; } 12 | } 13 | 14 | public Devices(ReadOnlyTargetRules Target) : base(Target) 15 | { 16 | PrivatePCHHeaderFile = "Devices/Public/Devices.h"; 17 | 18 | PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "Public")); 19 | PrivateIncludePaths.Add(Path.Combine(ModuleDirectory, "Private")); 20 | 21 | PublicDependencyModuleNames.AddRange( 22 | new string[] 23 | { 24 | "ZED", 25 | "Stereolabs", 26 | "MixedReality" 27 | 28 | // ... add other public dependencies that you statically link with here ... 29 | } 30 | ); 31 | 32 | PrivateDependencyModuleNames.AddRange( 33 | new string[] 34 | { 35 | "Core", 36 | "CoreUObject", 37 | "RenderCore", 38 | "Engine", 39 | "HeadMountedDisplay" 40 | } 41 | ); 42 | } 43 | } 44 | 45 | 46 | -------------------------------------------------------------------------------- /Stereolabs/Source/Devices/Private/Core/DevicesMotionController.cpp: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #include "DevicesPrivatePCH.h" 4 | #include "Devices/Public/Core/DevicesMotionController.h" 5 | #include "Stereolabs/Public/Core/StereolabsBaseTypes.h" 6 | #include "ZED/Public/Utilities/ZEDFunctionLibrary.h" 7 | #include "HeadMountedDisplayFunctionLibrary.h" 8 | #include "ZED/Public/Core/ZEDInitializer.h" 9 | 10 | #include "IXRTrackingSystem.h" 11 | 12 | #include 13 | 14 | ADevicesMotionController::ADevicesMotionController() 15 | { 16 | LatencyTime = 25; 17 | if (GEngine != nullptr) 18 | { 19 | if (GEngine->XRSystem.IsValid()) 20 | { 21 | FName deviceType = GEngine->XRSystem->GetSystemName(); 22 | if (deviceType == TEXT("OculusHMD")) 23 | LatencyTime = 55; 24 | else if (deviceType == TEXT("SteamVR")) 25 | LatencyTime = 25; 26 | } 27 | } 28 | 29 | PrimaryActorTick.bCanEverTick = true; 30 | 31 | RootComponent = CreateDefaultSubobject("RootComponent"); 32 | 33 | MotionController = CreateDefaultSubobject("MotionController"); 34 | MotionController->bDisableLowLatencyUpdate = true; 35 | MotionController->SetCanEverAffectNavigation(false); 36 | MotionController->SetupAttachment(RootComponent); 37 | 38 | AddTickPrerequisiteComponent(MotionController); 39 | 40 | TransformBuffer.Reserve(LatencyTime); 41 | 42 | // Get Zed initializer object 43 | TArray ZedInitializer; 44 | UGameplayStatics::GetAllActorsOfClass(this, AZEDInitializer::StaticClass(), ZedInitializer); 45 | if (ZedInitializer.Num() >= 1) 46 | { 47 | AZEDInitializer* Initializer = static_cast(ZedInitializer[0]); 48 | if(Initializer->TrackingParameters.TrackingType != ETrackingType::TrT_ZED) 49 | bHmdTranslationUsed = true; 50 | } 51 | } 52 | 53 | void ADevicesMotionController::BeginPlay() 54 | { 55 | Super::BeginPlay(); 56 | 57 | GSlCameraProxy->OnCameraClosed.AddDynamic(this, &ADevicesMotionController::Stop); 58 | } 59 | 60 | void ADevicesMotionController::EndPlay(const EEndPlayReason::Type EndPlayReason) 61 | { 62 | Super::EndPlay(EndPlayReason); 63 | 64 | if (GSlCameraProxy) 65 | { 66 | GSlCameraProxy->OnCameraClosed.RemoveDynamic(this, &ADevicesMotionController::Stop); 67 | } 68 | } 69 | 70 | void ADevicesMotionController::Tick(float DeltaTime) 71 | { 72 | if (!isDeviceInitialized) 73 | { 74 | AZEDCamera* ZedCameraActor = UZEDFunctionLibrary::GetCameraActor(this); 75 | if (ZedCameraActor) 76 | { 77 | Start(); 78 | } 79 | } 80 | 81 | if (isDeviceInitialized) 82 | { 83 | FTransform Transform; 84 | if (GetTransform(Transform)) 85 | { 86 | SetActorTransform(Transform); 87 | } 88 | } 89 | 90 | Super::Tick(DeltaTime); 91 | } 92 | 93 | void ADevicesMotionController::Start() 94 | { 95 | if (!UHeadMountedDisplayFunctionLibrary::IsHeadMountedDisplayEnabled()) 96 | { 97 | return; 98 | } 99 | 100 | UZEDFunctionLibrary::GetCameraActor(this)->OnCameraActorInitialized.RemoveDynamic(this, &ADevicesMotionController::Start); 101 | 102 | UpdateTransformBuffer(); 103 | 104 | GetWorldTimerManager().SetTimer(TimerHandle, this, &ADevicesMotionController::UpdateTransformBuffer, 0.001f, true); 105 | 106 | isDeviceInitialized = true; 107 | } 108 | 109 | void ADevicesMotionController::Stop() 110 | { 111 | GetWorldTimerManager().ClearTimer(TimerHandle); 112 | isDeviceInitialized = false; 113 | } 114 | 115 | void ADevicesMotionController::ModifyLatencyTime(const int& NewLatencyInMs) 116 | { 117 | LatencyTime = NewLatencyInMs; 118 | TransformBuffer.Empty(); 119 | TransformBuffer.Reserve(LatencyTime); 120 | } 121 | 122 | int ADevicesMotionController::GetModifiedLatencyTime() 123 | { 124 | return LatencyTime; 125 | } 126 | 127 | FTransform ADevicesMotionController::GetDelayedTransform() 128 | { 129 | if (TransformBuffer.Num() > 0) 130 | { 131 | return TransformBuffer[0]; 132 | } 133 | else 134 | { 135 | return FTransform(); 136 | } 137 | } 138 | 139 | void ADevicesMotionController::UpdateTransformBuffer() 140 | { 141 | check(MotionController); 142 | 143 | if (TransformBuffer.Num() + 1 > LatencyTime) 144 | { 145 | TransformBuffer.RemoveAt(0, 1, false); 146 | } 147 | 148 | TransformBuffer.Add(MotionController->GetRelativeTransform()); 149 | } 150 | 151 | bool ADevicesMotionController::GetTransform(FTransform& Transform) 152 | { 153 | if (TransformBuffer.Num() < LatencyTime) 154 | { 155 | return false; 156 | } 157 | 158 | FZEDTrackingData TrackingData = UZEDFunctionLibrary::GetTrackingData(); 159 | FTransform DelayedTransform = GetDelayedTransform(); 160 | sl::Transform SlLatencyTransform; 161 | bool bTransform = sl::mr::latencyCorrectorGetTransform(GSlCameraProxy->GetCamera().getTimestamp(sl::TIME_REFERENCE::CURRENT) - sl::Timestamp(LatencyTime * 1000000), SlLatencyTransform, false); 162 | if (!bTransform) 163 | { 164 | return false; 165 | } 166 | 167 | if (bHmdTranslationUsed) 168 | { 169 | Transform = DelayedTransform; 170 | } 171 | else 172 | { 173 | Transform = (DelayedTransform * sl::unreal::ToUnrealType(SlLatencyTransform).Inverse()) * TrackingData.OffsetZedWorldTransform; 174 | } 175 | 176 | return true; 177 | } -------------------------------------------------------------------------------- /Stereolabs/Source/Devices/Private/Devices.cpp: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #include "DevicesPrivatePCH.h" 4 | 5 | #define LOCTEXT_NAMESPACE "FStereolabsDevices" 6 | 7 | void FStereolabsDevices::StartupModule() 8 | { 9 | // This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module 10 | } 11 | 12 | void FStereolabsDevices::ShutdownModule() 13 | { 14 | // This function may be called during shutdown to clean up your module. For modules that support dynamic reloading, 15 | // we call this function before unloading the module. 16 | } 17 | 18 | #undef LOCTEXT_NAMESPACE 19 | 20 | IMPLEMENT_MODULE(FStereolabsDevices, Devices) -------------------------------------------------------------------------------- /Stereolabs/Source/Devices/Private/DevicesPrivatePCH.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "Devices.h" 6 | 7 | #include "Engine.h" 8 | #include "GameFramework/Actor.h" -------------------------------------------------------------------------------- /Stereolabs/Source/Devices/Public/Core/DevicesMotionController.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "MotionControllerComponent.h" 6 | #include "DevicesMotionController.generated.h" 7 | 8 | /* 9 | * Actor which can provide a MotionController transform with a delay in millisecond. AActor is needed for timer. 10 | */ 11 | UCLASS(Category = "Stereolabs|Controllers") 12 | class DEVICES_API ADevicesMotionController : public AActor 13 | { 14 | GENERATED_BODY() 15 | 16 | public: 17 | ADevicesMotionController(); 18 | 19 | protected: 20 | virtual void BeginPlay() override; 21 | virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override; 22 | virtual void Tick(float DeltaTime) override; 23 | 24 | private: 25 | UFUNCTION() 26 | void Start(); 27 | 28 | UFUNCTION() 29 | void Stop(); 30 | 31 | public: 32 | 33 | UFUNCTION(BlueprintCallable, Category = "Zed") 34 | void ModifyLatencyTime(const int& NewLatencyInMs); 35 | 36 | UFUNCTION(BlueprintCallable, Category = "Zed") 37 | int GetModifiedLatencyTime(); 38 | 39 | 40 | 41 | private: 42 | /* 43 | * Get the motion controller transform delayed of "LatencyTime" milliseconds 44 | * @return The transform 45 | */ 46 | FTransform GetDelayedTransform(); 47 | 48 | /** Function called by the timer. It add a new motion controller transform to the buffer and remove the old one if we have enough */ 49 | void UpdateTransformBuffer(); 50 | 51 | /* 52 | * Get the transform of the motion controller relative to the ZED 53 | * @param Transform The out transform 54 | * @return True if the transform is valid 55 | */ 56 | bool GetTransform(FTransform& Transform); 57 | 58 | public: 59 | /** MotionController */ 60 | UPROPERTY(BlueprintReadOnly, EditAnywhere, Instanced) 61 | UMotionControllerComponent* MotionController; 62 | 63 | private: 64 | /** Latency time add to controller pose (in ms) */ 65 | int32 LatencyTime; 66 | 67 | /** Buffer containing previous controller transforms (one transform each frame) */ 68 | TArray> TransformBuffer; 69 | 70 | /** Update transform timer handle */ 71 | FTimerHandle TimerHandle; 72 | 73 | /** */ 74 | bool isDeviceInitialized = false; 75 | 76 | /** */ 77 | bool bHmdTranslationUsed = false; 78 | }; 79 | -------------------------------------------------------------------------------- /Stereolabs/Source/Devices/Public/Devices.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "ModuleManager.h" 6 | 7 | class FStereolabsDevices : public IModuleInterface 8 | { 9 | public: 10 | /** IModuleInterface implementation */ 11 | virtual void StartupModule() override; 12 | virtual void ShutdownModule() override; 13 | }; -------------------------------------------------------------------------------- /Stereolabs/Source/EnvironmentalLighting/EnvironmentalLighting.Build.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | using UnrealBuildTool; 4 | using System.IO; 5 | using System; 6 | 7 | public class EnvironmentalLighting : ModuleRules 8 | { 9 | private string ModulePath 10 | { 11 | get { return ModuleDirectory; } 12 | } 13 | 14 | public EnvironmentalLighting(ReadOnlyTargetRules Target) : base(Target) 15 | { 16 | PrivatePCHHeaderFile = "EnvironmentalLighting/Public/EnvironmentalLighting.h"; 17 | 18 | PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "Public")); 19 | PrivateIncludePaths.Add(Path.Combine(ModuleDirectory, "Private")); 20 | 21 | PublicDependencyModuleNames.AddRange( 22 | new string[] 23 | { 24 | "Stereolabs", 25 | "MixedReality" 26 | 27 | // ... add other public dependencies that you statically link with here ... 28 | } 29 | ); 30 | 31 | PrivateDependencyModuleNames.AddRange( 32 | new string[] 33 | { 34 | "Core", 35 | "CoreUObject", 36 | "RenderCore", 37 | "Engine" 38 | } 39 | ); 40 | } 41 | } 42 | 43 | 44 | -------------------------------------------------------------------------------- /Stereolabs/Source/EnvironmentalLighting/Private/Core/EnvironmentalLightingManager.cpp: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #include "EnvironmentalLightingPrivatePCH.h" 4 | #include "EnvironmentalLighting/Public/Core/EnvironmentalLightingManager.h" 5 | #include "Stereolabs/Public/Core/StereolabsCameraProxy.h" 6 | #include "Stereolabs/Public/Core/StereolabsCoreUtilities.h" 7 | 8 | #include 9 | 10 | /** Set environmental lighting max intensity */ 11 | static TAutoConsoleVariable CVarEnvLightMaxIntensity( 12 | TEXT("r.ZED.EnvLightMaxIntensity"), 13 | 1.0f, 14 | TEXT("Default to 1.0, range [0.005, 2.0]"), 15 | ECVF_SetByConsole 16 | ); 17 | 18 | AEnvironmentalLightingManager::AEnvironmentalLightingManager() 19 | : 20 | Batch(nullptr), 21 | LeftEyeTexture(nullptr), 22 | Light(nullptr) 23 | { 24 | PrimaryActorTick.bCanEverTick = true; 25 | } 26 | 27 | void AEnvironmentalLightingManager::BeginPlay() 28 | { 29 | Super::BeginPlay(); 30 | 31 | Batch = USlCPUTextureBatch::CreateCPUTextureBatch(FName("EnvironmentalLightingBatch")); 32 | 33 | sl::mr::environmentalLightingInitialize(); 34 | 35 | SetActorTickEnabled(false); 36 | 37 | GSlCameraProxy->OnCameraOpened.AddDynamic(this, &AEnvironmentalLightingManager::ToggleTick); 38 | GSlCameraProxy->OnCameraClosed.AddDynamic(this, &AEnvironmentalLightingManager::ToggleTick); 39 | } 40 | 41 | void AEnvironmentalLightingManager::EndPlay(const EEndPlayReason::Type EndPlayReason) 42 | { 43 | Super::EndPlay(EndPlayReason); 44 | 45 | FlushRenderingCommands(); 46 | 47 | if (GSlCameraProxy) 48 | { 49 | GSlCameraProxy->RemoveFromGrabDelegate(GrabDelegateHandle); 50 | 51 | GSlCameraProxy->OnCameraOpened.RemoveDynamic(this, &AEnvironmentalLightingManager::ToggleTick); 52 | GSlCameraProxy->OnCameraClosed.RemoveDynamic(this, &AEnvironmentalLightingManager::ToggleTick); 53 | } 54 | 55 | Batch->Clear(); 56 | 57 | sl::mr::environmentalLightingShutdown(); 58 | } 59 | 60 | void AEnvironmentalLightingManager::Tick(float DeltaSeconds) 61 | { 62 | Super::Tick(DeltaSeconds); 63 | 64 | UDirectionalLightComponent* LightComponent = Light ? static_cast(Light->GetLightComponent()) : nullptr; 65 | 66 | if (LightComponent && LightComponent->bEnableEnvironmentalLighting) 67 | { 68 | if (!GrabDelegateHandle.IsValid()) 69 | { 70 | GrabDelegateHandle = GSlCameraProxy->AddToGrabDelegate([this](ESlErrorCode ErrorCode, const FSlTimestamp& Timestamp) { 71 | GrabCallback(ErrorCode, Timestamp); 72 | }); 73 | } 74 | 75 | bool bUpdateLighting = Batch->Tick(); 76 | if (bUpdateLighting) 77 | { 78 | sl::mr::environmentalLightingComputeDiffuseCoefficients(&LeftEyeTexture->Mat.Mat); 79 | 80 | sl::Matrix4f Red; 81 | sl::Matrix4f Green; 82 | sl::Matrix4f Blue; 83 | sl::mr::environmentalLightingGetShmMatrix(&Red, 0); 84 | sl::mr::environmentalLightingGetShmMatrix(&Green, 1); 85 | sl::mr::environmentalLightingGetShmMatrix(&Blue, 2); 86 | 87 | EnvironmentalLightingSettings.Red = sl::unreal::ToUnrealType(Red); 88 | EnvironmentalLightingSettings.Green = sl::unreal::ToUnrealType(Green); 89 | EnvironmentalLightingSettings.Blue = sl::unreal::ToUnrealType(Blue); 90 | } 91 | 92 | EnvironmentalLightingSettings.Exposure = sl::mr::environmentalLightingGetExposure(DeltaSeconds); 93 | EnvironmentalLightingSettings.Exposure += (EnvironmentalLightingSettings.Exposure > 0.1f ? 0.2f : 0.0f); 94 | EnvironmentalLightingSettings.Exposure = FMath::Min(2.0f, EnvironmentalLightingSettings.Exposure * 2.0f); 95 | 96 | LightComponent->SetIntensity(FMath::Clamp(EnvironmentalLightingSettings.Exposure, 0.005f, CVarEnvLightMaxIntensity.GetValueOnGameThread())); 97 | LightComponent->SetEnvironmentalLightingSettings(EnvironmentalLightingSettings); 98 | } 99 | else 100 | { 101 | GSlCameraProxy->RemoveFromGrabDelegate(GrabDelegateHandle); 102 | } 103 | } 104 | 105 | void AEnvironmentalLightingManager::ToggleTick() 106 | { 107 | if (GSlCameraProxy->IsCameraOpened()) 108 | { 109 | LeftEyeTexture = USlViewTexture::CreateCPUViewTexture(FName("EnvLightingLeftView"), 128, 72, ESlView::V_Left); 110 | 111 | Batch->AddTexture(LeftEyeTexture); 112 | } 113 | else 114 | { 115 | Batch->Clear(); 116 | 117 | delete LeftEyeTexture; 118 | LeftEyeTexture = nullptr; 119 | } 120 | 121 | SetActorTickEnabled(GSlCameraProxy->IsCameraOpened()); 122 | } 123 | 124 | void AEnvironmentalLightingManager::GrabCallback(ESlErrorCode ErrorCode, const FSlTimestamp& Timestamp) 125 | { 126 | if (ErrorCode != ESlErrorCode::EC_Success) 127 | { 128 | return; 129 | } 130 | 131 | Batch->RetrieveCurrentFrame(Timestamp); 132 | } -------------------------------------------------------------------------------- /Stereolabs/Source/EnvironmentalLighting/Private/EnvironmentalLighting.cpp: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #include "EnvironmentalLightingPrivatePCH.h" 4 | 5 | #define LOCTEXT_NAMESPACE "FStereolabsEnvironmentalLighting" 6 | 7 | void FStereolabsEnvironmentalLighting::StartupModule() 8 | { 9 | // This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module 10 | } 11 | 12 | void FStereolabsEnvironmentalLighting::ShutdownModule() 13 | { 14 | // This function may be called during shutdown to clean up your module. For modules that support dynamic reloading, 15 | // we call this function before unloading the module. 16 | } 17 | 18 | #undef LOCTEXT_NAMESPACE 19 | 20 | IMPLEMENT_MODULE(FStereolabsEnvironmentalLighting, EnvironmentalLighting) -------------------------------------------------------------------------------- /Stereolabs/Source/EnvironmentalLighting/Private/EnvironmentalLightingPrivatePCH.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "EnvironmentalLighting.h" 6 | 7 | #include "Engine.h" 8 | #include "CoreUObject.h" 9 | #include "GameFramework/Actor.h" 10 | -------------------------------------------------------------------------------- /Stereolabs/Source/EnvironmentalLighting/Public/Core/EnvironmentalLightingManager.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "Stereolabs/Public/Core/StereolabsTextureBatch.h" 6 | #include "Stereolabs/Public/Core/StereolabsTexture.h" 7 | #include "Engine/DirectionalLight.h" 8 | 9 | #include "EnvironmentalLightingManager.generated.h" 10 | 11 | /* 12 | * Manager for environmental lighting 13 | */ 14 | UCLASS(Category = "Stereolabs|EnvironmentalLighting") 15 | class ENVIRONMENTALLIGHTING_API AEnvironmentalLightingManager : public AActor 16 | { 17 | GENERATED_BODY() 18 | 19 | public: 20 | AEnvironmentalLightingManager(); 21 | 22 | protected: 23 | virtual void BeginPlay() override; 24 | 25 | public: 26 | virtual void Tick(float DeltaSeconds) override; 27 | virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override; 28 | 29 | 30 | private: 31 | UFUNCTION() 32 | void ToggleTick(); 33 | 34 | /* 35 | * Callback updating texture 36 | */ 37 | void GrabCallback(ESlErrorCode ErrorCode, const FSlTimestamp& Timestamp); 38 | 39 | public: 40 | /** Current directional light using environmental lighting */ 41 | UPROPERTY(EditAnywhere, BlueprintReadWrite) 42 | ADirectionalLight* Light; 43 | 44 | private: 45 | /** Batch for the CPU texture */ 46 | UPROPERTY() 47 | USlTextureBatch* Batch; 48 | 49 | /** CPU left texture */ 50 | UPROPERTY() 51 | USlTexture* LeftEyeTexture; 52 | 53 | /** The grab delegate handle */ 54 | FDelegateHandle GrabDelegateHandle; 55 | 56 | /** Lighting data*/ 57 | FEnvironmentalLightingSettings EnvironmentalLightingSettings; 58 | 59 | /** Update timestamp section */ 60 | FCriticalSection TimestampSection; 61 | }; -------------------------------------------------------------------------------- /Stereolabs/Source/EnvironmentalLighting/Public/EnvironmentalLighting.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "ModuleManager.h" 6 | 7 | class FStereolabsEnvironmentalLighting : public IModuleInterface 8 | { 9 | public: 10 | /** IModuleInterface implementation */ 11 | virtual void StartupModule() override; 12 | virtual void ShutdownModule() override; 13 | }; -------------------------------------------------------------------------------- /Stereolabs/Source/SpatialMapping/Private/Core/SpatialMappingCubemapManager.cpp: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #include "SpatialMappingPrivatePCH.h" 4 | #include "SpatialMapping/Public/Core/SpatialMappingCubemapManager.h" 5 | 6 | ASpatialMappingCubemapManager::ASpatialMappingCubemapManager() 7 | : 8 | bCanUpdateTextureTarget(true), 9 | CubemapWorker(nullptr), 10 | Cubemap(nullptr), 11 | TextureTarget(nullptr), 12 | Camera(nullptr) 13 | { 14 | PrimaryActorTick.bCanEverTick = true; 15 | PrimaryActorTick.TickGroup = ETickingGroup::TG_PrePhysics; 16 | 17 | RootComponent = CreateDefaultSubobject(TEXT("RootComponent")); 18 | 19 | Camera = CreateDefaultSubobject(TEXT("MainCamera"), true); 20 | Camera->SetupAttachment(RootComponent); 21 | Camera->bCaptureEveryFrame = false; 22 | Camera->bCaptureOnMovement = false; 23 | } 24 | 25 | void ASpatialMappingCubemapManager::BeginPlay() 26 | { 27 | Super::BeginPlay(); 28 | 29 | if (TextureTarget && TextureTarget->IsValidLowLevel()) 30 | { 31 | SetTextureTarget(TextureTarget); 32 | } 33 | 34 | CubemapWorker = new FSpatialMappingCubemapRunnable(&CubemapProxy); 35 | CubemapWorker->Start(1.0f); 36 | CubemapWorker->Sleep(); 37 | } 38 | 39 | void ASpatialMappingCubemapManager::EndPlay(const EEndPlayReason::Type EndPlayReason) 40 | { 41 | Super::EndPlay(EndPlayReason); 42 | 43 | if (CubemapWorker) 44 | { 45 | CubemapWorker->EnsureCompletion(); 46 | delete CubemapWorker; 47 | CubemapWorker = nullptr; 48 | } 49 | } 50 | 51 | void ASpatialMappingCubemapManager::Tick(float DeltaSeconds) 52 | { 53 | Super::Tick(DeltaSeconds); 54 | 55 | if (CubemapProxy.bComplete) 56 | { 57 | // Suspend thread 58 | CubemapWorker->Sleep(); 59 | // Building complete can update texture target 60 | bCanUpdateTextureTarget = true; 61 | // Reset flag 62 | CubemapProxy.bComplete = false; 63 | // Reset proxy cubemap 64 | CubemapProxy.Cubemap = nullptr; 65 | // Update cubemap resource 66 | Cubemap->UpdateResource(); 67 | // Notify 68 | OnCubemapBuildComplete.Broadcast(Cubemap); 69 | } 70 | } 71 | 72 | #if WITH_EDITOR 73 | void ASpatialMappingCubemapManager::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) 74 | { 75 | FName PropertyName = (PropertyChangedEvent.Property != NULL) ? PropertyChangedEvent.Property->GetFName() : NAME_None; 76 | 77 | if (PropertyName == GET_MEMBER_NAME_CHECKED(ASpatialMappingCubemapManager, TextureTarget)) 78 | { 79 | SetTextureTarget(TextureTarget); 80 | } 81 | 82 | Super::PostEditChangeProperty(PropertyChangedEvent); 83 | } 84 | 85 | bool ASpatialMappingCubemapManager::CanEditChange(const UProperty* InProperty) const 86 | { 87 | FName PropertyName = InProperty->GetFName(); 88 | 89 | 90 | if (PropertyName == GET_MEMBER_NAME_CHECKED(ASpatialMappingCubemapManager, TextureTarget)) 91 | { 92 | return CubemapWorker == nullptr; 93 | } 94 | 95 | return Super::CanEditChange(InProperty); 96 | } 97 | #endif 98 | 99 | bool ASpatialMappingCubemapManager::BuildCubemap(const FName& Name) 100 | { 101 | // Cubemap build not finished 102 | if (!CubemapWorker->IsSleeping()) 103 | { 104 | return false; 105 | } 106 | 107 | bCanUpdateTextureTarget = false; 108 | 109 | // create the cube texture or retrieve the existing one 110 | Cubemap = NewObject( 111 | GetTransientPackage(), 112 | Name, 113 | RF_Transient); 114 | 115 | CubemapProxy.Cubemap = Cubemap; 116 | CubemapWorker->GetPixels(); 117 | CubemapWorker->Awake(); 118 | 119 | return true; 120 | } 121 | 122 | void ASpatialMappingCubemapManager::CaptureScene() 123 | { 124 | Camera->CaptureScene(); 125 | } 126 | 127 | bool ASpatialMappingCubemapManager::SetTextureTarget(UTextureRenderTargetCube* NewTextureTarget) 128 | { 129 | if (!bCanUpdateTextureTarget) 130 | { 131 | return false; 132 | } 133 | 134 | Camera->TextureTarget = NewTextureTarget; 135 | CubemapProxy.TextureTarget = NewTextureTarget; 136 | 137 | return true; 138 | } -------------------------------------------------------------------------------- /Stereolabs/Source/SpatialMapping/Private/SpatialMapping.cpp: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #include "SpatialMappingPrivatePCH.h" 4 | 5 | #define LOCTEXT_NAMESPACE "FStereolabsSpatialMapping" 6 | 7 | void FStereolabsSpatialMapping::StartupModule() 8 | { 9 | // This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module 10 | } 11 | 12 | void FStereolabsSpatialMapping::ShutdownModule() 13 | { 14 | // This function may be called during shutdown to clean up your module. For modules that support dynamic reloading, 15 | // we call this function before unloading the module. 16 | } 17 | 18 | #undef LOCTEXT_NAMESPACE 19 | 20 | IMPLEMENT_MODULE(FStereolabsSpatialMapping, SpatialMapping) -------------------------------------------------------------------------------- /Stereolabs/Source/SpatialMapping/Private/SpatialMappingPrivatePCH.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "SpatialMapping.h" 6 | 7 | #include "Engine.h" 8 | #include "CoreUObject.h" 9 | #include "GameFramework/Actor.h" 10 | 11 | DECLARE_STATS_GROUP(TEXT("SPATIALMAPPING"), STATGROUP_SPATIALMAPPING, STATCAT_Advanced); 12 | DECLARE_CYCLE_STAT_EXTERN(TEXT("UpdateMesh"), STAT_UpdateMesh, STATGROUP_SPATIALMAPPING, SPATIALMAPPING_API); -------------------------------------------------------------------------------- /Stereolabs/Source/SpatialMapping/Private/Threading/SpatialMappingCubemapRunnable.cpp: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #include "SpatialMappingPrivatePCH.h" 4 | #include "SpatialMapping/Private/Threading/SpatialMappingCubemapRunnable.h" 5 | #include "SpatialMapping/Public/Core/SpatialMappingCubemapManager.h" 6 | 7 | FSpatialMappingCubemapRunnable::FSpatialMappingCubemapRunnable(FSpatialMappingCubemapProxy* CubemapProxy) 8 | : 9 | CubemapProxy(CubemapProxy), 10 | bPixelsInitialized(false) 11 | { 12 | } 13 | 14 | bool FSpatialMappingCubemapRunnable::Init() 15 | { 16 | OutputBuffersLDR.AddZeroed(6); 17 | OutputBuffersHDR.AddZeroed(6); 18 | 19 | return FSlRunnable::Init(); 20 | } 21 | 22 | uint32 FSpatialMappingCubemapRunnable::Run() 23 | { 24 | FPlatformProcess::SleepNoStats(0.0f); 25 | 26 | while (bIsRunning) 27 | { 28 | if (bIsSleeping) 29 | { 30 | FPlatformProcess::ConditionalSleep([this]() -> bool { 31 | return !bIsSleeping; 32 | }); 33 | } 34 | 35 | Timer.Start(); 36 | 37 | if (!CubemapProxy->bComplete && CubemapProxy->Cubemap && bPixelsInitialized) 38 | { 39 | ConverToTextureCube(); 40 | bPixelsInitialized = false; 41 | CubemapProxy->bComplete = true; 42 | } 43 | 44 | Timer.Stop(); 45 | 46 | if (Timer.CanSleep()) 47 | { 48 | FPlatformProcess::Sleep(Timer.GetSleepingTimeSeconds()); 49 | } 50 | } 51 | 52 | return 0; 53 | } 54 | 55 | void FSpatialMappingCubemapRunnable::Stop() 56 | { 57 | FSlRunnable::Stop(); 58 | } 59 | 60 | void FSpatialMappingCubemapRunnable::Exit() 61 | { 62 | CubemapProxy = nullptr; 63 | } 64 | 65 | void FSpatialMappingCubemapRunnable::Start(float Frequency) 66 | { 67 | static uint64 ThreadCounter = 0; 68 | 69 | Timer.SetFrequency(Frequency); 70 | 71 | FString ThreadName("ZEDCubemapMakerThread"); 72 | ThreadName.AppendInt(ThreadCounter++); 73 | 74 | Thread = FRunnableThread::Create(this, *ThreadName, 0, TPri_BelowNormal); 75 | } 76 | 77 | void FSpatialMappingCubemapRunnable::GetPixels() 78 | { 79 | const EPixelFormat PixelFormat = CubemapProxy->TextureTarget->GetFormat(); 80 | ETextureSourceFormat TextureFormat = TSF_Invalid; 81 | switch (PixelFormat) 82 | { 83 | case PF_FloatRGBA: 84 | TextureFormat = TSF_RGBA16F; 85 | break; 86 | case PF_B8G8R8A8: 87 | TextureFormat = TSF_BGRA8; 88 | break; 89 | } 90 | 91 | FTextureRenderTargetCubeResource* CubeResource = (FTextureRenderTargetCubeResource*)static_cast(CubemapProxy->TextureTarget->Resource); 92 | 93 | if (CubeResource && TextureFormat != TSF_Invalid) 94 | { 95 | switch (TextureFormat) 96 | { 97 | case TSF_BGRA8: 98 | { 99 | AsyncTask(ENamedThreads::GameThread, [this, CubeResource = CubeResource]() 100 | { 101 | for (int32 SliceIndex = 0; SliceIndex < 6; SliceIndex++) 102 | { 103 | CubeResource->ReadPixels(OutputBuffersLDR[SliceIndex], FReadSurfaceDataFlags(RCM_UNorm, (ECubeFace)SliceIndex)); 104 | } 105 | 106 | bPixelsInitialized = true; 107 | }); 108 | } 109 | break; 110 | case TSF_RGBA16F: 111 | { 112 | AsyncTask(ENamedThreads::GameThread, [this, CubeResource = CubeResource]() 113 | { 114 | for (int32 SliceIndex = 0; SliceIndex < 6; SliceIndex++) 115 | { 116 | CubeResource->ReadPixels(OutputBuffersHDR[SliceIndex], FReadSurfaceDataFlags(RCM_UNorm, (ECubeFace)SliceIndex)); 117 | } 118 | 119 | bPixelsInitialized = true; 120 | }); 121 | } 122 | break; 123 | } 124 | } 125 | } 126 | 127 | void FSpatialMappingCubemapRunnable::ConverToTextureCube() 128 | { 129 | // Check render target size is valid and power of two. 130 | if (CubemapProxy->TextureTarget->SizeX != 0 && !(CubemapProxy->TextureTarget->SizeX & (CubemapProxy->TextureTarget->SizeX - 1))) 131 | { 132 | const EPixelFormat PixelFormat = CubemapProxy->TextureTarget->GetFormat(); 133 | ETextureSourceFormat TextureFormat = TSF_Invalid; 134 | switch (PixelFormat) 135 | { 136 | case PF_FloatRGBA: 137 | TextureFormat = TSF_RGBA16F; 138 | break; 139 | case PF_B8G8R8A8: 140 | TextureFormat = TSF_BGRA8; 141 | break; 142 | } 143 | 144 | // The r2t resource will be needed to read its surface contents 145 | FTextureRenderTargetCubeResource* CubeResource = (FTextureRenderTargetCubeResource*)static_cast(CubemapProxy->TextureTarget->Resource); 146 | if (CubeResource && TextureFormat != TSF_Invalid) 147 | { 148 | bool bSRGB = true; 149 | // if render target gamma used was 1.0 then disable SRGB for the static texture 150 | if (FMath::Abs(CubeResource->GetDisplayGamma() - 1.0f) < KINDA_SMALL_NUMBER) 151 | { 152 | bSRGB = false; 153 | } 154 | 155 | int32 MipSize = CalculateImageBytes(CubemapProxy->TextureTarget->SizeX, CubemapProxy->TextureTarget->SizeX, 0, PixelFormat); 156 | 157 | if (CubemapProxy->Cubemap->PlatformData) 158 | { 159 | delete CubemapProxy->Cubemap->PlatformData; 160 | } 161 | 162 | CubemapProxy->Cubemap->PlatformData = new FTexturePlatformData(); 163 | CubemapProxy->Cubemap->PlatformData->SizeX = CubemapProxy->TextureTarget->SizeX; 164 | CubemapProxy->Cubemap->PlatformData->SizeY = CubemapProxy->TextureTarget->SizeX; 165 | CubemapProxy->Cubemap->PlatformData->PixelFormat = PixelFormat; 166 | 167 | { 168 | FTexture2DMipMap* Mip = new(CubemapProxy->Cubemap->PlatformData->Mips) FTexture2DMipMap(); 169 | Mip->SizeX = CubemapProxy->TextureTarget->SizeX; 170 | Mip->SizeY = CubemapProxy->TextureTarget->SizeX; 171 | Mip->BulkData.Lock(LOCK_READ_WRITE); 172 | Mip->BulkData.Realloc(Mip->SizeX * Mip->SizeY * 6 * GPixelFormats[PixelFormat].BlockBytes); 173 | Mip->BulkData.Unlock(); 174 | } 175 | 176 | FTexture2DMipMap& Mip = CubemapProxy->Cubemap->PlatformData->Mips[0]; 177 | uint8* SliceData = (uint8*)Mip.BulkData.Lock(LOCK_READ_WRITE); 178 | 179 | switch (TextureFormat) 180 | { 181 | case TSF_BGRA8: 182 | { 183 | for (int32 SliceIndex = 0; SliceIndex < 6; SliceIndex++) 184 | { 185 | FMemory::Memcpy((FColor*)(SliceData + SliceIndex * MipSize), OutputBuffersLDR[SliceIndex].GetData(), MipSize); 186 | } 187 | } 188 | break; 189 | case TSF_RGBA16F: 190 | { 191 | for (int32 SliceIndex = 0; SliceIndex < 6; SliceIndex++) 192 | { 193 | FMemory::Memcpy((FFloat16Color*)(SliceData + SliceIndex * MipSize), OutputBuffersHDR[SliceIndex].GetData(), MipSize); 194 | } 195 | } 196 | break; 197 | } 198 | 199 | Mip.BulkData.Unlock(); 200 | 201 | CubemapProxy->Cubemap->SRGB = bSRGB; 202 | // If HDR source image then choose HDR compression settings.. 203 | CubemapProxy->Cubemap->CompressionSettings = TextureFormat == TSF_RGBA16F ? TextureCompressionSettings::TC_HDR : TextureCompressionSettings::TC_Default; 204 | #if WITH_EDITORONLY_DATA 205 | CubemapProxy->Cubemap->CompressionNone = true; 206 | CubemapProxy->Cubemap->CompressionNoAlpha = true; 207 | CubemapProxy->Cubemap->DeferCompression = true; 208 | CubemapProxy->Cubemap->MipGenSettings = TextureMipGenSettings::TMGS_NoMipmaps; 209 | #endif 210 | } 211 | } 212 | } -------------------------------------------------------------------------------- /Stereolabs/Source/SpatialMapping/Private/Threading/SpatialMappingCubemapRunnable.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "Stereolabs/Public/Threading/StereolabsRunnable.h" 6 | 7 | /* 8 | * Build a cubemap asynchronously 9 | */ 10 | class FSpatialMappingCubemapRunnable : public FSlRunnable 11 | { 12 | public: 13 | FSpatialMappingCubemapRunnable(struct FSpatialMappingCubemapProxy* CubemapProxy); 14 | 15 | public: 16 | virtual bool Init() override; 17 | virtual uint32 Run() override; 18 | virtual void Start(float Frequency) override; 19 | virtual void Stop() override; 20 | virtual void Exit() override; 21 | 22 | public: 23 | /* 24 | * Get the pixels of the texture target 25 | */ 26 | void GetPixels(); 27 | 28 | /* 29 | * Convert the texture target to cubemap 30 | */ 31 | void ConverToTextureCube(); 32 | 33 | private: 34 | /** True if the pixels are initialized */ 35 | FThreadSafeBool bPixelsInitialized; 36 | 37 | /** The buffer of pixels in LDR */ 38 | TArray> OutputBuffersLDR; 39 | 40 | /** The buffer of pixels in HDR */ 41 | TArray> OutputBuffersHDR; 42 | 43 | /** Proxy */ 44 | struct FSpatialMappingCubemapProxy* CubemapProxy; 45 | }; 46 | 47 | -------------------------------------------------------------------------------- /Stereolabs/Source/SpatialMapping/Private/Threading/SpatialMappingRunnable.cpp: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #include "SpatialMappingPrivatePCH.h" 4 | #include "SpatialMapping/Private/Threading/SpatialMappingRunnable.h" 5 | #include "SpatialMapping/Public/Core/SpatialMappingManager.h" 6 | #include "Stereolabs/Public/Core/StereolabsCoreUtilities.h" 7 | 8 | #include "RenderUtils.h" 9 | 10 | DEFINE_STAT(STAT_UpdateMesh) 11 | DEFINE_LOG_CATEGORY(SpatialMappingThread); 12 | 13 | FSpatialMappingRunnable::FSpatialMappingRunnable(ASpatialMappingManager* SpatialMappingManager, USlMesh* Mesh) 14 | : 15 | SpatialMappingManager(SpatialMappingManager), 16 | Mesh(Mesh) 17 | { 18 | } 19 | 20 | bool FSpatialMappingRunnable::Init() 21 | { 22 | return FSlRunnable::Init(); 23 | } 24 | 25 | uint32 FSpatialMappingRunnable::Run() 26 | { 27 | FPlatformProcess::SleepNoStats(0.0f); 28 | 29 | while (bIsRunning) 30 | { 31 | if (bIsSleeping) 32 | { 33 | FPlatformProcess::ConditionalSleep([this]() -> bool { 34 | return !bIsSleeping; 35 | }); 36 | } 37 | 38 | Timer.Start(); 39 | 40 | SL_SCOPE_LOCK(Lock, StepSection) 41 | CurrentStep = Step; 42 | SL_SCOPE_UNLOCK 43 | 44 | switch (CurrentStep) 45 | { 46 | case ESpatialMappingStep::SS_Scan: 47 | { 48 | int Retrieved = RetrieveMesh(); 49 | 50 | if (Retrieved == 1) 51 | { 52 | UpdateMesh(); 53 | } 54 | else if(Retrieved == -1) 55 | { 56 | SpatialMappingManager->StepFailed(CurrentStep); 57 | SL_LOG_E(SpatialMappingThread, "Can't retrieve mesh"); 58 | } 59 | } 60 | break; 61 | case ESpatialMappingStep::SS_Filter: 62 | { 63 | bool bFiltered = FilterMesh(); 64 | 65 | if (bFiltered) 66 | { 67 | UpdateMesh(); 68 | } 69 | else 70 | { 71 | SpatialMappingManager->StepFailed(CurrentStep); 72 | SL_LOG_E(SpatialMappingThread, "Can't filter mesh"); 73 | } 74 | 75 | Step = ESpatialMappingStep::SS_None; 76 | } 77 | break; 78 | case ESpatialMappingStep::SS_Texture: 79 | { 80 | bool bTextured = TextureMesh(); 81 | 82 | if (!bTextured) 83 | { 84 | SpatialMappingManager->StepFailed(CurrentStep); 85 | SL_LOG_E(SpatialMappingThread, "Can't texture mesh"); 86 | } 87 | 88 | Step = ESpatialMappingStep::SS_None; 89 | } 90 | break; 91 | case ESpatialMappingStep::SS_Load: 92 | { 93 | bool bLoaded = LoadMesh(); 94 | 95 | if (bLoaded) 96 | { 97 | UpdateMesh(); 98 | } 99 | else 100 | { 101 | SpatialMappingManager->StepFailed(CurrentStep); 102 | SL_LOG_E(SpatialMappingThread, "Can't load mesh"); 103 | } 104 | 105 | Step = ESpatialMappingStep::SS_None; 106 | } 107 | break; 108 | case ESpatialMappingStep::SS_Save: 109 | { 110 | bool bSaved = SaveMesh(); 111 | 112 | if(!bSaved) 113 | { 114 | SpatialMappingManager->StepFailed(CurrentStep); 115 | SL_LOG_E(SpatialMappingThread, "Can't save mesh"); 116 | } 117 | 118 | Step = ESpatialMappingStep::SS_None; 119 | } 120 | break; 121 | } 122 | 123 | if (Timer.CanSleep()) 124 | { 125 | FPlatformProcess::Sleep(Timer.GetSleepingTimeSeconds()); 126 | } 127 | } 128 | 129 | return 0; 130 | } 131 | 132 | void FSpatialMappingRunnable::Stop() 133 | { 134 | FSlRunnable::Stop(); 135 | } 136 | 137 | void FSpatialMappingRunnable::Exit() 138 | { 139 | } 140 | 141 | void FSpatialMappingRunnable::Start(float Frequency) 142 | { 143 | static uint64 ThreadCounter = 0; 144 | 145 | Timer.SetFrequency(Frequency); 146 | 147 | FString ThreadName("SLSpatialMappingThread"); 148 | ThreadName.AppendInt(ThreadCounter++); 149 | 150 | Thread = FRunnableThread::Create(this, *ThreadName, 0, TPri_BelowNormal); 151 | } 152 | 153 | void FSpatialMappingRunnable::SetStep(ESpatialMappingStep NewStep) 154 | { 155 | SL_SCOPE_LOCK(Lock, StepSection) 156 | Step = NewStep; 157 | SL_SCOPE_UNLOCK 158 | } 159 | 160 | ESpatialMappingStep FSpatialMappingRunnable::GetStep() 161 | { 162 | SL_SCOPE_LOCK(Lock, StepSection) 163 | return CurrentStep; 164 | SL_SCOPE_UNLOCK 165 | } 166 | 167 | int FSpatialMappingRunnable::RetrieveMesh() 168 | { 169 | GSlCameraProxy->RequestMeshAsync(); 170 | 171 | return (GSlCameraProxy->GetMeshIsReadyAsync() ? (GSlCameraProxy->RetrieveMeshAsync(Mesh) ? 1 : -1) : 0); 172 | } 173 | 174 | bool FSpatialMappingRunnable::FilterMesh() 175 | { 176 | // Sleep in case no buffer available 177 | FPlatformProcess::Sleep(0.5f); 178 | 179 | return Mesh->Filter(MeshFilterParameters, false); 180 | } 181 | 182 | bool FSpatialMappingRunnable::TextureMesh() 183 | { 184 | bool bIsMeshTextured = Mesh->ApplyTexture(ESlMeshTextureFormat::MTF_RGBA, TexturingMode == ESpatialMappingTexturingMode::TM_Cubemap); 185 | if (bIsMeshTextured) 186 | { 187 | UpdateMesh(); 188 | 189 | return true; 190 | } 191 | 192 | return false; 193 | } 194 | 195 | void FSpatialMappingRunnable::UpdateMesh() 196 | { 197 | SCOPE_CYCLE_COUNTER(STAT_UpdateMesh); 198 | 199 | Mesh->UpdateMeshFromChunks(TArray()); 200 | 201 | SL_SCOPE_LOCK(Lock, SpatialMappingManager->MeshDataUpdateSection) 202 | Mesh->UpdateMeshData(); 203 | 204 | SpatialMappingManager->Step = Step; 205 | SL_SCOPE_UNLOCK 206 | } 207 | 208 | bool FSpatialMappingRunnable::LoadMesh() 209 | { 210 | FString Path; 211 | 212 | SL_SCOPE_LOCK(Lock, MeshOperationSection) 213 | Path = MeshLoadingPath; 214 | SL_SCOPE_UNLOCK 215 | 216 | return Mesh->Load(Path); 217 | } 218 | 219 | bool FSpatialMappingRunnable::SaveMesh() 220 | { 221 | FString Path; 222 | ESlMeshFileFormat Format; 223 | 224 | SL_SCOPE_LOCK(Lock, MeshOperationSection) 225 | Path = MeshSavingPath; 226 | Format = MeshFileFormat; 227 | SL_SCOPE_UNLOCK 228 | 229 | Mesh->Mesh.applyTexture(sl::MESH_TEXTURE_FORMAT::RGBA); 230 | 231 | bool bSaved = Mesh->Save(*Path, TArray(), Format); 232 | 233 | Mesh->Mesh.texture.free(); 234 | 235 | SL_SCOPE_LOCK(Lock, SpatialMappingManager->MeshDataUpdateSection) 236 | SpatialMappingManager->Step = Step; 237 | SL_SCOPE_UNLOCK 238 | 239 | return bSaved; 240 | } 241 | 242 | void FSpatialMappingRunnable::SetSaveMeshData(FString NewMeshSavingPath, ESlMeshFileFormat NewMeshFileFormat) 243 | { 244 | SL_SCOPE_LOCK(Lock, MeshOperationSection) 245 | MeshSavingPath = NewMeshSavingPath; 246 | MeshFileFormat = NewMeshFileFormat; 247 | SL_SCOPE_UNLOCK 248 | } 249 | 250 | void FSpatialMappingRunnable::SetLoadMeshData(FString NewMeshLoadingPath) 251 | { 252 | SL_SCOPE_LOCK(Lock, MeshOperationSection) 253 | MeshLoadingPath = NewMeshLoadingPath; 254 | SL_SCOPE_UNLOCK 255 | } 256 | -------------------------------------------------------------------------------- /Stereolabs/Source/SpatialMapping/Private/Threading/SpatialMappingRunnable.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "Stereolabs/Public/Core/StereolabsCoreGlobals.h" 6 | #include "Stereolabs/Public/Threading/StereolabsRunnable.h" 7 | #include "Stereolabs/Public/Core/StereolabsMesh.h" 8 | 9 | DECLARE_LOG_CATEGORY_EXTERN(SpatialMappingThread, Log, All); 10 | 11 | class FSpatialMappingRunnable : public FSlRunnable 12 | { 13 | public: 14 | FSpatialMappingRunnable(class ASpatialMappingManager* SpatialMappingManager, USlMesh* Mesh); 15 | 16 | public: 17 | virtual bool Init() override; 18 | virtual uint32 Run() override; 19 | virtual void Start(float Frequency) override; 20 | virtual void Stop() override; 21 | virtual void Exit() override; 22 | 23 | private: 24 | /* 25 | * Retrieve the mesh 26 | * @return 0 if mesh not ready, 1 if mesh ready and retrieved, -1 if mesh ready but retrieved failed 27 | */ 28 | int RetrieveMesh(); 29 | 30 | /* 31 | * Filter the mesh 32 | * @return True if filtered 33 | */ 34 | bool FilterMesh(); 35 | 36 | /* 37 | * Texture the mesh 38 | * @return True if textured 39 | */ 40 | bool TextureMesh(); 41 | 42 | /* 43 | * Update the mesh data 44 | * @param bGenerateNewMeshData True to create a new instance of MeshData 45 | */ 46 | void UpdateMesh(); 47 | 48 | /* 49 | * Load the mesh from a file 50 | */ 51 | bool LoadMesh(); 52 | 53 | /* 54 | * Save the mesh to a file 55 | */ 56 | bool SaveMesh(); 57 | 58 | public: 59 | /* 60 | * Set the current step 61 | * @param NewStep The new step 62 | */ 63 | void SetStep(ESpatialMappingStep NewStep); 64 | 65 | /* 66 | * @return The current step 67 | */ 68 | ESpatialMappingStep GetStep(); 69 | 70 | /* 71 | * Set the save data 72 | * @param NewMeshSavingPath The path to save the mesh 73 | * @param NewMeshFileFormat the file format 74 | */ 75 | void SetSaveMeshData(FString NewMeshSavingPath, ESlMeshFileFormat NewMeshFileFormat); 76 | 77 | 78 | /* 79 | * Set the load data 80 | * @param NewMeshLoadingPath the path to load the mesh 81 | */ 82 | void SetLoadMeshData(FString NewMeshLoadingPath); 83 | 84 | public: 85 | /** Texturing mode for texturing */ 86 | ESpatialMappingTexturingMode TexturingMode; 87 | 88 | /** Mesh filter parameters */ 89 | FSlMeshFilterParameters MeshFilterParameters; 90 | 91 | private: 92 | /** Manager using this runnable */ 93 | class ASpatialMappingManager* SpatialMappingManager; 94 | 95 | /** Update step section */ 96 | FCriticalSection StepSection; 97 | 98 | /** Set load/save mesh data section */ 99 | FCriticalSection MeshOperationSection; 100 | 101 | /** The step set by the manager */ 102 | ESpatialMappingStep Step; 103 | 104 | /** The current step */ 105 | ESpatialMappingStep CurrentStep; 106 | 107 | /** The current mesh */ 108 | USlMesh* Mesh; 109 | 110 | /** Loading path */ 111 | FString MeshLoadingPath; 112 | 113 | /** Saving path */ 114 | FString MeshSavingPath; 115 | 116 | /** Mesh file format to save */ 117 | ESlMeshFileFormat MeshFileFormat; 118 | }; 119 | 120 | -------------------------------------------------------------------------------- /Stereolabs/Source/SpatialMapping/Public/Core/SpatialMappingBaseTypes.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | /* 6 | * Current step of SpatialMapping 7 | */ 8 | UENUM() 9 | enum class ESpatialMappingStep : uint8 10 | { 11 | SS_Scan UMETA(DisplayName = "SpatialMapping"), 12 | SS_Filter UMETA(DisplayName = "Filtering"), 13 | SS_Texture UMETA(DisplayName = "Texturing"), 14 | SS_Load UMETA(DisplayName = "Loading"), 15 | SS_Save UMETA(DisplayName = "Saving"), 16 | SS_Pause UMETA(DisplayName = "Pause"), 17 | SS_None UMETA(Hidden, DisplayName = "None") 18 | }; 19 | 20 | /* 21 | * 22 | */ 23 | UENUM(BlueprintType, Category = "Stereolabs|SpatialMapping|Enum") 24 | enum class ESpatialMappingTexturingMode : uint8 25 | { 26 | TM_Cubemap UMETA(DisplayName = "Cubemap"), 27 | TM_Render UMETA(DisplayName = "Render"), 28 | TM_None UMETA(Hidden, DisplayName = "None") 29 | }; -------------------------------------------------------------------------------- /Stereolabs/Source/SpatialMapping/Public/Core/SpatialMappingCubemapManager.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | #include "SpatialMapping/Private/Threading/SpatialMappingCubemapRunnable.h" 5 | 6 | #include "SpatialMappingCubemapManager.generated.h" 7 | 8 | struct FSpatialMappingCubemapProxy 9 | { 10 | UTextureRenderTargetCube* TextureTarget = nullptr; 11 | 12 | UTextureCube* Cubemap = nullptr; 13 | 14 | FThreadSafeBool bComplete = false; 15 | }; 16 | 17 | /* 18 | * 19 | */ 20 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FSpatialMappingCubemapDelegate, UTextureCube*, Cubemap); 21 | 22 | /* 23 | * Asynchronously build a cubemap 24 | */ 25 | UCLASS(Category = "Stereolabs|SpatialMapping") 26 | class SPATIALMAPPING_API ASpatialMappingCubemapManager : public AActor 27 | { 28 | GENERATED_BODY() 29 | 30 | public: 31 | ASpatialMappingCubemapManager(); 32 | 33 | virtual void BeginPlay() override; 34 | virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override; 35 | virtual void Tick(float DeltaSeconds) override; 36 | 37 | #if WITH_EDITOR 38 | virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override; 39 | virtual bool CanEditChange(const UProperty* InProperty) const override; 40 | #endif 41 | 42 | /* 43 | * Build the cubemap asynchronously 44 | * @param Name The name of the texture 45 | * @return False if the build can't be done because previous build is not finished 46 | */ 47 | UFUNCTION(BlueprintCallable, Category = "Zed|Cubemap") 48 | bool BuildCubemap(const FName& Name); 49 | 50 | /* 51 | * Capture the scene at the current actor location and orientation 52 | */ 53 | UFUNCTION(BlueprintCallable, Category = "Zed|Cubemap") 54 | void CaptureScene(); 55 | 56 | /* 57 | * Set the new texture target 58 | * @param NewTextureTarget The new texture target to render the scene to 59 | * @return True if the texture is set 60 | */ 61 | UFUNCTION(BlueprintCallable, Category = "Zed|Cubemap") 62 | bool SetTextureTarget(UTextureRenderTargetCube* NewTextureTarget); 63 | 64 | public: 65 | /** Cubemap build complete dispatcher */ 66 | UPROPERTY(BlueprintAssignable, Category = "Zed|Cubemap") 67 | FSpatialMappingCubemapDelegate OnCubemapBuildComplete; 68 | 69 | public: 70 | /** Camera render target */ 71 | UPROPERTY(EditAnywhere, Category = "Zed|Cubemap") 72 | UTextureRenderTargetCube* TextureTarget; 73 | 74 | /** Camera used to capture the cubemap */ 75 | UPROPERTY(BlueprintReadOnly) 76 | USceneCaptureComponentCube* Camera; 77 | 78 | private: 79 | /** Cubemap being updated */ 80 | UPROPERTY() 81 | UTextureCube* Cubemap; 82 | 83 | /** The thread doing the update */ 84 | FSpatialMappingCubemapRunnable* CubemapWorker; 85 | 86 | /** True if the target texture can be updated */ 87 | bool bCanUpdateTextureTarget; 88 | 89 | /** Proxy */ 90 | FSpatialMappingCubemapProxy CubemapProxy; 91 | }; 92 | -------------------------------------------------------------------------------- /Stereolabs/Source/SpatialMapping/Public/Core/SpatialMappingManager.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "Stereolabs/Public/Core/StereolabsCoreGlobals.h" 6 | #include "SpatialMapping/Public/Core/SpatialMappingBaseTypes.h" 7 | #include "SpatialMapping/Private/Threading/SpatialMappingRunnable.h" 8 | #include "Stereolabs/Public/Core/StereolabsMesh.h" 9 | 10 | #include "SpatialMappingManager.generated.h" 11 | 12 | /* 13 | * Mesh related delegate 14 | */ 15 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FSpatialMappingManagerMeshDelegate, const FSlMeshData&, MeshData); 16 | 17 | /* 18 | * Simple dynamic multicast delegate 19 | */ 20 | DECLARE_DYNAMIC_MULTICAST_DELEGATE(FSpatialMappingManagerDelegate); 21 | 22 | /* 23 | * Notify that a step a failed to complete 24 | */ 25 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FSpatialMappingStepFailedDelegate, ESpatialMappingStep, Step); 26 | 27 | /* 28 | * Actor that manage the spatial mapping 29 | */ 30 | UCLASS(Category = "Stereolabs|SpatialMapping") 31 | class SPATIALMAPPING_API ASpatialMappingManager : public AActor 32 | { 33 | GENERATED_BODY() 34 | 35 | public: 36 | ASpatialMappingManager(); 37 | 38 | virtual void BeginPlay() override; 39 | virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override; 40 | virtual void Tick(float DeltaSeconds) override; 41 | 42 | #if WITH_EDITOR 43 | virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override; 44 | virtual bool CanEditChange(const UProperty* InProperty) const override; 45 | #endif 46 | 47 | /* 48 | * @return True if the SpatialMapping is enabled 49 | */ 50 | UFUNCTION(BlueprintPure, Category = "Zed|SpatialMapping") 51 | bool IsSpatialMappingEnabled(); 52 | 53 | /* 54 | * @return True if the SpatialMapping is paused 55 | */ 56 | UFUNCTION(BlueprintPure, Category = "Zed|SpatialMapping") 57 | bool IsSpatialMappingPaused(); 58 | 59 | /* 60 | * Enable the SpatialMapping in the SDK and start the SpatialMapping thread 61 | * @param bEnableZedSpatialMapping True to enable Zed spatial mapping with the SpatialMapping thread 62 | * @return True if bEnableZedSpatialMapping = false, else return true if Zed spatial mapping is enabled 63 | */ 64 | UFUNCTION(BlueprintCallable, Category = "Zed|SpatialMapping") 65 | void EnableSpatialMapping(); 66 | 67 | /* 68 | * Stop the SpatialMapping thread and Zed spatial mapping 69 | */ 70 | UFUNCTION(BlueprintCallable, Category = "Zed|SpatialMapping") 71 | void DisableSpatialMapping(); 72 | 73 | /* 74 | * Stop SpatialMapping thread and Zed spatial mapping, clear the mesh and restart the SpatialMapping thread 75 | * @return see EnableSpatialMapping 76 | */ 77 | UFUNCTION(BlueprintCallable, Category = "Zed|SpatialMapping") 78 | void ResetSpatialMapping(); 79 | 80 | /* 81 | * Start the spatial mapping 82 | * @return True if spatial mapping is enabled, false otherwise 83 | */ 84 | UFUNCTION(BlueprintCallable, Category = "Zed|SpatialMapping") 85 | bool StartSpatialMapping(); 86 | 87 | /* 88 | * Pause the SpatialMapping 89 | * @param bPaused True to pause, false to resume 90 | */ 91 | UFUNCTION(BlueprintCallable, Category = "Zed|SpatialMapping") 92 | void PauseSpatialMapping(bool bPaused); 93 | 94 | /* 95 | * Stop the spatial mapping but not the thread 96 | * Filtering mesh and texture mesh are still possible. 97 | */ 98 | UFUNCTION(BlueprintCallable, Category = "Zed|SpatialMapping") 99 | void StopSpatialMapping(); 100 | 101 | /* 102 | * Pause SpatialMapping and filter the mesh 103 | */ 104 | UFUNCTION(BlueprintCallable, Category = "Zed|SpatialMapping") 105 | void FilterMesh(); 106 | 107 | /* 108 | * Pause SpatialMapping and texture the mesh 109 | * @param TexturingMode The texturing mode selected 110 | */ 111 | UFUNCTION(BlueprintCallable, Category = "Zed|SpatialMapping") 112 | bool TextureMesh(ESpatialMappingTexturingMode TexturingMode); 113 | 114 | /* 115 | * Stop SpatialMapping and load the mesh 116 | */ 117 | UFUNCTION(BlueprintCallable, Category = "Zed|SpatialMapping") 118 | void LoadMesh(); 119 | 120 | /* 121 | * Pause SpatialMapping and save the mesh 122 | */ 123 | UFUNCTION(BlueprintCallable, Category = "Zed|SpatialMapping") 124 | void SaveMesh(); 125 | 126 | /* 127 | * @return the number of vertices in the mesh 128 | */ 129 | UFUNCTION(BlueprintPure, Category = "Zed|SpatialMapping") 130 | int GetMeshVerticesNumber(); 131 | 132 | public: 133 | /* 134 | * Notify that the step failed to complete 135 | */ 136 | void StepFailed(ESpatialMappingStep NewFailedStep); 137 | 138 | private: 139 | /* 140 | * Set the step in the SpatialMapping thread 141 | */ 142 | void SetStep(ESpatialMappingStep NewStep); 143 | 144 | public: 145 | /** SpatialMapping enabled dispatcher */ 146 | UPROPERTY(BlueprintAssignable, Category = "Zed|SpatialMapping") 147 | FSpatialMappingManagerDelegate OnScaningEnabled; 148 | 149 | /** SpatialMapping disabled dispatcher */ 150 | UPROPERTY(BlueprintAssignable, Category = "Zed|SpatialMapping") 151 | FSpatialMappingManagerDelegate OnSpatialMappingDisabled; 152 | 153 | /** Step fail dispatcher */ 154 | UPROPERTY(BlueprintAssignable, Category = "Zed|SpatialMapping") 155 | FSpatialMappingStepFailedDelegate OnStepFailed; 156 | 157 | /** Mesh update dispatcher */ 158 | UPROPERTY(BlueprintAssignable, Category = "Zed|SpatialMapping") 159 | FSpatialMappingManagerMeshDelegate OnMeshUpdated; 160 | 161 | /** Mesh filtered dispatcher */ 162 | UPROPERTY(BlueprintAssignable, Category = "Zed|SpatialMapping") 163 | FSpatialMappingManagerMeshDelegate OnMeshFiltered; 164 | 165 | /** Mesh textured for cubemap dispatcher */ 166 | UPROPERTY(BlueprintAssignable, Category = "Zed|SpatialMapping") 167 | FSpatialMappingManagerMeshDelegate OnMeshTexturedForCubemap; 168 | 169 | /** Mesh textured for rendering dispatcher */ 170 | UPROPERTY(BlueprintAssignable, Category = "Zed|SpatialMapping") 171 | FSpatialMappingManagerMeshDelegate OnMeshTexturedForRendering; 172 | 173 | /** Mesh loaded dispatcher */ 174 | UPROPERTY(BlueprintAssignable, Category = "Zed|SpatialMapping") 175 | FSpatialMappingManagerMeshDelegate OnMeshLoaded; 176 | 177 | /** Mesh saved dispatcher */ 178 | UPROPERTY(BlueprintAssignable , Category = "Zed|SpatialMapping") 179 | FSpatialMappingManagerDelegate OnMeshSaved; 180 | 181 | /** SpatialMapping reset */ 182 | UPROPERTY(BlueprintAssignable, Category = "Zed|SpatialMapping") 183 | FSpatialMappingManagerDelegate OnSpatialMappingReset; 184 | 185 | public: 186 | /** Spatial mapping settings */ 187 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Zed") 188 | FSlSpatialMappingParameters SpatialMappingParameters; 189 | 190 | /** Filtering settings */ 191 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Zed") 192 | FSlMeshFilterParameters MeshFilterParameters; 193 | 194 | /** Mesh file format to save */ 195 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Zed") 196 | ESlMeshFileFormat MeshFileFormat; 197 | 198 | /** Absolute mesh loading path */ 199 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Zed") 200 | FString MeshLoadingPath; 201 | 202 | /** Absolute mesh saving path */ 203 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Zed") 204 | FString MeshSavingPath; 205 | 206 | /** The mesh being used for spatial memory. Not thread safe to access if SpatialMapping enable, use delegate instead. */ 207 | UPROPERTY(BlueprintReadOnly, Category = "Zed|SpatialMapping") 208 | USlMesh* Mesh; 209 | 210 | /** Mesh data update section */ 211 | FCriticalSection MeshDataUpdateSection; 212 | 213 | /** Mesh data update section */ 214 | FCriticalSection MeshDataAccessSection; 215 | 216 | /** Step associated with the mesh data */ 217 | ESpatialMappingStep Step; 218 | 219 | private: 220 | /** True if a step failed */ 221 | FThreadSafeBool bStepFailed; 222 | 223 | /** Step that has failed */ 224 | ESpatialMappingStep FailedStep; 225 | 226 | /** A worker to thread the SpatialMapping */ 227 | class FSpatialMappingRunnable* SpatialMappingWorker; 228 | 229 | /** Timer to check if new mesh data are available */ 230 | float UpdateTime; 231 | 232 | /** True if SpatialMapping is paused */ 233 | bool bSpatialMappingPaused; 234 | }; 235 | 236 | -------------------------------------------------------------------------------- /Stereolabs/Source/SpatialMapping/Public/SpatialMapping.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "ModuleManager.h" 6 | 7 | class FStereolabsSpatialMapping : public IModuleInterface 8 | { 9 | public: 10 | /** IModuleInterface implementation */ 11 | virtual void StartupModule() override; 12 | virtual void ShutdownModule() override; 13 | }; -------------------------------------------------------------------------------- /Stereolabs/Source/SpatialMapping/SpatialMapping.Build.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | using UnrealBuildTool; 4 | using System.IO; 5 | using System; 6 | 7 | public class SpatialMapping : ModuleRules 8 | { 9 | private string ModulePath 10 | { 11 | get { return ModuleDirectory; } 12 | } 13 | 14 | public SpatialMapping(ReadOnlyTargetRules Target) : base(Target) 15 | { 16 | PrivatePCHHeaderFile = "SpatialMapping/Public/SpatialMapping.h"; 17 | 18 | PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "Public")); 19 | PrivateIncludePaths.Add(Path.Combine(ModuleDirectory, "Private")); 20 | 21 | PublicDependencyModuleNames.AddRange( 22 | new string[] 23 | { 24 | "Stereolabs", 25 | "ZED" 26 | 27 | // ... add other public dependencies that you statically link with here ... 28 | } 29 | ); 30 | 31 | PrivateDependencyModuleNames.AddRange( 32 | new string[] 33 | { 34 | "Core", 35 | "CoreUObject", 36 | "RenderCore", 37 | "Engine" 38 | } 39 | ); 40 | } 41 | } 42 | 43 | 44 | -------------------------------------------------------------------------------- /Stereolabs/Source/SpatialMappingEditor/Private/SpatialMappingEditorPlugin.cpp: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #include "SpatialMappingEditorPrivatePCH.h" 4 | #include "SpatialMappingEditor/Public/SpatialMappingManagerDetails.h" 5 | 6 | #define LOCTEXT_NAMESPACE "FStereolabsSpatialMappingEditor" 7 | 8 | void FStereolabsSpatialMappingEditor::StartupModule() 9 | { 10 | // This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module 11 | FPropertyEditorModule& PropertyModule = FModuleManager::LoadModuleChecked("PropertyEditor"); 12 | 13 | PropertyModule.RegisterCustomClassLayout(ASpatialMappingManager::StaticClass()->GetFName(), FOnGetDetailCustomizationInstance::CreateStatic(&FSpatialMappingManagerDetails::MakeInstance)); 14 | } 15 | 16 | void FStereolabsSpatialMappingEditor::ShutdownModule() 17 | { 18 | // This function may be called during shutdown to clean up your module. For modules that support dynamic reloading, 19 | // we call this function before unloading the module. 20 | 21 | FPropertyEditorModule& PropertyModule = FModuleManager::LoadModuleChecked("PropertyEditor"); 22 | PropertyModule.UnregisterCustomClassLayout(ASpatialMappingManager::StaticClass()->GetFName()); 23 | } 24 | 25 | #undef LOCTEXT_NAMESPACE 26 | 27 | IMPLEMENT_MODULE(FStereolabsSpatialMappingEditor, SpatialMappingEditor) -------------------------------------------------------------------------------- /Stereolabs/Source/SpatialMappingEditor/Private/SpatialMappingEditorPrivatePCH.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "SpatialMappingEditorPlugin.h" 6 | 7 | #include "Engine.h" 8 | #include "CoreUObject.h" 9 | #include "UnrealEd.h" 10 | #include "PropertyEditorModule.h" 11 | #include "DetailLayoutBuilder.h" 12 | #include "DetailCategoryBuilder.h" 13 | #include "DetailWidgetRow.h" 14 | #include "IDetailsView.h" -------------------------------------------------------------------------------- /Stereolabs/Source/SpatialMappingEditor/Public/SpatialMappingEditorPlugin.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "ModuleManager.h" 6 | 7 | class FStereolabsSpatialMappingEditor : public IModuleInterface 8 | { 9 | public: 10 | /** IModuleInterface implementation */ 11 | virtual void StartupModule() override; 12 | virtual void ShutdownModule() override; 13 | }; -------------------------------------------------------------------------------- /Stereolabs/Source/SpatialMappingEditor/Public/SpatialMappingManagerDetails.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "SpatialMapping/Public/Core/SpatialMappingManager.h" 6 | #include "Stereolabs/Public/Core/StereolabsCameraProxy.h" 7 | #include "IDetailCustomization.h" 8 | #include "DetailLayoutBuilder.h" 9 | 10 | 11 | DECLARE_LOG_CATEGORY_EXTERN(SpatialMappingManagerDetails, Log, All); 12 | 13 | class FSpatialMappingManagerDetails : public IDetailCustomization 14 | { 15 | public: 16 | /** Makes a new instance of this detail layout class for a specific detail view requesting it */ 17 | static TSharedRef MakeInstance(); 18 | 19 | /** IDetailCustomization interface */ 20 | virtual void CustomizeDetails(IDetailLayoutBuilder& DetailBuilder) override; 21 | 22 | /** Button enabled */ 23 | bool IsSpatialMappingEnabled() const 24 | { 25 | ASpatialMappingManager* SpatialMappingManager = static_cast(SelectedObjects[0].Get()); 26 | 27 | return SpatialMappingManager->IsSpatialMappingEnabled()/* && GSlCameraProxy->bSpatialMappingEnabled*/; 28 | } 29 | 30 | /** Button enabled */ 31 | bool IsSpatialMappingDisabled() const { return !IsSpatialMappingEnabled(); } 32 | 33 | /** Button enabled */ 34 | bool IsSpatialMappingStarted() const { return IsSpatialMappingEnabled() && GSlCameraProxy && GSlCameraProxy->bSpatialMappingEnabled; } 35 | 36 | /** Button enabled */ 37 | bool IsSpatialMappingPaused() const 38 | { 39 | ASpatialMappingManager* SpatialMappingManager = static_cast(SelectedObjects[0].Get()); 40 | 41 | return IsSpatialMappingStarted() && SpatialMappingManager->IsSpatialMappingPaused(); 42 | } 43 | 44 | /** Button enabled */ 45 | bool IsSpatialMappingNotPaused() const 46 | { 47 | ASpatialMappingManager* SpatialMappingManager = static_cast(SelectedObjects[0].Get()); 48 | 49 | return IsSpatialMappingStarted() && !SpatialMappingManager->IsSpatialMappingPaused(); 50 | } 51 | 52 | /** Button enabled */ 53 | bool IsSpatialMappingStopped() const { return IsSpatialMappingEnabled() && GSlCameraProxy && !GSlCameraProxy->bSpatialMappingEnabled; } 54 | 55 | /** Button enabled */ 56 | bool HasMeshVertices() const 57 | { 58 | ASpatialMappingManager* SpatialMappingManager = static_cast(SelectedObjects[0].Get()); 59 | 60 | return IsSpatialMappingEnabled() && SpatialMappingManager->GetMeshVerticesNumber() > 0; 61 | } 62 | 63 | /** Button enabled */ 64 | bool IsTexturingEnabled() const 65 | { 66 | ASpatialMappingManager* SpatialMappingManager = static_cast(SelectedObjects[0].Get()); 67 | 68 | return IsSpatialMappingEnabled() && HasMeshVertices() && SpatialMappingManager->SpatialMappingParameters.bSaveTexture; 69 | } 70 | 71 | 72 | /** Clicking the enable SpatialMapping button */ 73 | FReply OnClickEnableSpatialMapping(); 74 | 75 | /** Clicking the disable SpatialMapping button */ 76 | FReply OnClickDisableSpatialMapping(); 77 | 78 | /** Clicking the reset SpatialMapping button */ 79 | FReply OnClickResetSpatialMapping(); 80 | 81 | /** Clicking the start SpatialMapping button */ 82 | FReply OnClickStartSpatialMapping(); 83 | 84 | /** Clicking the pause SpatialMapping button */ 85 | FReply OnClickPauseSpatialMapping(); 86 | 87 | /** Clicking the resume SpatialMapping button */ 88 | FReply OnClickResumeSpatialMapping(); 89 | 90 | /** Clicking the stop SpatialMapping button */ 91 | FReply OnClickStopSpatialMapping(); 92 | 93 | /** Clicking the filter mesh button */ 94 | FReply OnClickFilterMesh(); 95 | 96 | /** Clicking the texture mesh button */ 97 | FReply OnClickTextureMesh(); 98 | 99 | /** Clicking the load mesh button */ 100 | FReply OnClickLoadMesh(); 101 | 102 | /** Clicking the save mesh button */ 103 | FReply OnClickSaveMesh(); 104 | 105 | private: 106 | /** Can only be one camera actor */ 107 | TArray> SelectedObjects; 108 | 109 | /** Detail builder used to draw */ 110 | IDetailLayoutBuilder* CachedDetailBuilder; 111 | }; -------------------------------------------------------------------------------- /Stereolabs/Source/SpatialMappingEditor/SpatialMappingEditor.Build.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | using System.IO; 4 | 5 | namespace UnrealBuildTool.Rules 6 | { 7 | public class SpatialMappingEditor : ModuleRules 8 | { 9 | public SpatialMappingEditor(ReadOnlyTargetRules Target) : base(Target) 10 | { 11 | PrivatePCHHeaderFile = "SpatialMappingEditor/Public/SpatialMappingEditor.h"; 12 | 13 | PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "Public")); 14 | PrivateIncludePaths.Add(Path.Combine(ModuleDirectory, "Private")); 15 | 16 | PrivateDependencyModuleNames.AddRange(new string[] 17 | {"Slate", 18 | "SlateCore" }); 19 | 20 | PublicDependencyModuleNames.AddRange( 21 | new string[] 22 | { 23 | "Stereolabs", 24 | "SpatialMapping" 25 | } 26 | ); 27 | 28 | PublicDependencyModuleNames.AddRange( 29 | new string[] 30 | { 31 | "Core", 32 | "CoreUObject", 33 | "Slate", 34 | "SlateCore", 35 | "Engine", 36 | "UnrealEd", 37 | "HeadMountedDisplay", 38 | "DesktopPlatform", 39 | "InputCore" 40 | } 41 | ); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /Stereolabs/Source/Stereolabs/Private/Core/StereolabsBaseTypes.cpp: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #include "StereolabsPrivatePCH.h" 4 | #include "Stereolabs/Public/Core/StereolabsBaseTypes.h" 5 | #include "Stereolabs/Public/Core/StereolabsCoreGlobals.h" 6 | 7 | FSlSpatialMappingParameters::FSlSpatialMappingParameters() 8 | : 9 | MaxMemoryUsage(2048), 10 | PresetResolution(ESlSpatialMappingResolution::SMR_Medium), 11 | PresetRange(ESlSpatialMappingRange::SMR_Auto), 12 | bSaveTexture(false)/*, 13 | bUseChunkOnly(bUseChunkOnly)*/ 14 | { 15 | MaxRange = sl::SpatialMappingParameters::get(sl::unreal::ToSlType(PresetRange)); 16 | Resolution = sl::SpatialMappingParameters::get(sl::unreal::ToSlType(PresetResolution)); 17 | 18 | } 19 | 20 | void FSlSpatialMappingParameters::SetMaxRange(ESlSpatialMappingRange NewPresetRange) 21 | { 22 | PresetRange = NewPresetRange; 23 | MaxRange = sl::SpatialMappingParameters::get(sl::unreal::ToSlType(PresetRange)); 24 | } 25 | 26 | void FSlSpatialMappingParameters::SetResolution(ESlSpatialMappingResolution NewPresetResolution) 27 | { 28 | PresetResolution = NewPresetResolution; 29 | Resolution = sl::SpatialMappingParameters::get(sl::unreal::ToSlType(PresetResolution)); 30 | } -------------------------------------------------------------------------------- /Stereolabs/Source/Stereolabs/Private/Core/StereolabsCoreGlobals.cpp: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #include "StereolabsPrivatePCH.h" 4 | #include "Stereolabs/Public/Core/StereolabsCoreGlobals.h" 5 | #include "Stereolabs/Public/Core/StereolabsCameraProxy.h" 6 | 7 | uint32 GSlGrabThreadId = 0; 8 | 9 | bool GSlIsGrabThreadIdInitialized = false; 10 | 11 | float GSlEyeHalfBaseline = 0.0f; 12 | 13 | USlCameraProxy* GSlCameraProxy = nullptr; -------------------------------------------------------------------------------- /Stereolabs/Source/Stereolabs/Private/Core/StereolabsMesh.cpp: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #include "StereolabsPrivatePCH.h" 4 | #include "Stereolabs/Public/Core/StereolabsMesh.h" 5 | #include "Stereolabs/Public/Core/StereolabsCoreGlobals.h" 6 | 7 | USlMesh::USlMesh() 8 | { 9 | } 10 | 11 | void USlMesh::UpdateMeshData() 12 | { 13 | int VerticesNum = Mesh.vertices.size(); 14 | int IndicesNum = Mesh.triangles.size(); 15 | int UVNum = 0; 16 | 17 | MeshData.Vertices.Reset(VerticesNum); 18 | MeshData.Indices.Reset(IndicesNum * 3); 19 | 20 | if (MeshData.Texture) 21 | { 22 | UVNum = Mesh.uv.size(); 23 | 24 | MeshData.UV0.Reset(UVNum); 25 | } 26 | 27 | int MaxNum = FMath::Max(VerticesNum, IndicesNum); 28 | 29 | for (int i = 0; i < MaxNum; ++i) 30 | { 31 | if (i < VerticesNum) 32 | { 33 | MeshData.Vertices.Add(FVector( 34 | Mesh.vertices[i].x, 35 | Mesh.vertices[i].y, 36 | Mesh.vertices[i].z)); 37 | 38 | MeshData.Normals.Add(FVector( 39 | Mesh.normals[i].x, 40 | Mesh.normals[i].y, 41 | Mesh.normals[i].z)); 42 | } 43 | 44 | if (i < IndicesNum) 45 | { 46 | MeshData.Indices.Add(Mesh.triangles[i][0]); 47 | MeshData.Indices.Add(Mesh.triangles[i][1]); 48 | MeshData.Indices.Add(Mesh.triangles[i][2]); 49 | } 50 | 51 | if (UVNum && i < UVNum) 52 | { 53 | MeshData.UV0.Add(FVector2D(Mesh.uv[i][0], Mesh.uv[i][1])); 54 | } 55 | } 56 | } 57 | 58 | void USlMesh::UpdateMeshFromChunks(const TArray& ChunksIDs) 59 | { 60 | Mesh.updateMeshFromChunkList(sl::unreal::arrays::ToSlType(ChunksIDs)); 61 | } 62 | 63 | TArray USlMesh::GetVisibleChunks(const FTransform& ViewPoint) 64 | { 65 | return sl::unreal::arrays::ToUnrealType(Mesh.getVisibleList(sl::unreal::ToSlType(ViewPoint))); 66 | } 67 | 68 | TArray USlMesh::GetSurroundingChunks(const FTransform& ViewPoint, float Radius) 69 | { 70 | return sl::unreal::arrays::ToUnrealType(Mesh.getSurroundingList(sl::unreal::ToSlType(ViewPoint), Radius)); 71 | } 72 | 73 | bool USlMesh::Filter(const FSlMeshFilterParameters& MeshFilterParameters/* = FSlMeshFilterParameters()*/, bool bUpdateChunksOnly/* = false*/) 74 | { 75 | return Mesh.filter(sl::unreal::ToSlType(MeshFilterParameters), bUpdateChunksOnly); 76 | } 77 | 78 | bool USlMesh::ApplyTexture(ESlMeshTextureFormat TextureFormat/* = ESlMeshTextureFormat::MTF_RGBA*/, bool bSRGB/* = false*/) 79 | { 80 | bool bIsMeshTextured = Mesh.texture.isInit(); 81 | 82 | if (!bIsMeshTextured) 83 | { 84 | bIsMeshTextured = Mesh.applyTexture(sl::unreal::ToSlType(TextureFormat)); 85 | } 86 | 87 | if (!bIsMeshTextured) 88 | { 89 | return false; 90 | } 91 | 92 | // Texture data 93 | sl::Mat& MeshTexture = Mesh.texture; 94 | 95 | // Create texture 96 | UTexture2D* Texture = UTexture2D::CreateTransient(MeshTexture.getWidth(), MeshTexture.getHeight()); 97 | 98 | // Populate texture 99 | FTexture2DMipMap& Mip = Texture->PlatformData->Mips[0]; 100 | void* Data = Mip.BulkData.Lock(LOCK_READ_WRITE); 101 | FMemory::Memcpy(Data, MeshTexture.getPtr(sl::MEM::CPU), MeshTexture.getStepBytes(sl::MEM::CPU) * MeshTexture.getHeight()); 102 | Mip.BulkData.Unlock(); 103 | 104 | // Set texture settings 105 | #if WITH_EDITORONLY_DATA 106 | Texture->MipGenSettings = TextureMipGenSettings::TMGS_NoMipmaps; 107 | Texture->CompressionNone = true; 108 | Texture->CompressionNoAlpha = true; 109 | Texture->DeferCompression = false; 110 | #endif 111 | Texture->SRGB = bSRGB; 112 | Texture->CompressionSettings = TextureCompressionSettings::TC_VectorDisplacementmap; 113 | Texture->bNoTiling = true; 114 | Texture->bIsStreamable = false; 115 | Texture->Filter = TextureFilter::TF_Bilinear; 116 | Texture->AddressX = TextureAddress::TA_Clamp; 117 | Texture->AddressY = TextureAddress::TA_Clamp; 118 | Texture->LODGroup = TextureGroup::TEXTUREGROUP_World; 119 | 120 | if (IsInRenderingThread()) 121 | { 122 | Texture->UpdateResource(); 123 | } 124 | 125 | MeshData.Texture = Texture; 126 | 127 | return true; 128 | } 129 | 130 | void USlMesh::MergeChunks(int NumberOfFacesPerChunk) 131 | { 132 | Mesh.mergeChunks(NumberOfFacesPerChunk); 133 | } 134 | 135 | FVector USlMesh::GetGravityVector() 136 | { 137 | return sl::unreal::ToUnrealType(Mesh.getGravityEstimate()); 138 | } 139 | 140 | bool USlMesh::Save(const FString& FilePath, const TArray& ChunksIDs, ESlMeshFileFormat FileFormat/* = ESlMeshFileFormat::MFF_OBJ*/) 141 | { 142 | bool bSaved = Mesh.save(TCHAR_TO_UTF8(*FilePath), sl::unreal::ToSlType(FileFormat), sl::unreal::arrays::ToSlType(ChunksIDs)); 143 | 144 | return bSaved; 145 | } 146 | 147 | bool USlMesh::Load(const FString& FilePath, bool bUpdateChunksOnly/* = false*/) 148 | { 149 | return Mesh.load(TCHAR_TO_UTF8(*FilePath), bUpdateChunksOnly); 150 | } 151 | 152 | void USlMesh::Clear() 153 | { 154 | Mesh.clear(); 155 | MeshData.Clear(); 156 | } -------------------------------------------------------------------------------- /Stereolabs/Source/Stereolabs/Private/Stereolabs.cpp: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #include "StereolabsPrivatePCH.h" 4 | 5 | #define LOCTEXT_NAMESPACE "FStereolabs" 6 | 7 | #define SL_HANDLE_DEFINE(Name) void* ##Name##Handle = nullptr; 8 | #define SL_IMPORT(Name, Lib) { ##Name##Handle = FPlatformProcess::GetDllHandle(TEXT(Lib)); } 9 | #define SL_IMPORT_STRING(Name, Lib) { ##Name##Handle = FPlatformProcess::GetDllHandle(Lib); } 10 | #define SL_FREE(Name) FPlatformProcess::FreeDllHandle(##Name##Handle); 11 | 12 | SL_HANDLE_DEFINE(Core) 13 | SL_HANDLE_DEFINE(Inputs) 14 | SL_HANDLE_DEFINE(Zed) 15 | SL_HANDLE_DEFINE(Nvd3dumx) 16 | SL_HANDLE_DEFINE(MRCore) 17 | 18 | void FStereolabs::StartupModule() 19 | { 20 | // This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module 21 | SL_IMPORT(Zed, "sl_zed64.dll"); 22 | SL_IMPORT(Nvd3dumx, "nvd3dumx.dll"); 23 | 24 | #if WITH_EDITOR 25 | FString MixedRealityBinPath = FPaths::Combine(*FPaths::ConvertRelativePathToFull(*FPaths::ProjectPluginsDir()), TEXT("Stereolabs/Source/ThirdParty/MixedReality/bin/")); 26 | 27 | FString CoreFilePath = FPaths::Combine(*MixedRealityBinPath, TEXT("sl_mr_core64.dll")); 28 | SL_IMPORT_STRING(MRCore, *CoreFilePath); 29 | #else 30 | SL_IMPORT_STRING(MRCore, TEXT("sl_mr_core64.dll")); 31 | #endif 32 | } 33 | 34 | void FStereolabs::ShutdownModule() 35 | { 36 | // This function may be called during shutdown to clean up your module. For modules that support dynamic reloading, 37 | // we call this function before unloading the module. 38 | 39 | SL_FREE(Core); 40 | SL_FREE(Inputs); 41 | SL_FREE(Zed); 42 | SL_FREE(Nvd3dumx); 43 | SL_FREE(MRCore); 44 | } 45 | 46 | #undef LOCTEXT_NAMESPACE 47 | 48 | IMPLEMENT_MODULE(FStereolabs, Stereolabs) -------------------------------------------------------------------------------- /Stereolabs/Source/Stereolabs/Private/StereolabsPrivatePCH.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "Stereolabs.h" 6 | 7 | #include "Engine.h" 8 | #include "CoreUObject.h" 9 | #include "GameFramework/Actor.h" 10 | 11 | #include "Stereolabs/Public/Core/StereolabsCoreUtilities.h" -------------------------------------------------------------------------------- /Stereolabs/Source/Stereolabs/Private/Threading/StereolabsGrabRunnable.cpp: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #include "StereolabsPrivatePCH.h" 4 | #include "Stereolabs/Private/Threading/StereolabsGrabRunnable.h" 5 | #include "Stereolabs/Public/Core/StereolabsCoreGlobals.h" 6 | 7 | DEFINE_LOG_CATEGORY(SlGrabThread); 8 | 9 | bool FSlGrabRunnable::Init() 10 | { 11 | return FSlRunnable::Init(); 12 | } 13 | 14 | uint32 FSlGrabRunnable::Run() 15 | { 16 | FPlatformProcess::SleepNoStats(0.0f); 17 | 18 | while (bIsRunning) 19 | { 20 | GSlCameraProxy->Grab(); 21 | 22 | FPlatformProcess::SleepNoStats(0.001f); 23 | } 24 | 25 | return 0; 26 | } 27 | 28 | void FSlGrabRunnable::Stop() 29 | { 30 | FSlRunnable::Stop(); 31 | 32 | SL_LOG(SlGrabThread, "Thread stopped"); 33 | } 34 | 35 | void FSlGrabRunnable::Exit() 36 | { 37 | GSlIsGrabThreadIdInitialized = false; 38 | } 39 | 40 | void FSlGrabRunnable::Start(float Frequency) 41 | { 42 | static uint64 ThreadCounter = 0; 43 | 44 | Timer.SetFrequency(Frequency); 45 | 46 | FString ThreadName("SlGrabRunnable"); 47 | ThreadName.AppendInt(ThreadCounter++); 48 | 49 | Thread = FRunnableThread::Create(this, *ThreadName, 0, TPri_BelowNormal); 50 | GSlGrabThreadId = Thread->GetThreadID(); 51 | GSlIsGrabThreadIdInitialized = true; 52 | 53 | SL_LOG(SlGrabThread, "Thread started"); 54 | } -------------------------------------------------------------------------------- /Stereolabs/Source/Stereolabs/Private/Threading/StereolabsGrabRunnable.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "Stereolabs/Public/Threading/StereolabsRunnable.h" 6 | 7 | DECLARE_LOG_CATEGORY_EXTERN(SlGrabThread, Log, All); 8 | 9 | /* 10 | * Grab thread 11 | */ 12 | class FSlGrabRunnable : public FSlRunnable 13 | { 14 | public: 15 | virtual bool Init() override; 16 | virtual uint32 Run() override; 17 | virtual void Stop() override; 18 | virtual void Exit() override; 19 | virtual void Start(float Frequency) override; 20 | }; -------------------------------------------------------------------------------- /Stereolabs/Source/Stereolabs/Private/Threading/StereolabsMeasureRunnable.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "Stereolabs/Public/Threading/StereolabsRunnable.h" 6 | 7 | 8 | DECLARE_LOG_CATEGORY_EXTERN(SlMeasureThread, Log, All); 9 | 10 | struct FSlMeasureRunnableMatBuffer 11 | { 12 | FSlMeasureRunnableMatBuffer(); 13 | 14 | /** True if the buffer is free to use */ 15 | bool bIsFree; 16 | 17 | /** True if the buffer is updated */ 18 | bool bIsUpdated; 19 | 20 | /** True if depth enabled for this buffer */ 21 | bool bDepthEnabled; 22 | 23 | /** True if normals enabled for this buffer */ 24 | bool bNormalsEnabled; 25 | 26 | /** Current mats used by the buffer */ 27 | TArray> Mats; 28 | }; 29 | 30 | /* 31 | * Retrieve thread which should be at least twice as fast as grab thread 32 | */ 33 | class FSlMeasureRunnable : public FSlRunnable 34 | { 35 | public: 36 | FSlMeasureRunnable(); 37 | 38 | public: 39 | virtual bool Init() override; 40 | virtual uint32 Run() override; 41 | virtual void Stop() override; 42 | virtual void Exit() override; 43 | virtual void Start(float Frequency) override; 44 | 45 | /* 46 | * Toggle depth and normals 47 | * @param bEnableDepth True to enable depth retrieve 48 | * @param bEnableNormals True to enable normals retrieve 49 | */ 50 | void SetDepthAndNormals(bool bEnableDepth, bool bEnableNormals); 51 | 52 | /* 53 | * @param ScreenPosition The screen position 54 | * @param ViewportSizeX The viewport size width 55 | * @param ViewportSizeY The viewport size height 56 | * @return The depth at the screen position 57 | */ 58 | float GetDepth(const FIntPoint& ScreenPosition, const FVector2D& InputRangeX, const FVector2D& InputRangeY); 59 | 60 | /* 61 | * @param ScreenPositions The screen positions 62 | * @param ViewportSizeX The viewport size width 63 | * @param ViewportSizeY The viewport size height 64 | * @return The depths at the screen positions 65 | */ 66 | TArray GetDepths(const TArray& ScreenPositions, const FVector2D& InputRangeX, const FVector2D& InputRangeY); 67 | 68 | /* 69 | * @param ScreenPosition The screen position 70 | * @param ViewportSizeX The viewport size width 71 | * @param ViewportSizeY The viewport size height 72 | * @return The normal at the screen position 73 | */ 74 | FVector GetNormal(const FIntPoint& ScreenPosition, const FVector2D& InputRangeX, const FVector2D& InputRangeY); 75 | 76 | /* 77 | * @param ScreenPositions The screen positions 78 | * @param ViewportSizeX The viewport size width 79 | * @param ViewportSizeY The viewport size height 80 | * @return The normals at the screen positions 81 | */ 82 | TArray GetNormals(const TArray& ScreenPositions, const FVector2D& InputRangeX, const FVector2D& InputRangeY); 83 | 84 | /* 85 | * @param ScreenPosition The screen position 86 | * @param ViewportSizeX The viewport size width 87 | * @param ViewportSizeY The viewport size height 88 | * @return The depth and normal at the screen position 89 | */ 90 | FVector4 GetDepthAndNormal(const FIntPoint& ScreenPosition, const FVector2D& InputRangeX, const FVector2D& InputRangeY); 91 | 92 | /* 93 | * @param ScreenPositions The screen positions 94 | * @param ViewportSizeX The viewport size width 95 | * @param ViewportSizeY The viewport size height 96 | * @return The depths and normals at the screen positions 97 | */ 98 | TArray GetDepthsAndNormals(const TArray& ScreenPositions, const FVector2D& InputRangeX, const FVector2D& InputRangeY); 99 | 100 | private: 101 | /* 102 | * Grab delegate callback 103 | * @param ErrorCode Grab error code 104 | */ 105 | void GrabCallback(ESlErrorCode ErrorCode); 106 | 107 | private: 108 | /** True if depth retrieve enabled */ 109 | FThreadSafeBool bDepthEnabled; 110 | 111 | /** True if normals retrieve enabled */ 112 | FThreadSafeBool bNormalsEnabled; 113 | 114 | /** Pool of mats */ 115 | TArray> BuffersPool; 116 | 117 | /** Current used buffer */ 118 | FSlMeasureRunnableMatBuffer* Buffer; 119 | 120 | /** Update Section */ 121 | FCriticalSection UpdateSection; 122 | 123 | /** Depth Section */ 124 | FCriticalSection GetSection; 125 | 126 | /** Handle to remove callback from delegate */ 127 | FDelegateHandle GrabDelegateHandle; 128 | 129 | /** Range [0, mats width] */ 130 | FVector2D OutputRangeX; 131 | 132 | /** Range [0, mats height] */ 133 | FVector2D OutputRangeY; 134 | }; 135 | -------------------------------------------------------------------------------- /Stereolabs/Source/Stereolabs/Private/Threading/StereolabsRunnable.cpp: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #include "StereolabsPrivatePCH.h" 4 | 5 | #include "Stereolabs/Public/Threading/StereolabsRunnable.h" 6 | 7 | FSlRunnable::FSlRunnable() 8 | : 9 | Thread(nullptr), 10 | bIsRunning(false), 11 | bIsPaused(false), 12 | bIsSleeping(false) 13 | { 14 | } 15 | 16 | FSlRunnable::~FSlRunnable() 17 | { 18 | delete Thread; 19 | Thread = nullptr; 20 | } -------------------------------------------------------------------------------- /Stereolabs/Source/Stereolabs/Private/Utilities/StereolabsViewportHelper.cpp: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #include "StereolabsPrivatePCH.h" 4 | #include "Stereolabs/Public/Utilities/StereolabsViewportHelper.h" 5 | #include "Stereolabs/Public/Core/StereolabsCameraProxy.h" 6 | #include "HeadMountedDisplayFunctionLibrary.h" 7 | 8 | FSlViewportHelper::FSlViewportHelper() 9 | : 10 | ScreenRatio(0.0f), 11 | GameViewportClient(nullptr) 12 | { 13 | } 14 | 15 | void FSlViewportHelper::AddToViewportResizeEvent(UGameViewportClient* NewGameViewportClient) 16 | { 17 | // Already init 18 | if (GameViewportClient) 19 | { 20 | return; 21 | } 22 | 23 | GameViewportClient = NewGameViewportClient; 24 | 25 | ViewportResizedEventHandle = FViewport::ViewportResizedEvent.AddLambda([this](FViewport* Viewport, uint32) 26 | { 27 | if (Viewport->GetClient() == GameViewportClient) 28 | { 29 | Update(Viewport->GetSizeXY()); 30 | } 31 | }); 32 | } 33 | 34 | void FSlViewportHelper::Update(const FIntPoint& ViewportSize) 35 | { 36 | FIntPoint Resolution = GSlCameraProxy->CameraInformation.CalibrationParameters.LeftCameraParameters.Resolution; 37 | 38 | if (UHeadMountedDisplayFunctionLibrary::IsHeadMountedDisplayEnabled()) 39 | { 40 | if (Size == Resolution) 41 | { 42 | return; 43 | } 44 | 45 | Size = Resolution; 46 | 47 | Offset.X = 0.0f; 48 | Offset.Y = 0.0f; 49 | } 50 | else 51 | { 52 | // No update needed 53 | if (Size == ViewportSize) 54 | { 55 | return; 56 | } 57 | 58 | //Update 59 | Size = ViewportSize; 60 | 61 | ScreenRatio = (float)Size.X / (float)Size.Y; 62 | float ImageRatio = (float)Resolution.X / (float)Resolution.Y; 63 | 64 | // Not 16/9 65 | if (ScreenRatio < ImageRatio) 66 | { 67 | Offset.X = 0.0f; 68 | Offset.Y = (Size.Y - (Size.X / ImageRatio)) / 2; 69 | } 70 | else if (ScreenRatio > ImageRatio) 71 | { 72 | Offset.X = (Size.X - (Size.Y * ImageRatio)) / 2; 73 | Offset.Y = 0.0f; 74 | } 75 | else 76 | { 77 | Offset.X = 0.0f; 78 | Offset.Y = 0.0f; 79 | } 80 | } 81 | 82 | RangeX.X = Offset.X; 83 | RangeX.Y = Size.X - Offset.X; 84 | 85 | RangeY.X = Offset.Y; 86 | RangeY.Y = Size.Y - Offset.Y; 87 | } -------------------------------------------------------------------------------- /Stereolabs/Source/Stereolabs/Public/Core/StereolabsCoreUtilities.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "ScopeTryLock.h" 6 | 7 | #define SL_SCOPE_LOCK(LockName, CriticalSection)\ 8 | {\ 9 | FScopeLock LockName(&CriticalSection); 10 | 11 | #define SL_SCOPE_UNLOCK\ 12 | }\ 13 | 14 | #define SL_SCOPE_TRY_LOCK(LockName, CriticalSection)\ 15 | {\ 16 | FScopeTryLock LockName(&CriticalSection);\ 17 | if(LockName.IsLocked())\ 18 | {\ 19 | 20 | #define SL_SCOPE_TRY_UNLOCK\ 21 | }\ 22 | }\ 23 | 24 | #if WITH_EDITOR 25 | /* 26 | * Log 27 | */ 28 | #define SL_LOG(LogCategory, Format, ...) \ 29 | { \ 30 | SET_WARN_COLOR(COLOR_CYAN);\ 31 | const FString Msg = FString::Printf(TEXT(Format), ##__VA_ARGS__); \ 32 | UE_LOG(LogCategory, Log, TEXT("%s"), *Msg);\ 33 | CLEAR_WARN_COLOR();\ 34 | } 35 | 36 | /* 37 | * Warning 38 | */ 39 | #define SL_LOG_W(LogCategory, Format, ...) \ 40 | { \ 41 | SET_WARN_COLOR(COLOR_CYAN);\ 42 | const FString Msg = FString::Printf(TEXT(Format), ##__VA_ARGS__); \ 43 | UE_LOG(LogCategory, Warning, TEXT("%s"), *Msg);\ 44 | CLEAR_WARN_COLOR();\ 45 | } 46 | 47 | /* 48 | * Error 49 | */ 50 | #define SL_LOG_E(LogCategory, Format, ...) \ 51 | { \ 52 | SET_WARN_COLOR(COLOR_CYAN);\ 53 | const FString Msg = FString::Printf(TEXT(Format), ##__VA_ARGS__); \ 54 | UE_LOG(LogCategory, Error, TEXT("%s"), *Msg);\ 55 | CLEAR_WARN_COLOR();\ 56 | } 57 | 58 | /* 59 | * Fatal 60 | */ 61 | #define SL_LOG_F(LogCategory, Format, ...) \ 62 | { \ 63 | SET_WARN_COLOR(COLOR_CYAN);\ 64 | const FString Msg = FString::Printf(TEXT(Format), ##__VA_ARGS__); \ 65 | UE_LOG(LogCategory, Fatal, TEXT("%s"), *Msg);\ 66 | CLEAR_WARN_COLOR();\ 67 | } 68 | #else 69 | #define SL_LOG(LogCategory, Format, ...) 70 | #define SL_LOG_W(LogCategory, Format, ...) 71 | #define SL_LOG_E(LogCategory, Format, ...) 72 | #define SL_LOG_F(LogCategory, Format, ...) 73 | #endif 74 | 75 | DECLARE_STATS_GROUP(TEXT("ZED"), STATGROUP_ZED, STATCAT_Advanced); -------------------------------------------------------------------------------- /Stereolabs/Source/Stereolabs/Public/Core/StereolabsMesh.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "Stereolabs/Public/Core/StereolabsBaseTypes.h" 6 | 7 | #include 8 | 9 | #include "StereolabsMesh.generated.h" 10 | 11 | UCLASS(Category = "Stereolabs|Texture") 12 | class STEREOLABS_API USlMesh : public UObject 13 | { 14 | GENERATED_BODY() 15 | 16 | public: 17 | USlMesh(); 18 | 19 | /* 20 | * Updates the mesh data from underlying mesh. 21 | * Call this function after UpdateMeshFromChunks, Load, Filter, ApplyTexture 22 | */ 23 | UFUNCTION(BlueprintCallable, Category = "Stereolabs") 24 | void UpdateMeshData(); 25 | 26 | /* 27 | * Updates vertices, normals, triangles, UVs from chunks' data pointed by the given chunk IDs array. 28 | * @param ChunksIDs The index of chunks which will be concatenated. 29 | * 30 | * If the given ChunksIDs is empty, all chunks will be used to update the current Mesh. 31 | */ 32 | UFUNCTION(BlueprintCallable, meta = (AutoCreateRefTerm = "ChunksIDs"), Category = "Stereolabs") 33 | void UpdateMeshFromChunks(const TArray& ChunksIDs); 34 | 35 | /* 36 | * Computes the list of visible chunk from a specific point of view 37 | * @param ViewPoint The point of view 38 | * @return The list of visible chunks. 39 | */ 40 | UFUNCTION(BlueprintPure, Category = "Stereolabs") 41 | TArray GetVisibleChunks(const FTransform& ViewPoint); 42 | 43 | /* 44 | * Computes the list of chunks which are close to a specific point of view. 45 | * @param ViewPoint The point of view 46 | * @param Radius The radius in ESlUNIT 47 | * @return The list of chunks close to the given point. 48 | */ 49 | UFUNCTION(BlueprintPure, Category = "Stereolabs") 50 | TArray GetSurroundingChunks(const FTransform& ViewPoint, float Radius); 51 | 52 | /* 53 | * Filters the mesh. 54 | * 55 | * The resulting mesh in smoothed, small holes are filled and small blobs of non connected triangles are deleted. 56 | * 57 | * @param MeshFilterParameters The filtering parameters 58 | * @param bUpdateChunksOnly If set to false the mesh data (vertices/normals/triangles) are updated otherwise only the chunks data are updated. default : false. * @return True if the filtering was successful, false otherwise. 59 | * 60 | * The filtering is a costly operation, its not recommended to call it every time you retrieve a mesh but at the end of your spatial mapping process. 61 | */ 62 | UFUNCTION(BlueprintCallable, meta = (AutoCreateRefTerm = "MeshFilterParameters"), Category = "Stereolabs") 63 | bool Filter(const FSlMeshFilterParameters& MeshFilterParameters, bool bUpdateChunksOnly = false); 64 | 65 | /* 66 | * Applies texture to the mesh. 67 | * 68 | * By using this function you will get access to UV0 and Texture. 69 | * The number of triangles in the mesh may slightly differ before and after calling this functions due to missing texture informations. 70 | * There is only one texture for the mesh, the uv of each chunks are expressed for it in its globality. 71 | * Vectors of vertices/normals and uv have now the same size. 72 | * 73 | * @param TextureFormat The number of channel desired for the computed texture 74 | * @param bSRGB True if texture must be SRGB, usefull if you want to create a cubemap from the mesh 75 | * @return True if the texturing was successful, false otherwise. 76 | * 77 | * This function can be call as long as you do not start a new spatial mapping process, due to shared memory. 78 | * This function can require a lot of computation time depending on the number of triangles in the mesh. Its recommended to call it once a the end of your spatial mapping process. 79 | * 80 | * The bSaveTexture parameter in FSlSpatialMappingParameters must be set as true when enabling the spatial mapping to be able to apply the textures. 81 | * The mesh should be filtered before calling this function since filter will erased the textures, the texturing is also significantly slower on non-filtered meshes. 82 | * 83 | * If not called in the render thread you must call MeshData.Texture->UpdateResource() 84 | */ 85 | UFUNCTION(BlueprintCallable, Category = "Stereolabs") 86 | bool ApplyTexture(ESlMeshTextureFormat TextureFormat = ESlMeshTextureFormat::MTF_RGBA, bool bSRGB = false); 87 | 88 | /* 89 | * Merges currents chunks. 90 | * 91 | * This can be use to merge chunks into bigger set to improve rendering process. 92 | * 93 | * @param NumberOfFacesPerChunk The new number of faces per chunk (useful for Unity which required chunk of size smaller than 65k). 94 | * 95 | * You should not use this function during spatial mapping process because mesh updates will revert this changes. 96 | */ 97 | UFUNCTION(BlueprintCallable, Category = "Stereolabs") 98 | void MergeChunks(int NumberOfFacesPerChunk); 99 | 100 | /* 101 | * Estimates the gravity vector. 102 | * This function looks for a dominant plane in the whole mesh considering that it is the floor (or an horizontal plane). 103 | * This can be use to find the gravity and then create realistic physical interactions. 104 | * 105 | * @return The gravity vector. 106 | */ 107 | UFUNCTION(BlueprintPure, Category = "Stereolabs") 108 | FVector GetGravityVector(); 109 | 110 | /* 111 | * Saves the current Mesh into a file. 112 | * @param FilePath the path and filename of the mesh 113 | * @param ChunksIDs Specify a set of chunks to be saved, if none provided alls chunks are saved 114 | * @param FileFormat The file type (extension). default : MESH_FILE_OBJ. 115 | * @return True if the file was successfully saved, false otherwise. 116 | * 117 | * Only ESlMeshFileFormat::MFF_OBJ support textures data. 118 | * This function operate on the Mesh not on the chunks. This way you can save different parts of your Mesh (update your Mesh with UpdateMeshFromChunks). 119 | */ 120 | UFUNCTION(BlueprintCallable, meta = (AutoCreateRefTerm = "ChunksIDs"), Category = "Stereolabs") 121 | bool Save(const FString& FilePath, const TArray& ChunksIDs, ESlMeshFileFormat FileFormat = ESlMeshFileFormat::MFF_OBJ); 122 | 123 | /* 124 | * Loads the mesh from a file. 125 | * @param FilePath The path and filename of the mesh (do not forget the extension). 126 | * @param bUpdateChunksOnly If set to false the mesh data (vertices/normals/triangles) are updated otherwise only the chunks data are updated. default : false. 127 | * @return True if the loading was successful, false otherwise. 128 | */ 129 | UFUNCTION(BlueprintCallable, Category = "Stereolabs") 130 | bool Load(const FString& FilePath, bool bUpdateChunksOnly = false); 131 | 132 | /* 133 | * Clears all the data. 134 | */ 135 | UFUNCTION(BlueprintCallable, Category="Stereolabs") 136 | void Clear(); 137 | 138 | public: 139 | /** Mesh data (indices, vertices, normals, UV0, texture) */ 140 | FSlMeshData MeshData; 141 | 142 | /** Underlying sl mesh */ 143 | sl::Mesh Mesh; 144 | }; -------------------------------------------------------------------------------- /Stereolabs/Source/Stereolabs/Public/Core/StereolabsTextureBatch.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "Stereolabs/Public/Core/StereolabsCoreGlobals.h" 6 | #include "Stereolabs/Public/Core/StereolabsTexture.h" 7 | 8 | #include "StereolabsTextureBatch.generated.h" 9 | 10 | DECLARE_LOG_CATEGORY_EXTERN(SlTextureBatch, Log, All); 11 | 12 | #define TB_BUFFERS_POOL_SIZE 2 13 | 14 | struct FSlTextueBatchMatBuffer 15 | { 16 | FSlTextueBatchMatBuffer(); 17 | ~FSlTextueBatchMatBuffer(); 18 | 19 | /** Timestamp of the buffer */ 20 | sl::Timestamp Timestamp; 21 | 22 | /** True if the buffer is free to use */ 23 | bool bIsFree; 24 | 25 | /** True if the buffer is updated */ 26 | bool bIsUpdated; 27 | 28 | /** Current mats used by the buffer */ 29 | TArray Mats; 30 | }; 31 | 32 | /* 33 | * A batch that retrieve and update textures. 34 | */ 35 | UCLASS(BlueprintType, Category = "Stereolabs|Texture") 36 | class STEREOLABS_API USlTextureBatch : public UObject 37 | { 38 | GENERATED_BODY() 39 | 40 | public: 41 | USlTextureBatch(); 42 | 43 | virtual void BeginDestroy() override; 44 | 45 | /* 46 | * Retrieve the textures. Called inside the grab thread. 47 | * @param ImageTimestamp The Zed image timestamp 48 | */ 49 | UFUNCTION(BlueprintCallable, Category = "Stereolabs|Texture") 50 | void RetrieveCurrentFrame(const FSlTimestamp& ImageTimestamp); 51 | 52 | /* 53 | * Tick the batch. Update the textures. 54 | * @return Single thread : Always return true. 55 | * Multi thread : True if textures updated. 56 | */ 57 | UFUNCTION(BlueprintCallable, Category = "Stereolabs|Texture") 58 | virtual bool Tick(); 59 | 60 | /* 61 | * Add a texture 62 | * @param Texture The texture to add 63 | */ 64 | UFUNCTION(BlueprintCallable, Category = "Stereolabs|Texture") 65 | virtual void AddTexture(USlTexture* Texture); 66 | 67 | /* 68 | * Remove a texture 69 | * @param Texture The texture to remove 70 | */ 71 | UFUNCTION(BlueprintCallable, Category = "Stereolabs|Texture") 72 | virtual void RemoveTexture(USlTexture* Texture); 73 | 74 | /* 75 | * Remove all textures 76 | */ 77 | UFUNCTION(BlueprintCallable, Category = "Stereolabs") 78 | virtual void Clear(); 79 | 80 | protected: 81 | /* 82 | * Enable/Disable async retrieve 83 | * @param bEnabled True to enable 84 | */ 85 | UFUNCTION() 86 | virtual void SetAsyncRetrieveEnabled(bool bEnabled); 87 | 88 | /* 89 | * Create a batch 90 | * @param Name The new name of the batch 91 | * @param Type The type of batch 92 | */ 93 | static USlTextureBatch* CreateTextureBatch(const FName& Name, ESlMemoryType Type); 94 | 95 | public: 96 | /** Name of the batch */ 97 | FName Name; 98 | 99 | protected: 100 | /** Pool of textures */ 101 | TArray TexturesPool; 102 | 103 | /** Buffers for async retrieve */ 104 | TArray> BuffersPool; 105 | 106 | /** Section to synchronize with buffers */ 107 | FCriticalSection BuffersSection; 108 | 109 | /** Section to synchronize with retrieves */ 110 | FCriticalSection RetrieveSection; 111 | 112 | /** Section to synchronize with mat swaping */ 113 | FCriticalSection SwapSection; 114 | 115 | /** True if the batch will retrieve in grab thread. Set to true before calling RetrieveCurrentFrame(). */ 116 | FThreadSafeBool bAsyncRetrieveEnabled; 117 | 118 | /** Buffers for double buffering in async retrieve */ 119 | FSlTextueBatchMatBuffer* Buffers[2]; 120 | 121 | /** Current frame timestamp*/ 122 | FSlTimestamp CurrentFrameTimestamp; 123 | 124 | /** The minimal size of the batch */ 125 | int32 MinSize; 126 | 127 | private: 128 | /** True to automatically add this batch to the OnGrabThreadEnabled delegate */ 129 | bool bIsAutoAddToGrabDelegate; 130 | }; 131 | 132 | 133 | /* 134 | * Batch for GPU textures with Texture2D 135 | */ 136 | UCLASS(BlueprintType, Category = "Stereolabs|Texture") 137 | class STEREOLABS_API USlGPUTextureBatch : public USlTextureBatch 138 | { 139 | GENERATED_BODY() 140 | 141 | public: 142 | /* 143 | * Create a GPU batch 144 | * @param Name The new name of the batch 145 | * @return The batch 146 | */ 147 | UFUNCTION(BlueprintCallable, Category = "Stereolabs|Texture") 148 | static USlGPUTextureBatch* CreateGPUTextureBatch(const FName& Name) 149 | { 150 | return static_cast(USlTextureBatch::CreateTextureBatch(Name, ESlMemoryType::MT_GPU)); 151 | } 152 | 153 | /* 154 | * Tick the batch. Update the textures. 155 | * @return Single thread : Always return true. 156 | * Multi thread : True if render command enqueued. 157 | */ 158 | virtual bool Tick() override; 159 | 160 | /* 161 | * Add a texture 162 | * @param Texture The texture to add 163 | */ 164 | virtual void AddTexture(USlTexture* Texture) override; 165 | 166 | /* 167 | * Remove a texture. Sync with render thread. 168 | * @param Texture The texture to remove 169 | */ 170 | virtual void RemoveTexture(USlTexture* Texture) override; 171 | 172 | /* 173 | * Remove all textures. Sync with render thread. 174 | */ 175 | virtual void Clear() override; 176 | 177 | private: 178 | /* 179 | * Enable/Disable async retrieve 180 | * @param bEnabled True to enable 181 | */ 182 | virtual void SetAsyncRetrieveEnabled(bool bEnabled) override; 183 | 184 | private: 185 | /** Pool of CUDA resources associated with textures */ 186 | TArray CudaResourcesPool; 187 | }; 188 | 189 | /* 190 | * Batch for GPU textures without Texture2D 191 | */ 192 | UCLASS(BlueprintType, Category = "Stereolabs|Texture") 193 | class STEREOLABS_API USlSimpleGPUTextureBatch : public USlTextureBatch 194 | { 195 | GENERATED_BODY() 196 | 197 | public: 198 | /* 199 | * Create a GPU batch 200 | * @param Name The new name of the batch 201 | * @return The batch 202 | */ 203 | UFUNCTION(BlueprintCallable, Category = "Stereolabs|Texture") 204 | static USlSimpleGPUTextureBatch* CreateSimpleGPUTextureBatch(const FName& Name) 205 | { 206 | return static_cast(USlTextureBatch::CreateTextureBatch(Name, ESlMemoryType::MT_GPU)); 207 | } 208 | 209 | /* 210 | * Add a texture 211 | * @param Texture The texture to add 212 | */ 213 | virtual void AddTexture(USlTexture* Texture) override; 214 | }; 215 | 216 | /* 217 | * Batch for CPU textures 218 | */ 219 | UCLASS(BlueprintType, Category = "Stereolabs|Texture") 220 | class STEREOLABS_API USlCPUTextureBatch : public USlTextureBatch 221 | { 222 | GENERATED_BODY() 223 | 224 | public: 225 | /* 226 | * Create a CPU batch 227 | * @param Name The new name of the batch 228 | * @return The batch 229 | */ 230 | UFUNCTION(BlueprintCallable, Category = "Stereolabs|Texture") 231 | static USlCPUTextureBatch* CreateCPUTextureBatch(const FName& Name) 232 | { 233 | return static_cast(USlTextureBatch::CreateTextureBatch(Name, ESlMemoryType::MT_CPU)); 234 | } 235 | 236 | /* 237 | * Add a texture 238 | * @param Texture The texture to add 239 | */ 240 | virtual void AddTexture(USlTexture* Texture) override; 241 | }; -------------------------------------------------------------------------------- /Stereolabs/Source/Stereolabs/Public/Stereolabs.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "ModuleManager.h" 6 | 7 | class FStereolabs : public IModuleInterface 8 | { 9 | public: 10 | /** IModuleInterface implementation */ 11 | virtual void StartupModule() override; 12 | virtual void ShutdownModule() override; 13 | }; -------------------------------------------------------------------------------- /Stereolabs/Source/Stereolabs/Public/Threading/StereolabsRunnable.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "Stereolabs/Public/Utilities/StereolabsTimer.h" 6 | 7 | #include "ThreadingBase.h" 8 | 9 | /* 10 | * Base class for runnables allowing to start/pause/resume/stop a thread 11 | */ 12 | class STEREOLABS_API FSlRunnable : public FRunnable 13 | { 14 | public: 15 | FSlRunnable(); 16 | virtual ~FSlRunnable(); 17 | 18 | /* 19 | * Start the thread 20 | * @param Frequency The Frequency of the thread in seconds 21 | */ 22 | virtual void Start(float Frequency) { } 23 | 24 | virtual bool Init() override 25 | { 26 | bIsRunning = true; 27 | 28 | return true; 29 | } 30 | 31 | virtual void Stop() override 32 | { 33 | bIsRunning = false; 34 | } 35 | 36 | FORCEINLINE void EnsureCompletion() 37 | { 38 | if(!Thread) 39 | { 40 | return; 41 | } 42 | 43 | // Stop if running 44 | if (bIsRunning) 45 | { 46 | Stop(); 47 | } 48 | 49 | // Awake if sleeping 50 | if (bIsSleeping) 51 | { 52 | Awake(); 53 | } 54 | 55 | // Resume if paused 56 | if (bIsPaused) 57 | { 58 | Suspend(false); 59 | } 60 | 61 | Thread->WaitForCompletion(); 62 | } 63 | 64 | /* 65 | * Pause/Resume the thread 66 | * @param bShouldPause True to pause the thread, false to resume 67 | */ 68 | FORCEINLINE void Suspend(bool bShouldPause = true) 69 | { 70 | Thread->Suspend(bShouldPause); 71 | bIsPaused = bShouldPause; 72 | } 73 | 74 | /* 75 | * Set the thread to sleep 76 | */ 77 | FORCEINLINE void Sleep() 78 | { 79 | bIsSleeping = true; 80 | } 81 | 82 | /* 83 | * Awake the thread 84 | */ 85 | FORCEINLINE void Awake() 86 | { 87 | bIsSleeping = false; 88 | } 89 | 90 | /* 91 | * @return True if the thread is running 92 | */ 93 | FORCEINLINE bool IsRunning() 94 | { 95 | return bIsRunning; 96 | } 97 | 98 | /* 99 | * @return True if the thread is paused 100 | */ 101 | FORCEINLINE bool IsPaused() 102 | { 103 | return bIsPaused; 104 | } 105 | 106 | /* 107 | * @return True if the thread is sleeping 108 | */ 109 | FORCEINLINE bool IsSleeping() 110 | { 111 | return bIsSleeping; 112 | } 113 | 114 | public: 115 | /** Current thread running the runnable */ 116 | FRunnableThread* Thread; 117 | 118 | protected: 119 | /** A timer for this runnable */ 120 | FSlTimer Timer; 121 | 122 | /** True if the thread is running */ 123 | bool bIsRunning; 124 | 125 | /** True if the thread is paused */ 126 | bool bIsPaused; 127 | 128 | /** True if the thread is sleeping */ 129 | bool bIsSleeping; 130 | }; -------------------------------------------------------------------------------- /Stereolabs/Source/Stereolabs/Public/Utilities/StereolabsCriticalSection.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "Stereolabs/Public/Core/StereolabsCoreGlobals.h" 6 | 7 | #include "StereolabsCriticalSection.generated.h" 8 | 9 | /* 10 | * Critical section in blueprint 11 | */ 12 | UCLASS(BlueprintType, Category = "Stereolabs") 13 | class STEREOLABS_API USlCriticalSection : public UObject 14 | { 15 | GENERATED_BODY() 16 | 17 | public: 18 | virtual void BeginDestroy() override 19 | { 20 | Unlock(); 21 | 22 | Super::BeginDestroy(); 23 | } 24 | 25 | public: 26 | UFUNCTION(BlueprintCallable, Category = "Stereolabs|Critical Section") 27 | static USlCriticalSection* CreateCriticalSection() 28 | { 29 | return NewObject(); 30 | } 31 | 32 | /* 33 | * Lock the section 34 | */ 35 | UFUNCTION(BlueprintCallable) 36 | void Lock() 37 | { 38 | CriticalSection.Lock(); 39 | bIsLocked = true; 40 | } 41 | 42 | /* 43 | * Try to lock the section 44 | * @return True if locked 45 | */ 46 | UFUNCTION(BlueprintCallable) 47 | bool TryLock() 48 | { 49 | bIsLocked = CriticalSection.TryLock(); 50 | return bIsLocked; 51 | } 52 | 53 | /* 54 | * Unlock the section 55 | */ 56 | UFUNCTION(BlueprintCallable) 57 | void Unlock() 58 | { 59 | CriticalSection.Unlock(); 60 | bIsLocked = false; 61 | } 62 | 63 | /* 64 | * @return True if locked 65 | */ 66 | UFUNCTION(BlueprintCallable) 67 | bool IsLocked() 68 | { 69 | return bIsLocked; 70 | } 71 | 72 | private: 73 | /** Underlying critical section */ 74 | FCriticalSection CriticalSection; 75 | 76 | /** True if locked */ 77 | FThreadSafeBool bIsLocked; 78 | }; -------------------------------------------------------------------------------- /Stereolabs/Source/Stereolabs/Public/Utilities/StereolabsTimer.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | /* 5 | * A timer to measure threads loop time and get sleep time 6 | */ 7 | struct STEREOLABS_API FSlTimer 8 | { 9 | public: 10 | FSlTimer() 11 | : 12 | CycleTime(0.0), 13 | ExecTime(0.0), 14 | StartTime(0.0) 15 | { 16 | } 17 | 18 | /* 19 | * Set the frequency 20 | * @param Frequency The frequency in seconds 21 | */ 22 | FORCEINLINE void SetFrequency(double Frequency) 23 | { 24 | CycleTime = 1.0 / Frequency * 1000.0; 25 | } 26 | 27 | /* 28 | * Start the timer 29 | */ 30 | FORCEINLINE void Start() 31 | { 32 | StartTime = FDateTime::Now().GetTimeOfDay().GetTotalMilliseconds(); 33 | } 34 | 35 | /* 36 | * Stop the timer 37 | */ 38 | FORCEINLINE void Stop() 39 | { 40 | double StopTime = FDateTime::Now().GetTimeOfDay().GetTotalMilliseconds(); 41 | ExecTime = StopTime - StartTime; 42 | } 43 | 44 | /* 45 | * @return True if the timer stopped before one full cycle 46 | */ 47 | FORCEINLINE bool CanSleep() const 48 | { 49 | return (ExecTime < CycleTime); 50 | } 51 | 52 | /* 53 | * @return The time needed to finish the cycle 54 | */ 55 | FORCEINLINE float GetSleepingTimeSeconds() const 56 | { 57 | return (CycleTime - ExecTime) / 1000.0f; 58 | } 59 | 60 | private: 61 | /** Maximum time in milliseconds */ 62 | double CycleTime; 63 | 64 | /** Execution time in milliseconds */ 65 | double ExecTime; 66 | 67 | /** Start time in milliseconds */ 68 | double StartTime; 69 | }; -------------------------------------------------------------------------------- /Stereolabs/Source/Stereolabs/Public/Utilities/StereolabsViewportHelper.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "StereolabsViewportHelper.generated.h" 6 | 7 | /* 8 | * Helper class to cache viewport data 9 | * 10 | * Example : 11 | * 12 | * UGameViewportClient* GameViewport = GetLocalPlayer()->ViewportClient; 13 | * check(GameViewport); 14 | * 15 | * if (!UHeadMountedDisplayFunctionLibrary::IsHeadMountedDisplayEnabled()) 16 | * { 17 | * ViewportHelper.AddToViewportResizeEvent(GameViewport); 18 | * } 19 | * 20 | * ViewportHelper.Update(GameViewport->Viewport->GetSizeXY()); 21 | * 22 | */ 23 | USTRUCT(BlueprintType) 24 | struct STEREOLABS_API FSlViewportHelper 25 | { 26 | GENERATED_BODY() 27 | 28 | public: 29 | FSlViewportHelper(); 30 | 31 | /** Add to viewport resize event to automatically update */ 32 | void AddToViewportResizeEvent(class UGameViewportClient* NewGameViewportClient); 33 | 34 | /** Update cache */ 35 | void Update(const FIntPoint& ViewportSize = FIntPoint()); 36 | 37 | /** Return true if in viewport */ 38 | FORCEINLINE bool IsInViewport(int32 X, int32 Y) 39 | { 40 | return (X >= RangeX.X && Y >= RangeY.X && X <= RangeX.Y && Y <= RangeY.Y); 41 | } 42 | 43 | public: 44 | /** X/Y offsets if ratio is not 16/9 */ 45 | FVector2D Offset; 46 | 47 | /** Range to scale width */ 48 | FVector2D RangeX; 49 | 50 | /** Range to scale height */ 51 | FVector2D RangeY; 52 | 53 | /** Current size */ 54 | FIntPoint Size; 55 | 56 | /** Current screen ratio */ 57 | float ScreenRatio; 58 | 59 | private: 60 | /** Viewport resize event handler */ 61 | FDelegateHandle ViewportResizedEventHandle; 62 | 63 | /** Current game viewport rendering the game */ 64 | UGameViewportClient* GameViewportClient; 65 | }; 66 | -------------------------------------------------------------------------------- /Stereolabs/Source/Stereolabs/Stereolabs.Build.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | using UnrealBuildTool; 4 | using System.IO; 5 | using System; 6 | 7 | public class Stereolabs : ModuleRules 8 | { 9 | private string ModulePath 10 | { 11 | get { return ModuleDirectory; } 12 | } 13 | 14 | public Stereolabs(ReadOnlyTargetRules Target) : base(Target) 15 | { 16 | PrivatePCHHeaderFile = "Stereolabs/Public/Stereolabs.h"; 17 | 18 | string CudaSDKPath = System.Environment.GetEnvironmentVariable("CUDA_PATH_V9_0", EnvironmentVariableTarget.Machine); 19 | if (!Directory.Exists(CudaSDKPath)) 20 | CudaSDKPath = System.Environment.GetEnvironmentVariable("CUDA_PATH_V10_0", EnvironmentVariableTarget.Machine); 21 | if (!Directory.Exists(CudaSDKPath)) 22 | CudaSDKPath = System.Environment.GetEnvironmentVariable("CUDA_PATH_V10_2", EnvironmentVariableTarget.Machine); 23 | 24 | string ZEDSDKPath = System.Environment.GetEnvironmentVariable("ZED_SDK_ROOT_DIR", EnvironmentVariableTarget.Machine); 25 | 26 | PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "Public")); 27 | PrivateIncludePaths.Add(Path.Combine(ModuleDirectory, "Private")); 28 | 29 | PublicDependencyModuleNames.AddRange( 30 | new string[] 31 | { 32 | "MixedReality", 33 | 34 | "HeadMountedDisplay" 35 | 36 | // ... add other public dependencies that you statically link with here ... 37 | } 38 | ); 39 | 40 | PrivateDependencyModuleNames.AddRange( 41 | new string[] 42 | { 43 | "Core", 44 | "CoreUObject", 45 | 46 | "Engine", 47 | 48 | "InputCore", 49 | 50 | "RenderCore", 51 | "ShaderCore", 52 | 53 | "RHI", 54 | "D3D11RHI", 55 | "OpenGLDrv", 56 | 57 | "UMG", 58 | "SlateCore" 59 | } 60 | ); 61 | 62 | // Paths for low-level directx and opengl access 63 | string engine_path = Path.GetFullPath(Target.RelativeEnginePath); 64 | PrivateIncludePaths.AddRange( 65 | new string[] 66 | { 67 | engine_path + "Source/Runtime/Windows/D3D11RHI/Private/", 68 | engine_path + "Source/Runtime/Windows/D3D11RHI/Private/Windows", 69 | engine_path + "Source/Runtime/OpenGLDrv/Private/", 70 | engine_path + "Source/Runtime/OpenGLDrv/Private/Windows", 71 | engine_path + "Source/ThirdParty/OpenGL" 72 | // ... add other private include paths required here ... 73 | } 74 | ); 75 | 76 | 77 | LoadZEDSDK(Target, ZEDSDKPath); 78 | LoadCUDA(Target, CudaSDKPath); 79 | } 80 | 81 | public void LoadZEDSDK(ReadOnlyTargetRules Target, string DirPath) 82 | { 83 | if (Target.Platform == UnrealTargetPlatform.Win64) 84 | { 85 | if(!Directory.Exists(DirPath)) 86 | { 87 | string Err = string.Format("ZED SDK missing"); 88 | System.Console.WriteLine(Err); 89 | throw new BuildException(Err); 90 | } 91 | 92 | // Check SDK version 93 | string DefinesHeaderFilePath = Path.Combine(DirPath, "include\\sl\\Camera.hpp"); 94 | string Major = "3"; 95 | string Minor = "0"; 96 | 97 | // Find SDK major and minor version and compare 98 | foreach (var line in File.ReadLines(DefinesHeaderFilePath)) 99 | { 100 | if (!string.IsNullOrEmpty(line)) 101 | { 102 | if(line.Contains("#define ZED_SDK_MAJOR_VERSION")) 103 | { 104 | string SDKMajor = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[2]; 105 | if(!SDKMajor.Equals(Major)) 106 | { 107 | string Err = string.Format("ZED SDK Major Version mismatch : found {0} expected {1}", SDKMajor, Major); 108 | System.Console.WriteLine(Err); 109 | throw new BuildException(Err); 110 | } 111 | } 112 | else if (line.Contains("#define ZED_SDK_MINOR_VERSION")) 113 | { 114 | string SDKMinor = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[2]; 115 | if (!SDKMinor.Equals(Minor)) 116 | { 117 | string Err = string.Format("ZED SDK Minor Version mismatch : found {0} expected {1}", SDKMinor, Minor); 118 | System.Console.WriteLine(Err); 119 | throw new BuildException(Err); 120 | } 121 | 122 | break; 123 | } 124 | } 125 | } 126 | 127 | // Set the paths to the SDK 128 | string[] LibrariesNames = Directory.GetFiles(Path.Combine(DirPath, "lib")); 129 | 130 | PublicIncludePaths.Add(Path.Combine(DirPath, "include")); 131 | PublicLibraryPaths.Add(Path.Combine(DirPath, "lib")); 132 | 133 | foreach (string Library in LibrariesNames) 134 | { 135 | PublicAdditionalLibraries.Add(Library); 136 | } 137 | } 138 | else if (Target.Platform == UnrealTargetPlatform.Win32) 139 | { 140 | string Err = string.Format("Attempt to build against ZED SDK on unsupported platform {0}", Target.Platform); 141 | System.Console.WriteLine(Err); 142 | throw new BuildException(Err); 143 | } 144 | } 145 | 146 | public void LoadCUDA(ReadOnlyTargetRules Target, string DirPath) 147 | { 148 | if (Target.Platform == UnrealTargetPlatform.Win64) 149 | { 150 | if (!Directory.Exists(DirPath)) 151 | { 152 | string Err = string.Format("CUDA SDK missing"); 153 | System.Console.WriteLine(Err); 154 | throw new BuildException(Err); 155 | } 156 | 157 | string[] LibrariesName = { 158 | "cuda", 159 | "cudart" 160 | }; 161 | 162 | PublicIncludePaths.Add(Path.Combine(DirPath, "include")); 163 | PublicLibraryPaths.Add(Path.Combine(DirPath, "lib\\x64")); 164 | 165 | foreach (string Library in LibrariesName) 166 | { 167 | PublicAdditionalLibraries.Add(Library + ".lib"); 168 | } 169 | } 170 | else if (Target.Platform == UnrealTargetPlatform.Win32) 171 | { 172 | string Err = string.Format("Attempt to build against CUDA on unsupported platform {0}", Target.Platform); 173 | System.Console.WriteLine(Err); 174 | throw new BuildException(Err); 175 | } 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /Stereolabs/Source/ThirdParty/MixedReality/MixedReality.build.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | using System; 4 | using System.IO; 5 | using UnrealBuildTool; 6 | 7 | public class MixedReality : ModuleRules 8 | { 9 | private string ModulePath 10 | { 11 | get { return ModuleDirectory; } 12 | } 13 | 14 | public string ProjectBinariesPathDirectory 15 | { 16 | get { return Path.GetFullPath(Path.Combine(ModulePath, "../../../../../Binaries/Win64/")); } 17 | } 18 | 19 | public MixedReality(ReadOnlyTargetRules Target) : base(Target) 20 | { 21 | Type = ModuleType.External; 22 | 23 | if (Target.Platform == UnrealTargetPlatform.Win64) 24 | { 25 | string PostFix = "64"; 26 | string[] LibrariesName = { 27 | "sl_mr_core" 28 | }; 29 | 30 | PublicIncludePaths.Add(ModulePath + "/include"); 31 | PublicLibraryPaths.Add(ModulePath + "/lib"); 32 | 33 | foreach (string Library in LibrariesName) 34 | { 35 | string DLLName = Library + PostFix + ".dll"; 36 | string LibName = Library + PostFix + ".lib"; 37 | 38 | PublicAdditionalLibraries.Add(LibName); 39 | PublicDelayLoadDLLs.Add(DLLName); 40 | 41 | string DLLPath = Path.Combine(ModulePath + "/bin/", DLLName); 42 | 43 | if (Target.Type != TargetRules.TargetType.Editor) 44 | { 45 | if (!Directory.Exists(ProjectBinariesPathDirectory)) 46 | { 47 | Directory.CreateDirectory(ProjectBinariesPathDirectory); 48 | } 49 | // Copy to the project binary folder 50 | File.Copy(DLLPath, Path.Combine(ProjectBinariesPathDirectory, DLLName), true); 51 | 52 | // Add library to the packaged binary folder 53 | RuntimeDependencies.Add(ProjectBinariesPathDirectory + DLLName, StagedFileType.NonUFS); 54 | } 55 | // Remove the library if it already exist in the binary folder 56 | else 57 | { 58 | if (Directory.Exists(ProjectBinariesPathDirectory) && File.Exists(Path.Combine(ProjectBinariesPathDirectory, DLLName))) 59 | { 60 | File.Delete(Path.Combine(ProjectBinariesPathDirectory, DLLName)); 61 | } 62 | } 63 | } 64 | } 65 | else if (Target.Platform == UnrealTargetPlatform.Win32) 66 | { 67 | string Err = string.Format("Attempt to build against ZED MIXED REALITY SDK on unsupported platform {0}", Target.Platform); 68 | System.Console.WriteLine(Err); 69 | throw new BuildException(Err); 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /Stereolabs/Source/ThirdParty/MixedReality/bin/sl_mr_core64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Source/ThirdParty/MixedReality/bin/sl_mr_core64.dll -------------------------------------------------------------------------------- /Stereolabs/Source/ThirdParty/MixedReality/include/sl_mr_core/AntiDrift.hpp: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #ifndef __MR_CORE_ANTIDRIFT_H__ 4 | #define __MR_CORE_ANTIDRIFT_H__ 5 | 6 | #include "sl_mr_core/defines.hpp" 7 | 8 | namespace sl { 9 | namespace mr { 10 | 11 | /** 12 | * \brief Initialize drift corrector. No functions can be called before initialization. 13 | */ 14 | SLMRCORE_API void driftCorrectorInitialize(); 15 | 16 | /** 17 | * \brief Shutdown drift corrector. No functions can be called after shutdown. 18 | */ 19 | SLMRCORE_API void driftCorrectorShutdown(); 20 | 21 | /** 22 | * \brief Compute the tracking data 23 | * @param trackingData The tracking data to apply anti drift to 24 | * @param HMDTransform The HMD transform 25 | * @param latencyCorrectorTransform The latency corrector transform 26 | * @param hasValidTrackingPosition True if the position tracking is enabled 27 | */ 28 | SLMRCORE_API bool driftCorrectorGetTrackingData(sl::mr::trackingData& trackingData, const sl::Transform& HMDTransform, const sl::Transform& latencyCorrectorTransform, bool hasValidTrackingPosition, bool checkDrift); 29 | 30 | /** 31 | * \brief Set calibration transform 32 | * @param calibrationTransform The transform created from calibration 33 | */ 34 | SLMRCORE_API void driftCorrectorSetCalibrationTransform(const sl::Transform& calibrationTransform); 35 | 36 | /** 37 | * \brief Set const offset transform 38 | * @param constOffsetTransform The transform 39 | */ 40 | SLMRCORE_API void driftCorrectorSetConstOffsetTransfrom(const sl::Transform& constOffsetTransform); 41 | 42 | /** 43 | * \brief Set the tracking offset transform 44 | * @param trackingOffsetTransform The transform 45 | */ 46 | SLMRCORE_API void driftCorrectorSetTrackingOffsetTransfrom(const sl::Transform& trackingOffsetTransform); 47 | } 48 | } 49 | 50 | #endif // __ANTIDRIFT_H__ -------------------------------------------------------------------------------- /Stereolabs/Source/ThirdParty/MixedReality/include/sl_mr_core/EnvironmentalLighting.hpp: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #ifndef __ENVLIGHT_H__ 4 | #define __ENVLIGHT_H__ 5 | 6 | #include "sl_mr_core/defines.hpp" 7 | 8 | namespace sl { 9 | namespace mr { 10 | 11 | /** 12 | * \brief Init the environmental lighting, all the coefficients are initialized during the process. 13 | */ 14 | SLMRCORE_API void environmentalLightingInitialize(); 15 | 16 | /** 17 | * brief Shutdown environmental lighting. No functions can be called after shutdown. 18 | */ 19 | SLMRCORE_API void environmentalLightingShutdown(); 20 | 21 | /** 22 | * \brief Compute the diffuse coefficients 23 | * @param buffer The mat buffer storing zed left image 24 | */ 25 | SLMRCORE_API void environmentalLightingComputeDiffuseCoefficients(sl::Mat* buffer); 26 | 27 | /** 28 | * \brief Return the SHM matrix 29 | * @param matrix The SHM matrix 30 | * @param index The column index 31 | * @return the SHM matrix 32 | */ 33 | SLMRCORE_API void environmentalLightingGetShmMatrix(sl::Matrix4f* matrix, int index); 34 | 35 | /** 36 | * \brief Return the exposure 37 | * @param deltaTime Delta time of the application 38 | * @return The exposure 39 | */ 40 | SLMRCORE_API float environmentalLightingGetExposure(float deltaTime); 41 | 42 | } 43 | } 44 | 45 | #endif // __ENVLIGHTS_H__ -------------------------------------------------------------------------------- /Stereolabs/Source/ThirdParty/MixedReality/include/sl_mr_core/Rendering.hpp: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #ifndef __RENDERING_H__ 4 | #define __RENDERING_H__ 5 | 6 | #include "sl_mr_core/defines.hpp" 7 | 8 | 9 | namespace sl { 10 | namespace mr { 11 | 12 | /** 13 | * \brief Compute rendering plane size 14 | * @param verticalFOV Zed vertical FOV 15 | * @param planeDistance Plane rendering distance from camera 16 | * @param imageResolution Zed image resolution 17 | * @return size width/height of the plane 18 | */ 19 | SLMRCORE_API sl::float2 computeRenderPlaneSize(const sl::Resolution& imageResolution, float verticalFOV, float planeDistance); 20 | 21 | /** 22 | * \brief Compute rendering plane size using gamma 23 | * @param gamma The gamma 24 | * @param HMDFocal HMD focal 25 | * @param planeDistance Plane rendering distance from camera 26 | * @param imageResolution Zed image resolution 27 | * @return the width/height of the plane 28 | */ 29 | SLMRCORE_API sl::float2 computeRenderPlaneSizeWithGamma(const sl::Resolution& imageResolution, float perceptionDistance, float eyeToZedDistance, float planeDistance, float HMDFocal, float zedFocal); 30 | 31 | /** 32 | * \brief Compute optical center offsets for left/right images 33 | * @param calibrationParameters Zed calibration parameters 34 | * @param imageResolution Zed image resolution 35 | * @param distance Distance from camera 36 | * @return the x/y offset for each eye 37 | */ 38 | SLMRCORE_API sl::float4 computeOpticalCentersOffsets(const sl::CalibrationParameters& calibrationParameters, const sl::Resolution& imageResolution, float distance); 39 | 40 | /** 41 | * \brief Compute HMD focal 42 | * @param renderTargetSize Render target size used by the HMD 43 | * @param w Projection matrix [0][0] case 44 | * @param h Projection matrix [1][1] case 45 | */ 46 | SLMRCORE_API float computeHMDFocal(const sl::Resolution& renderTargetSize, float w, float h); 47 | 48 | /** 49 | * \brief Return the distance from the eyes to the Zed 50 | * @param HMDDeviceType The HMD type 51 | */ 52 | SLMRCORE_API float getEyeToZEDDistance(sl::mr::HMD_DEVICE_TYPE HMDDeviceType); 53 | 54 | /** 55 | * \brief Return factors for generating noise 56 | * @param gain The camera gain 57 | */ 58 | SLMRCORE_API sl::mr::noiseFactors computeNoiseFactors(float gain); 59 | 60 | /** 61 | * \brief 62 | */ 63 | SLMRCORE_API void computeSRemap(sl::mr::HMD_DEVICE_TYPE HMDDeviceType, sl::RESOLUTION camRes, float b, float Ipd, float f_h, float f_z, float dp, float Hy, float Hz, sl::Resolution requestedSize, int precision, sl::Mat*& outputMx, sl::Mat*& outputMy); 64 | 65 | } 66 | } 67 | 68 | #endif // __RENDERING_H__ 69 | -------------------------------------------------------------------------------- /Stereolabs/Source/ThirdParty/MixedReality/include/sl_mr_core/defines.hpp: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #ifndef __MR_CORE_DEFINES_H__ 4 | #define __MR_CORE_DEFINES_H__ 5 | 6 | #ifdef _WIN32 7 | #ifdef SLMRCORE_EXPORT 8 | #define SLMRCORE_API __declspec(dllexport) 9 | #else 10 | #define SLMRCORE_API __declspec(dllimport) 11 | #endif 12 | #else 13 | #define SLMRCORE_API 14 | #endif 15 | 16 | #include 17 | #include 18 | 19 | namespace sl { 20 | namespace mr { 21 | 22 | /** 23 | * \enum HMD_DEVICE_TYPE 24 | * \ingroup Enumerations 25 | * \brief Types of HMD supported 26 | */ 27 | enum class HMD_DEVICE_TYPE : uint8_t { 28 | HMD_DEVICE_TYPE_UNKNOWN, 29 | HMD_DEVICE_TYPE_OCULUS, 30 | HMD_DEVICE_TYPE_HTC 31 | }; 32 | 33 | /** 34 | * \struct noiseFactors 35 | * \brief Factors of each channel for noise generation 36 | */ 37 | struct SLMRCORE_API noiseFactors { 38 | 39 | noiseFactors(sl::float2 r, sl::float2 g, sl::float2 b) 40 | : 41 | r(r), 42 | g(g), 43 | b(b) 44 | {} 45 | 46 | /** r channel */ 47 | sl::float2 r; 48 | 49 | /** g channel */ 50 | sl::float2 g; 51 | 52 | /** b channel */ 53 | sl::float2 b; 54 | }; 55 | 56 | 57 | /** 58 | * \struct trackingData 59 | * \brief Tracking data 60 | */ 61 | struct SLMRCORE_API trackingData { 62 | /** Path transform from tracking origin ((0, 0, 0) in world space relative to left eye) */ 63 | sl::Transform zedPathTransform; 64 | 65 | /** Zed world space transform ((Location/rotation in world space) with anti drift in stereo) */ 66 | sl::Transform zedWorldTransform; 67 | 68 | /** Zed world transform without camera offset (Head location/rotation) */ 69 | sl::Transform offsetZedWorldTransform; 70 | 71 | /** Tracking state */ 72 | sl::POSITIONAL_TRACKING_STATE trackingState; 73 | }; 74 | 75 | typedef unsigned long long latencyTime; 76 | 77 | /** 78 | * \struct keyPose 79 | * \brief A pair transform/time stamp 80 | */ 81 | struct SLMRCORE_API keyPose { 82 | keyPose() 83 | {} 84 | 85 | keyPose(sl::Transform transform, sl::Timestamp timeStamp) 86 | : 87 | transform(transform), 88 | timeStamp(timeStamp) 89 | {} 90 | 91 | /** The pose transform */ 92 | sl::Transform transform; 93 | 94 | /** The pose time stamp */ 95 | sl::Timestamp timeStamp; 96 | }; 97 | 98 | 99 | /** 100 | * \struct keyPose 101 | * \brief A pair transform/time stamp 102 | */ 103 | struct SLMRCORE_API keyOrientation { 104 | keyOrientation() 105 | {} 106 | 107 | keyOrientation(sl::Orientation orientation, sl::Timestamp timeStamp) 108 | : 109 | orientation(orientation), 110 | timeStamp(timeStamp) 111 | {} 112 | 113 | /** The pose transform */ 114 | sl::Orientation orientation; 115 | 116 | /** The pose time stamp */ 117 | sl::Timestamp timeStamp; 118 | }; 119 | } 120 | } 121 | 122 | #endif // __DEFINES_H__ 123 | -------------------------------------------------------------------------------- /Stereolabs/Source/ThirdParty/MixedReality/include/sl_mr_core/latency.hpp: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #ifndef __LATENCY_H__ 4 | #define __LATENCY_H__ 5 | 6 | #include "sl_mr_core/defines.hpp" 7 | 8 | namespace sl { 9 | namespace mr { 10 | 11 | enum EHmdType { 12 | eHmdType_Vive, 13 | eHmdType_Oculus 14 | }; 15 | 16 | /** 17 | * \brief Initialize latency corrector. No functions can be called before initialization. 18 | */ 19 | SLMRCORE_API void latencyCorrectorInitialize(EHmdType type); 20 | 21 | /** 22 | * \brief Shutdown latency corrector. No functions can be called after shutdown. 23 | */ 24 | SLMRCORE_API void latencyCorrectorShutdown(); 25 | 26 | /** 27 | * \brief Shutdown latency corrector. No functions can be called after shutdown. 28 | */ 29 | SLMRCORE_API void latencyCorrectorAdjOffset(sl::Timestamp offset); 30 | 31 | /** 32 | * \brief Delete latency corrector 33 | * @param keyPose The key 34 | */ 35 | SLMRCORE_API void latencyCorrectorAddKeyPose(const sl::mr::keyPose& keyPose); 36 | 37 | /** 38 | * \brief Delete latency corrector 39 | * @param timeStamp Timestamp of the transform 40 | * @param outTransform Retrieved transform 41 | * @return True if the transform is retrieved 42 | */ 43 | SLMRCORE_API bool latencyCorrectorGetTransform(sl::Timestamp timeStamp, sl::Transform& outTransform, bool useLatencyTime = true); 44 | 45 | SLMRCORE_API void ComputeOptimSO3(std::vector serie1, std::vector serie2, sl::mr::keyOrientation& output); 46 | 47 | } 48 | } 49 | 50 | #endif // __LATENCY_H__ 51 | -------------------------------------------------------------------------------- /Stereolabs/Source/ThirdParty/MixedReality/lib/sl_mr_core64.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stereolabs/zed-unreal-plugin/b88989507dd4e5ec56d4e461320b68f6a36b4009/Stereolabs/Source/ThirdParty/MixedReality/lib/sl_mr_core64.lib -------------------------------------------------------------------------------- /Stereolabs/Source/ZED/Classes/ZEDGameInstance.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | #include "Engine/GameInstance.h" 5 | 6 | #include "ZEDGameInstance.generated.h" 7 | 8 | UCLASS() 9 | class UZEDGameInstance : public UGameInstance 10 | { 11 | GENERATED_BODY() 12 | 13 | public: 14 | virtual void Init() override; 15 | virtual void Shutdown() override; 16 | 17 | #if WITH_EDITOR 18 | virtual FGameInstancePIEResult InitializeForPlayInEditor(int32 PIEInstanceIndex, const FGameInstancePIEParameters& Params) override; 19 | virtual FGameInstancePIEResult StartPlayInEditorGameInstance(ULocalPlayer* LocalPlayer, const FGameInstancePIEParameters& Params) override; 20 | #endif 21 | }; -------------------------------------------------------------------------------- /Stereolabs/Source/ZED/Classes/ZEDGameViewportClient.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "Engine/GameViewportClient.h" 6 | 7 | #include "ZEDGameViewportClient.generated.h" 8 | 9 | UCLASS() 10 | class ZED_API UZEDGameViewportClient : public UGameViewportClient 11 | { 12 | GENERATED_UCLASS_BODY() 13 | 14 | public: 15 | virtual ~UZEDGameViewportClient(); 16 | 17 | public: 18 | virtual void Draw(FViewport* Viewport, FCanvas* SceneCanvas) override; 19 | 20 | private: 21 | /** Current buffer visualization mode for this game viewport */ 22 | FName CurrentBufferVisualizationMode; 23 | 24 | /** Delegate called when the engine starts drawing a game viewport */ 25 | FSimpleMulticastDelegate BeginDrawDelegate; 26 | 27 | /** Delegate called when the game viewport is drawn, before drawing the console */ 28 | FSimpleMulticastDelegate DrawnDelegate; 29 | 30 | /** Delegate called when the engine finishes drawing a game viewport */ 31 | FSimpleMulticastDelegate EndDrawDelegate; 32 | 33 | /** Whether or not this audio device is in audio-focus */ 34 | bool bHasAudioFocus; 35 | }; -------------------------------------------------------------------------------- /Stereolabs/Source/ZED/Classes/ZEDLocalPlayer.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "Engine/LocalPlayer.h" 6 | 7 | #include "ZEDLocalPlayer.generated.h" 8 | 9 | UCLASS() 10 | class ZED_API UZEDLocalPlayer : public ULocalPlayer 11 | { 12 | GENERATED_UCLASS_BODY() 13 | 14 | private: 15 | FSceneViewStateReference ViewState; 16 | FSceneViewStateReference StereoViewState; 17 | 18 | public: 19 | virtual bool GetProjectionData(FViewport* Viewport, 20 | EStereoscopicPass StereoPass, 21 | FSceneViewProjectionData& ProjectionData) const override; 22 | 23 | bool GetZEDProjectionData(FViewport* Viewport, FSceneViewProjectionData& ProjectionData) const; 24 | 25 | virtual FSceneView* CalcSceneView(class FSceneViewFamily* ViewFamily, 26 | FVector& OutViewLocation, 27 | FRotator& OutViewRotation, 28 | FViewport* Viewport, 29 | class FViewElementDrawer* ViewDrawer = NULL, 30 | EStereoscopicPass StereoPass = eSSP_FULL) override; 31 | }; -------------------------------------------------------------------------------- /Stereolabs/Source/ZED/Defaults/Camera.ini: -------------------------------------------------------------------------------- 1 | [Camera] 2 | Brightness=4 3 | Contrast=4 4 | Hue=0 5 | Saturation=4 6 | WhiteBalance=4700 7 | Gain=56 8 | Exposure=100 9 | bAutoWhiteBalance=True 10 | bAutoGainAndExposure=True 11 | bDefault=False 12 | -------------------------------------------------------------------------------- /Stereolabs/Source/ZED/Defaults/DefaultEngine.ini: -------------------------------------------------------------------------------- 1 | [URL] 2 | [/Script/EngineSettings.GameMapsSettings] 3 | GlobalDefaultGameMode=/Stereolabs/ZED/Blueprints/GameMode/BP_ZED_GameMode.BP_ZED_GameMode_C 4 | GameInstanceClass=/Script/ZED.ZEDGameInstance 5 | 6 | [/Script/Engine.Engine] 7 | GameViewportClientClassName=/Script/ZED.ZEDGameViewportClient 8 | LocalPlayerClassName=/Script/ZED.ZEDLocalPlayer 9 | NearClipPlane=1.000000 10 | 11 | [/Script/Engine.RendererSettings] 12 | r.TextureStreaming=False 13 | r.AllowStaticLighting=False 14 | r.SeparateTranslucency=False 15 | r.DBuffer=False 16 | r.DefaultFeature.AmbientOcclusion=False 17 | r.DefaultFeature.AmbientOcclusionStaticFraction=False 18 | r.DefaultFeature.AutoExposure=False 19 | r.DefaultFeature.MotionBlur=False 20 | r.DefaultFeature.AntiAliasing=1 21 | r.CustomDepth=0 22 | r.EarlyZPass=0 23 | r.HZBOcclusion=0 24 | r.MotionBlurQuality=0 25 | r.PostProcessAAQuality=3 26 | r.BloomQuality=1 27 | r.EyeAdaptationQuality=0 28 | r.AmbientOcclusionLevels=0 29 | r.SSR.Quality=1 30 | r.DepthOfFieldQuality=0 31 | r.SceneColorFormat=2 32 | r.TranslucencyVolumeBlur=0 33 | r.TranslucencyLightingVolumeDim=4 34 | r.MaxAnisotropy=8 35 | r.LensFlareQuality=0 36 | r.SceneColorFringeQuality=0 37 | r.FastBlurThreshold=0 38 | r.SSR.MaxRoughness=0.1 39 | r.rhicmdbypass=0 40 | sg.EffectsQuality=2 41 | sg.PostProcessQuality=0 -------------------------------------------------------------------------------- /Stereolabs/Source/ZED/Defaults/ZED.ini: -------------------------------------------------------------------------------- 1 | [Init] 2 | Resolution=2 3 | FPS=60 4 | bUseSVO=False 5 | bRealTime=False 6 | DepthMode=1 7 | GPUID=-1 8 | DepthMinimumDistance=10.000000 9 | DepthMaximumDistance=2000.000000 10 | bVerbose=False 11 | bDisableSelfCalibration=False 12 | bVerticalFlipImage=False 13 | SVOFilePath= 14 | VerboseFilePath= 15 | bEnableDepthStabilization=True 16 | bEnableRightSideMeasure=True 17 | 18 | [Tracking] 19 | SpatialMemoryFileLoadingPath= 20 | SpatialMemoryFileSavingPath= 21 | bEnableTracking=True 22 | bEnableSpatialMemory=False 23 | bEnablePoseSmoothing=True 24 | bLoadSpatialMemoryFile=False 25 | Location=X=0.000 Y=0.000 Z=0.000 26 | Rotation=P=0.000000 Y=0.000000 R=0.000000 27 | TrackingType=0 28 | 29 | [Runtime] 30 | SensingMode=0 31 | bEnableDepth=True 32 | bEnablePointCloud=False 33 | ReferenceFrame=0 34 | 35 | [Rendering] 36 | PerceptionDistance=100.000000 37 | ThreadingMode=0 38 | SRemapEnable=False 39 | 40 | [SVO] 41 | RecordingFilePath= 42 | CompressionMode=0 43 | bLoop=False -------------------------------------------------------------------------------- /Stereolabs/Source/ZED/Private/Core/ZEDBaseTypes.cpp: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #include "ZEDPrivatePCH.h" 4 | #include "ZED/Public/Core/ZEDBaseTypes.h" -------------------------------------------------------------------------------- /Stereolabs/Source/ZED/Private/Core/ZEDCoreGlobals.cpp: -------------------------------------------------------------------------------- 1 | ///======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #include "ZEDPrivatePCH.h" 4 | #include "ZED/Public/Core/ZEDCoreGlobals.h" 5 | 6 | FZEDTrackingData GZedTrackingData = FZEDTrackingData(); 7 | 8 | FRotator GZedRawRotation = FRotator::ZeroRotator; 9 | 10 | FVector GZedRawLocation = FVector::ZeroVector; 11 | 12 | FRotator GZedViewPointRotation = FRotator::ZeroRotator; 13 | 14 | FVector GZedViewPointLocation = FVector::ZeroVector; -------------------------------------------------------------------------------- /Stereolabs/Source/ZED/Private/Core/ZEDInitializer.cpp: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #include "ZEDPrivatePCH.h" 4 | #include "ZED/Public/Core/ZEDInitializer.h" 5 | #include "ZED/Public/Utilities/ZEDFunctionLibrary.h" 6 | 7 | #if WITH_EDITOR 8 | #define ZED_CONFIG_FILE_PATH FPaths::Combine(*FPaths::ProjectDir(), *FString("Saved/Config/ZED/ZED.ini")) 9 | #define ZED_CAMERA_CONFIG_FILE_PATH FPaths::Combine(*FPaths::ProjectDir(), *FString("Saved/Config/ZED/Camera.ini")) 10 | #define DEFAULT_VERBOSE_FILE_PATH FPaths::Combine(*FPaths::ConvertRelativePathToFull(FPaths::ProjectDir()), *FString("Binaries/Win64/ZedLog.txt")) 11 | #else 12 | #define ZED_CONFIG_FILE_PATH FPaths::Combine(*FPaths::ConvertRelativePathToFull("../../"), *FString("Saved/Config/ZED/ZED.ini")) 13 | #define ZED_CAMERA_CONFIG_FILE_PATH FPaths::Combine(*FPaths::ConvertRelativePathToFull("../../"), *FString("Saved/Config/ZED/Camera.ini")) 14 | #define DEFAULT_VERBOSE_FILE_PATH FPaths::Combine(*FPaths::ConvertRelativePathToFull("."), *FString("ZedLog.txt")) 15 | #endif 16 | 17 | bool CheckGConfigAvailable() 18 | { 19 | if (!GConfig) 20 | { 21 | SL_LOG_E(ZEDFunctionLibrary, "GConfig not available"); 22 | return false; 23 | } 24 | 25 | return true; 26 | } 27 | 28 | AZEDInitializer::AZEDInitializer() 29 | : 30 | bLoadParametersFromConfigFile(false), 31 | bLoadCameraSettingsFromConfigFile(false), 32 | bUseHMDTrackingAsOrigin(false) 33 | { 34 | if (InitParameters.VerboseFilePath.IsEmpty()) 35 | { 36 | InitParameters.VerboseFilePath = DEFAULT_VERBOSE_FILE_PATH; 37 | } 38 | } 39 | 40 | #if WITH_EDITOR 41 | void AZEDInitializer::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) 42 | { 43 | FName PropertyName = (PropertyChangedEvent.Property != NULL) ? PropertyChangedEvent.Property->GetFName() : NAME_None; 44 | 45 | Super::PostEditChangeProperty(PropertyChangedEvent); 46 | } 47 | 48 | bool AZEDInitializer::CanEditChange(const UProperty* InProperty) const 49 | { 50 | FName PropertyName = InProperty->GetFName(); 51 | 52 | if (InProperty->GetOwnerStruct()) 53 | { 54 | FString StructName = InProperty->GetOwnerStruct()->GetName(); 55 | 56 | if (StructName == FString("SlCameraSettings")) 57 | { 58 | return !InitParameters.bUseSVO; 59 | } 60 | 61 | if (StructName == FString("SlRuntimeParameters")) 62 | { 63 | if (PropertyName == GET_MEMBER_NAME_CHECKED(FSlRuntimeParameters, ReferenceFrame)) 64 | { 65 | return false; 66 | } 67 | 68 | return true; 69 | } 70 | } 71 | 72 | if (PropertyName == GET_MEMBER_NAME_CHECKED(FSlInitParameters, Resolution) || 73 | PropertyName == GET_MEMBER_NAME_CHECKED(FSlSVOParameters, RecordingFilePath) || 74 | PropertyName == GET_MEMBER_NAME_CHECKED(FSlSVOParameters, CompressionMode) 75 | ) 76 | { 77 | return !InitParameters.bUseSVO; 78 | } 79 | 80 | if (PropertyName == GET_MEMBER_NAME_CHECKED(FSlInitParameters, SVOFilePath) || 81 | PropertyName == GET_MEMBER_NAME_CHECKED(FSlInitParameters, bRealTime) || 82 | PropertyName == GET_MEMBER_NAME_CHECKED(FSlSVOParameters, bLoop)) 83 | { 84 | return InitParameters.bUseSVO; 85 | } 86 | 87 | if (PropertyName == GET_MEMBER_NAME_CHECKED(FSlInitParameters, DepthMode)) 88 | { 89 | return RuntimeParameters.bEnableDepth; 90 | } 91 | 92 | if(PropertyName == GET_MEMBER_NAME_CHECKED(FSlPositionalTrackingParameters, Location) || 93 | PropertyName == GET_MEMBER_NAME_CHECKED(FSlPositionalTrackingParameters, Rotation)) 94 | { 95 | return !bUseHMDTrackingAsOrigin; 96 | } 97 | 98 | if (PropertyName == GET_MEMBER_NAME_CHECKED(FSlPositionalTrackingParameters, bEnablePoseSmoothing)) 99 | { 100 | return TrackingParameters.bEnableAreaMemory; 101 | } 102 | 103 | if (PropertyName == GET_MEMBER_NAME_CHECKED(FSlRenderingParameters, ThreadingMode)) 104 | { 105 | return !InitParameters.bUseSVO; 106 | } 107 | 108 | return Super::CanEditChange(InProperty); 109 | } 110 | #endif 111 | 112 | void AZEDInitializer::LoadParametersAndSettings() 113 | { 114 | if (bLoadParametersFromConfigFile) 115 | { 116 | LoadParameters(); 117 | } 118 | if (bLoadCameraSettingsFromConfigFile) 119 | { 120 | LoadCameraSettings(); 121 | } 122 | 123 | LoadAntiDriftParameters(); 124 | } 125 | 126 | void AZEDInitializer::LoadParameters() 127 | { 128 | if (!CheckGConfigAvailable()) 129 | { 130 | return; 131 | } 132 | 133 | FString Path = ZED_CONFIG_FILE_PATH; 134 | FConfigFile* ConfigFile = GConfig->Find(Path, false); 135 | 136 | if (!ConfigFile) 137 | { 138 | SaveParameters(); 139 | } 140 | else 141 | { 142 | InitParameters.Load(Path); 143 | if (InitParameters.VerboseFilePath.IsEmpty()) 144 | { 145 | InitParameters.VerboseFilePath = DEFAULT_VERBOSE_FILE_PATH; 146 | } 147 | 148 | TrackingParameters.Load(Path); 149 | RuntimeParameters.Load(Path); 150 | RenderingParameters.Load(Path); 151 | SVOParameters.Load(Path); 152 | } 153 | } 154 | 155 | void AZEDInitializer::LoadCameraSettings() 156 | { 157 | if (!CheckGConfigAvailable()) 158 | { 159 | return; 160 | } 161 | 162 | FString Path = ZED_CAMERA_CONFIG_FILE_PATH; 163 | FConfigFile* ConfigFile = GConfig->Find(Path, false); 164 | 165 | if (!ConfigFile) 166 | { 167 | SaveCameraSettings(); 168 | } 169 | else 170 | { 171 | CameraSettings.Load(Path); 172 | } 173 | } 174 | 175 | void AZEDInitializer::SaveParameters() 176 | { 177 | if (!CheckGConfigAvailable()) 178 | { 179 | return; 180 | } 181 | 182 | FString Path = ZED_CONFIG_FILE_PATH; 183 | 184 | #if WITH_EDITOR 185 | if (InitParameters.VerboseFilePath == DEFAULT_VERBOSE_FILE_PATH) 186 | { 187 | InitParameters.VerboseFilePath.Empty(); 188 | } 189 | #endif 190 | 191 | InitParameters.Save(Path); 192 | TrackingParameters.Save(Path); 193 | RuntimeParameters.Save(Path); 194 | RenderingParameters.Save(Path); 195 | SVOParameters.Save(Path); 196 | 197 | GConfig->Flush(false, *Path); 198 | } 199 | 200 | void AZEDInitializer::SaveCameraSettings() 201 | { 202 | if (!CheckGConfigAvailable()) 203 | { 204 | return; 205 | } 206 | 207 | FString Path = ZED_CAMERA_CONFIG_FILE_PATH; 208 | CameraSettings.Save(Path); 209 | 210 | GConfig->Flush(false, *Path); 211 | } 212 | 213 | void AZEDInitializer::ResetParameters() 214 | { 215 | InitParameters = FSlInitParameters(); 216 | if (InitParameters.VerboseFilePath.IsEmpty()) 217 | { 218 | InitParameters.VerboseFilePath = DEFAULT_VERBOSE_FILE_PATH; 219 | } 220 | 221 | TrackingParameters = FSlPositionalTrackingParameters(); 222 | RuntimeParameters = FSlRuntimeParameters(); 223 | RenderingParameters = FSlRenderingParameters(); 224 | } 225 | 226 | void AZEDInitializer::ResetSettings() 227 | { 228 | CameraSettings = FSlVideoSettings(); 229 | } 230 | 231 | void AZEDInitializer::LoadAntiDriftParameters() 232 | { 233 | if (!CheckGConfigAvailable()) 234 | { 235 | return; 236 | } 237 | 238 | // Path set in build.cs 239 | FString Path = ZED_CALIBRAITON_FILE_PATH; 240 | FConfigFile* ConfigFile = GConfig->Find(Path, false); 241 | 242 | if (!ConfigFile) 243 | { 244 | AntiDriftParameters.Save(Path); 245 | 246 | GConfig->Flush(false, *Path); 247 | } 248 | else 249 | { 250 | AntiDriftParameters.Load(Path); 251 | } 252 | } 253 | -------------------------------------------------------------------------------- /Stereolabs/Source/ZED/Private/Core/ZEDPawn.cpp: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #include "ZEDPrivatePCH.h" 4 | #include "ZED/Public/Core/ZEDPawn.h" 5 | #include "ZED/Public/Core/ZEDPlayerController.h" 6 | #include "UMG.h" 7 | 8 | #include "Stereolabs/Public/Utilities/StereolabsFunctionLibrary.h" 9 | 10 | AZEDPawn::AZEDPawn() 11 | { 12 | PrimaryActorTick.bCanEverTick = false; 13 | 14 | RootComponent = CreateDefaultSubobject(TEXT("RootComponent")); 15 | 16 | SpringArm = CreateDefaultSubobject(TEXT("SpringArm")); 17 | SpringArm->SetupAttachment(RootComponent); 18 | 19 | Camera = CreateDefaultSubobject(TEXT("MainCamera")); 20 | Camera->SetupAttachment(SpringArm); 21 | Camera->bConstrainAspectRatio = true; 22 | Camera->PostProcessSettings.VignetteIntensity = 0.0f; 23 | Camera->PostProcessSettings.bOverride_VignetteIntensity = true; 24 | 25 | // Widget material 26 | static ConstructorHelpers::FObjectFinder ZedWidgetMaterial(TEXT("Material'/Stereolabs/ZED/Materials/M_ZED_3DWidgetPassthroughNoDepth.M_ZED_3DWidgetPassthroughNoDepth'")); 27 | ZedWidgetSourceMaterial = ZedWidgetMaterial.Object; 28 | 29 | // Zed loading source widget 30 | static ConstructorHelpers::FObjectFinder ZedLoadingWidgetBlueprint(TEXT("'/Stereolabs/ZED/Blueprints/HUD/Loading/W_ZED_Loading.W_ZED_Loading_C'")); 31 | ZedLoadingSourceWidget = ZedLoadingWidgetBlueprint.Object; 32 | 33 | // Zed error source widget 34 | static ConstructorHelpers::FObjectFinder ZedErrorWidgetBlueprint(TEXT("'/Stereolabs/ZED/Blueprints/HUD/Error/W_ZED_Error.W_ZED_Error_C'")); 35 | ZedErrorSourceWidget = ZedErrorWidgetBlueprint.Object; 36 | 37 | // Zed loading widget 38 | ZedLoadingWidget = CreateDefaultSubobject(TEXT("LoadingMessage")); 39 | ZedLoadingWidget->SetupAttachment(Camera); 40 | ZedLoadingWidget->SetWorldScale3D(FVector(0.5f)); 41 | ZedLoadingWidget->SetRelativeLocation(FVector(300.0f, 0.0f, 0.0f)); 42 | ZedLoadingWidget->SetRelativeRotation(FRotator(0.0f, 180.0f, 0.0f)); 43 | ZedLoadingWidget->WidgetComponent->SetMaterial(0, ZedWidgetSourceMaterial); 44 | ZedLoadingWidget->WidgetComponent->SetWidgetSpace(EWidgetSpace::World); 45 | ZedLoadingWidget->WidgetComponent->SetWidgetClass(ZedLoadingSourceWidget); 46 | ZedLoadingWidget->WidgetComponent->SetDrawSize(FVector2D(1920, 1080)); 47 | ZedLoadingWidget->WidgetComponent->SetGeometryMode(EWidgetGeometryMode::Cylinder); 48 | ZedLoadingWidget->WidgetComponent->SetCylinderArcAngle(80.0f); 49 | ZedLoadingWidget->WidgetComponent->SetBlendMode(EWidgetBlendMode::Transparent); 50 | ZedLoadingWidget->SetVisibility(false); 51 | 52 | // Zed error widget 53 | ZedErrorWidget = CreateDefaultSubobject(TEXT("ErrorMessage")); 54 | ZedErrorWidget->SetupAttachment(Camera); 55 | ZedErrorWidget->SetWorldScale3D(FVector(0.5f)); 56 | ZedErrorWidget->SetRelativeLocation(FVector(300.0f, 0.0f, 0.0f)); 57 | ZedErrorWidget->SetRelativeRotation(FRotator(0.0f, 180.0f, 0.0f)); 58 | ZedErrorWidget->WidgetComponent->SetMaterial(0, ZedWidgetSourceMaterial); 59 | ZedErrorWidget->WidgetComponent->SetWidgetSpace(EWidgetSpace::World); 60 | ZedErrorWidget->WidgetComponent->SetWidgetClass(ZedErrorSourceWidget); 61 | ZedErrorWidget->WidgetComponent->SetDrawSize(FVector2D(1920, 1080)); 62 | ZedErrorWidget->WidgetComponent->SetGeometryMode(EWidgetGeometryMode::Cylinder); 63 | ZedErrorWidget->WidgetComponent->SetCylinderArcAngle(80.0f); 64 | ZedErrorWidget->WidgetComponent->SetBlendMode(EWidgetBlendMode::Transparent); 65 | ZedErrorWidget->SetVisibility(false); 66 | 67 | AutoPossessPlayer = EAutoReceiveInput::Disabled; 68 | 69 | static ConstructorHelpers::FObjectFinder RemapMaterial(TEXT("Material'/Stereolabs/Stereolabs/Materials/M_SL_RPP.M_SL_RPP'")); 70 | RemapSourceMaterial = RemapMaterial.Object; 71 | } 72 | 73 | void AZEDPawn::ZedCameraTrackingUpdated(const FZEDTrackingData& NewTrackingData) 74 | { 75 | SetActorTransform(NewTrackingData.OffsetZedWorldTransform); 76 | } 77 | 78 | void AZEDPawn::InitRemap(FName HMDname, sl::RESOLUTION camRes, float dp) 79 | { 80 | FSlCameraInformation camInfo = GSlCameraProxy->GetCameraInformation(FIntPoint(0, 0)); 81 | FVector2D hmdFoc = USlFunctionLibrary::GetHmdFocale(); 82 | int RemapRez = 2501; 83 | int RemapPrecision = 100; 84 | sl::Mat* Mx; 85 | sl::Mat* My; 86 | // Warning: b, Ipd and dp have to be in mm 87 | sl::mr::computeSRemap(sl::unreal::ToSlType(HMDname), camRes, camInfo.HalfBaseline*20, camInfo.HalfBaseline*20, (hmdFoc.X + hmdFoc.Y)/2.0, camInfo.CalibrationParameters.LeftCameraParameters.HFocal, dp*10 + 100.0, -120.0, 100.0, sl::Resolution(RemapRez, RemapRez), RemapPrecision, Mx, My); 88 | RemapMx = USlFunctionLibrary::GenerateTextureFromSlMat(Mx); 89 | RemapMy = USlFunctionLibrary::GenerateTextureFromSlMat(My); 90 | 91 | RemapMaterialInstanceDynamic = UMaterialInstanceDynamic::Create(RemapSourceMaterial, nullptr); 92 | RemapMaterialInstanceDynamic->SetTextureParameterValue(FName("Mx"), RemapMx); 93 | RemapMaterialInstanceDynamic->SetTextureParameterValue(FName("My"), RemapMy); 94 | RemapMaterialInstanceDynamic->SetScalarParameterValue(FName("Mwidth"), RemapMx->GetSizeX()); 95 | RemapMaterialInstanceDynamic->SetScalarParameterValue(FName("Mheight"), RemapMx->GetSizeY()); 96 | FMatrix ProjectionMatrixLeft = GEngine->StereoRenderingDevice->GetStereoProjectionMatrix(EStereoscopicPass::eSSP_LEFT_EYE); 97 | RemapMaterialInstanceDynamic->SetScalarParameterValue(FName("OCxLeft"), ProjectionMatrixLeft.M[2][0] /2 + 0.5); 98 | RemapMaterialInstanceDynamic->SetScalarParameterValue(FName("OCyLeft"), -ProjectionMatrixLeft.M[2][1] /2 + 0.5); 99 | FMatrix ProjectionMatrixRight = GEngine->StereoRenderingDevice->GetStereoProjectionMatrix(EStereoscopicPass::eSSP_RIGHT_EYE); 100 | RemapMaterialInstanceDynamic->SetScalarParameterValue(FName("OCxRight"), ProjectionMatrixRight.M[2][0] /2 + 0.5); 101 | RemapMaterialInstanceDynamic->SetScalarParameterValue(FName("OCyRight"), -ProjectionMatrixRight.M[2][1] /2 + 0.5); 102 | Camera->AddOrUpdateBlendable(RemapMaterialInstanceDynamic, 1.0f); 103 | } -------------------------------------------------------------------------------- /Stereolabs/Source/ZED/Private/Engine/ZEDGameInstance.cpp: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #include "ZEDPrivatePCH.h" 4 | #include "ZED/Classes/ZEDGameInstance.h" 5 | #include "Stereolabs/Public/Core/StereolabsCameraProxy.h" 6 | 7 | #if WITH_EDITOR 8 | void InitializeCameraProxy(UZEDGameInstance& GameInstance) 9 | { 10 | // Uncomment if dedicated server is not supported 11 | //if (GEngine && GWorld) 12 | //{ 13 | // ENetMode Mode = GEngine->GetNetMode(GWorld); 14 | // 15 | // if (Mode == ENetMode::NM_Client || 16 | // Mode == ENetMode::NM_Standalone || 17 | // Mode == ENetMode::NM_ListenServer) 18 | // { 19 | CreateSlCameraProxyInstance(); 20 | // } 21 | //} 22 | } 23 | #endif 24 | 25 | void UZEDGameInstance::Init() 26 | { 27 | Super::Init(); 28 | 29 | // Uncomment if dedicated server is not supported 30 | //if (!IsDedicatedServerInstance()) 31 | //{ 32 | CreateSlCameraProxyInstance(); 33 | //} 34 | } 35 | 36 | void UZEDGameInstance::Shutdown() 37 | { 38 | FreeSlCameraProxyInstance(); 39 | 40 | if (GEngine) 41 | { 42 | GEngine->ForceGarbageCollection(true); 43 | } 44 | 45 | Super::Shutdown(); 46 | } 47 | 48 | #if WITH_EDITOR 49 | FGameInstancePIEResult UZEDGameInstance::InitializeForPlayInEditor(int32 PIEInstanceIndex, const FGameInstancePIEParameters& Params) 50 | { 51 | FGameInstancePIEResult Result = Super::InitializeForPlayInEditor(PIEInstanceIndex, Params); 52 | 53 | if (Result.bSuccess) 54 | { 55 | InitializeCameraProxy(*this); 56 | } 57 | 58 | return Result; 59 | } 60 | 61 | FGameInstancePIEResult UZEDGameInstance::StartPlayInEditorGameInstance(ULocalPlayer* LocalPlayer, const FGameInstancePIEParameters& Params) 62 | { 63 | FGameInstancePIEResult Result = Super::StartPlayInEditorGameInstance(LocalPlayer, Params); 64 | 65 | if (Result.bSuccess) 66 | { 67 | InitializeCameraProxy(*this); 68 | } 69 | 70 | return Result; 71 | } 72 | #endif -------------------------------------------------------------------------------- /Stereolabs/Source/ZED/Private/HUD/ZEDWidget.cpp: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #include "ZEDPrivatePCH.h" 4 | #include "ZED/Public/HUD/ZEDWidget.h" 5 | #include "Stereolabs/Public/Utilities/StereolabsFunctionLibrary.h" 6 | 7 | UZEDWidget::UZEDWidget() 8 | { 9 | WidgetComponent = CreateDefaultSubobject(MakeUniqueObjectName(this, UZEDWidgetComponent::StaticClass(), "WidgetComponent")); 10 | WidgetComponent->SetupAttachment(this); 11 | } 12 | 13 | void UZEDWidget::SetVisibility(bool bNewVisibility, bool bPropagateToChildren) 14 | { 15 | Super::SetVisibility(bNewVisibility, bPropagateToChildren); 16 | 17 | WidgetComponent->SetVisibility(bNewVisibility, true); 18 | } 19 | 20 | EWidgetSpace UZEDWidget::GetWidgetSpace() 21 | { 22 | return WidgetComponent->GetWidgetSpace(); 23 | } 24 | 25 | void UZEDWidget::SetWidgetSpace(EWidgetSpace NewWidgetSpace) 26 | { 27 | WidgetComponent->SetWidgetSpace(NewWidgetSpace); 28 | } 29 | 30 | void UZEDWidget::SetText(const FText& NewText) 31 | { 32 | WidgetComponent->SetText(NewText); 33 | } 34 | 35 | void UZEDWidget::SetFontSize(int32 NewSize) 36 | { 37 | WidgetComponent->SetFontSize(NewSize); 38 | } 39 | 40 | void UZEDWidget::SetTextColorAndOpacity(const FLinearColor& NewColor) 41 | { 42 | WidgetComponent->SetTextColorAndOpacity(NewColor); 43 | } 44 | 45 | void UZEDWidget::FadeIn() 46 | { 47 | WidgetComponent->FadeIn(); 48 | } 49 | 50 | void UZEDWidget::FadeOut() 51 | { 52 | WidgetComponent->FadeOut(); 53 | } -------------------------------------------------------------------------------- /Stereolabs/Source/ZED/Private/HUD/ZEDWidgetComponent.cpp: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #include "ZEDPrivatePCH.h" 4 | #include "ZED/Public/HUD/ZEDWidgetComponent.h" 5 | #include "UMG.h" 6 | 7 | #define GET_TEXT_BLOCK() static_cast(GetUserWidgetObject()->WidgetTree->FindWidget(TEXT("Text"))) 8 | 9 | UZEDWidgetComponent::UZEDWidgetComponent() 10 | { 11 | static ConstructorHelpers::FObjectFinder FadeCurve(TEXT("CurveFloat'/Stereolabs/ZED/Utility/C_Fade.C_Fade'")); 12 | FadeTimelineCurve = FadeCurve.Object; 13 | 14 | FadeTimeline = CreateDefaultSubobject("FadeTimeline"); 15 | FadeTimeline->SetTimelineLength(0.75f); 16 | 17 | FadeFunction.BindUFunction(this, "Fading"); 18 | FadeTimeline->AddInterpFloat(FadeTimelineCurve, FadeFunction); 19 | } 20 | 21 | void UZEDWidgetComponent::SetText(const FText& NewText) 22 | { 23 | UTextBlock* TextBlock = GET_TEXT_BLOCK(); 24 | TextBlock->SetText(NewText); 25 | } 26 | 27 | void UZEDWidgetComponent::SetFontSize(int32 NewSize) 28 | { 29 | UTextBlock* TextBlock = GET_TEXT_BLOCK(); 30 | TextBlock->Font.Size = NewSize; 31 | } 32 | 33 | void UZEDWidgetComponent::SetTextColorAndOpacity(const FLinearColor& NewColor) 34 | { 35 | UTextBlock* TextBlock = GET_TEXT_BLOCK(); 36 | TextBlock->SetColorAndOpacity(NewColor); 37 | } 38 | 39 | void UZEDWidgetComponent::FadeIn() 40 | { 41 | FadeTimeline->PlayFromStart(); 42 | } 43 | 44 | void UZEDWidgetComponent::FadeOut() 45 | { 46 | FadeTimeline->ReverseFromEnd(); 47 | } 48 | 49 | void UZEDWidgetComponent::SetGeometryMode(EWidgetGeometryMode NewGeometryMode) 50 | { 51 | GeometryMode = NewGeometryMode; 52 | } 53 | 54 | void UZEDWidgetComponent::SetCylinderArcAngle(float NewCylinderArcAngle) 55 | { 56 | CylinderArcAngle = NewCylinderArcAngle; 57 | } 58 | 59 | void UZEDWidgetComponent::Fading(float FadingFactor) 60 | { 61 | SetTintColorAndOpacity(FLinearColor(1.0f, 1.0f, 1.0f, FadingFactor)); 62 | } -------------------------------------------------------------------------------- /Stereolabs/Source/ZED/Private/ZED.cpp: -------------------------------------------------------------------------------- 1 | #include "ZEDPrivatePCH.h" 2 | 3 | #define LOCTEXT_NAMESPACE "FStereolabsZED" 4 | 5 | void FStereolabsZED::StartupModule() 6 | { 7 | // This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module 8 | } 9 | 10 | void FStereolabsZED::ShutdownModule() 11 | { 12 | // This function may be called during shutdown to clean up your module. For modules that support dynamic reloading, 13 | // we call this function before unloading the module. 14 | } 15 | 16 | #undef LOCTEXT_NAMESPACE 17 | 18 | IMPLEMENT_MODULE(FStereolabsZED, ZED) -------------------------------------------------------------------------------- /Stereolabs/Source/ZED/Private/ZEDPrivatePCH.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "ZED.h" 6 | 7 | #include "Engine.h" 8 | #include "CoreUObject.h" 9 | #include "GameFramework/Actor.h" 10 | 11 | #include "Stereolabs/Public/Core/StereolabsCoreUtilities.h" -------------------------------------------------------------------------------- /Stereolabs/Source/ZED/Public/Core/ZEDBaseTypes.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "Stereolabs/Public/Core/StereolabsBaseTypes.h" 6 | 7 | #include "ZEDBaseTypes.generated.h" 8 | 9 | 10 | /* 11 | * Tracking data of the camera 12 | */ 13 | USTRUCT(BlueprintType, Category = "ZED|Struct") 14 | struct ZED_API FZEDTrackingData 15 | { 16 | GENERATED_BODY() 17 | 18 | FZEDTrackingData() 19 | : 20 | TrackingState(ESlTrackingState::TS_TrackingOff), 21 | Timestamp((sl::Timestamp)0), 22 | OffsetZedWorldTransform(FTransform::Identity), 23 | ZedWorldTransform(FTransform::Identity), 24 | ZedPathTransform(FTransform::Identity), 25 | IMURotator(FRotator::ZeroRotator) 26 | { 27 | } 28 | 29 | /** Tracking state */ 30 | UPROPERTY(BlueprintReadWrite) 31 | ESlTrackingState TrackingState; 32 | 33 | /** Timestamp */ 34 | UPROPERTY(BlueprintReadWrite) 35 | FSlTimestamp Timestamp; 36 | 37 | /** Zed world space transform relative to the head with anti drift if using an HMD */ 38 | UPROPERTY(BlueprintReadWrite) 39 | FTransform OffsetZedWorldTransform; 40 | 41 | /** Zed world space transform with anti drift if using an HMD */ 42 | UPROPERTY(BlueprintReadWrite) 43 | FTransform ZedWorldTransform; 44 | 45 | /** Raw path transform from tracking origin */ 46 | UPROPERTY(BlueprintReadWrite) 47 | FTransform ZedPathTransform; 48 | 49 | /** IMU rotation */ 50 | UPROPERTY(BlueprintReadWrite) 51 | FRotator IMURotator; 52 | }; 53 | 54 | /* 55 | * Result of a hit test 56 | */ 57 | USTRUCT(BlueprintType, Category = "ZED|Struct") 58 | struct ZED_API FZEDHitResult 59 | { 60 | GENERATED_BODY() 61 | 62 | FZEDHitResult() 63 | : 64 | Location(FVector::ZeroVector), 65 | ImpactPoint(FVector::ZeroVector), 66 | Normal(FVector::ZeroVector), 67 | Depth(-1.0f), 68 | Distance(0.0f), 69 | bIsVisible(false), 70 | bIsBehind(false), 71 | bNormalValid(false) 72 | { 73 | } 74 | 75 | FORCEINLINE void Reset() 76 | { 77 | Location = FVector::ZeroVector; 78 | ImpactPoint = FVector::ZeroVector; 79 | Normal = FVector::ZeroVector; 80 | Depth = -1.0f; 81 | Distance = 0.0f; 82 | bIsVisible = false; 83 | bIsBehind = false; 84 | bNormalValid = false; 85 | } 86 | 87 | /** Location of the hit in world space */ 88 | UPROPERTY(BlueprintReadWrite) 89 | FVector Location = FVector::ZeroVector; 90 | 91 | /** Location of the actual contact point. Equal the tested world location. */ 92 | UPROPERTY(BlueprintReadWrite) 93 | FVector ImpactPoint = FVector::ZeroVector; 94 | 95 | /** Normal of the hit in world space */ 96 | UPROPERTY(BlueprintReadWrite) 97 | FVector Normal = FVector::ZeroVector; 98 | 99 | /** The depth of the hit */ 100 | UPROPERTY(BlueprintReadWrite) 101 | float Depth = -1.0f; 102 | 103 | /** The distance from the hit location to the player */ 104 | UPROPERTY(BlueprintReadWrite) 105 | float Distance = 0.0f; 106 | 107 | /** True if the location is visible by the player */ 108 | UPROPERTY(BlueprintReadWrite) 109 | bool bIsVisible = false; 110 | 111 | /* True if the ImpactPoint is behind real. 112 | * Always false if hit test "bHitIfBehind" set to false. 113 | */ 114 | UPROPERTY(BlueprintReadWrite) 115 | bool bIsBehind = false; 116 | 117 | /** True if the normal is valid */ 118 | UPROPERTY(BlueprintReadWrite) 119 | bool bNormalValid = false; 120 | }; 121 | 122 | /* 123 | * RGB noise factors 124 | */ 125 | struct ZED_API FZEDNoiseFactors 126 | { 127 | FZEDNoiseFactors() 128 | : 129 | R(FVector2D::ZeroVector), 130 | G(FVector2D::ZeroVector), 131 | B(FVector2D::ZeroVector) 132 | { 133 | } 134 | 135 | FZEDNoiseFactors(const FVector2D& R, 136 | const FVector2D& G, 137 | const FVector2D& B) 138 | : 139 | R(R), 140 | G(G), 141 | B(B) 142 | { 143 | } 144 | 145 | bool IsZeroed() 146 | { 147 | return R == FVector2D::ZeroVector && G == FVector2D::ZeroVector && B == FVector2D::ZeroVector; 148 | } 149 | 150 | FVector2D R; 151 | FVector2D G; 152 | FVector2D B; 153 | }; 154 | 155 | /* 156 | * Camera calibration for external view 157 | */ 158 | USTRUCT(BlueprintType, Category = "ZED|Struct") 159 | struct ZED_API FZEDExternalViewParameters 160 | { 161 | GENERATED_BODY() 162 | 163 | FZEDExternalViewParameters(FVector Location = FVector::ZeroVector, FRotator Rotation = FRotator::ZeroRotator) 164 | : 165 | Location(Location), 166 | Rotation(Rotation) 167 | { 168 | } 169 | 170 | FORCEINLINE void Load(const FString& Path, const TCHAR* Section = TEXT("Calibration")) 171 | { 172 | float X; 173 | float Y; 174 | float Z; 175 | float Yaw; 176 | float Pitch; 177 | float Roll; 178 | 179 | GConfig->GetFloat( 180 | Section, 181 | TEXT("x"), 182 | X, 183 | *Path 184 | ); 185 | GConfig->GetFloat( 186 | Section, 187 | TEXT("y"), 188 | Y, 189 | *Path 190 | ); 191 | GConfig->GetFloat( 192 | Section, 193 | TEXT("z"), 194 | Z, 195 | *Path 196 | ); 197 | 198 | GConfig->GetFloat( 199 | Section, 200 | TEXT("rx"), 201 | Pitch, 202 | *Path 203 | ); 204 | GConfig->GetFloat( 205 | Section, 206 | TEXT("ry"), 207 | Yaw, 208 | *Path 209 | ); 210 | GConfig->GetFloat( 211 | Section, 212 | TEXT("rz"), 213 | Roll, 214 | *Path 215 | ); 216 | 217 | Location = FVector(Z, X, Y) * 100.0f; 218 | Rotation = FRotator(-Pitch, Yaw, Roll); 219 | } 220 | 221 | FVector Location; 222 | FRotator Rotation; 223 | }; -------------------------------------------------------------------------------- /Stereolabs/Source/ZED/Public/Core/ZEDCoreGlobals.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "ZED/Public/Core/ZEDBaseTypes.h" 6 | 7 | #include "sl_mr_core/defines.hpp" 8 | 9 | /** Current frame tracking data */ 10 | extern ZED_API FZEDTrackingData GZedTrackingData; 11 | 12 | /** Current Zed rotation (stereo/mono). Same as GZedViewPointRotation in mono. Antidrifted rotation in stereo. */ 13 | extern ZED_API FRotator GZedRawRotation; 14 | 15 | /** Current Zed location (stereo/mono). Same as GZedViewPointLocation in mono. Antidrifted location in stereo. */ 16 | extern ZED_API FVector GZedRawLocation; 17 | 18 | /** Current view point rotation, head(stereo)/camera(mono) */ 19 | extern ZED_API FRotator GZedViewPointRotation; 20 | 21 | /** Current view point location, head(stereo)/camera(mono) */ 22 | extern ZED_API FVector GZedViewPointLocation; 23 | 24 | namespace sl 25 | { 26 | namespace unreal 27 | { 28 | /* 29 | * Convert from FZEDTrackingData to sl::mr::trackingData 30 | */ 31 | FORCEINLINE sl::mr::trackingData ToSlType(const FZEDTrackingData& UnrealType) 32 | { 33 | sl::mr::trackingData TrackingData; 34 | 35 | TrackingData.zedPathTransform = sl::unreal::ToSlType(UnrealType.ZedPathTransform); 36 | TrackingData.zedWorldTransform = sl::unreal::ToSlType(UnrealType.ZedWorldTransform); 37 | TrackingData.trackingState = sl::unreal::ToSlType(UnrealType.TrackingState); 38 | 39 | return TrackingData; 40 | } 41 | 42 | /* 43 | * Convert from sl::mr::noiseFactors to FZEDNoiseFactors 44 | */ 45 | FORCEINLINE FZEDNoiseFactors ToUnrealType(const sl::mr::noiseFactors& SlData) 46 | { 47 | return FZEDNoiseFactors(sl::unreal::ToUnrealType(SlData.r), sl::unreal::ToUnrealType(SlData.g), sl::unreal::ToUnrealType(SlData.b)); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /Stereolabs/Source/ZED/Public/Core/ZEDInitializer.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "Stereolabs/Public/Core/StereolabsBaseTypes.h" 6 | #include "ZED/Public/Core/ZEDBaseTypes.h" 7 | 8 | #include "ZEDInitializer.generated.h" 9 | 10 | 11 | /* 12 | * Actor used to initialize Zed camera using configuration file 13 | */ 14 | UCLASS(Category = "Stereolabs|Zed") 15 | class ZED_API AZEDInitializer : public AActor 16 | { 17 | GENERATED_BODY() 18 | 19 | public: 20 | AZEDInitializer(); 21 | 22 | #if WITH_EDITOR 23 | virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override; 24 | virtual bool CanEditChange(const UProperty* InProperty) const override; 25 | #endif 26 | 27 | public: 28 | /* 29 | * Load all parameters and settings 30 | */ 31 | UFUNCTION(BlueprintCallable, Category="Zed") 32 | void LoadParametersAndSettings(); 33 | 34 | /* 35 | * Load config parameters 36 | */ 37 | UFUNCTION(BlueprintCallable, Category = "Zed") 38 | void LoadParameters(); 39 | 40 | /* 41 | * Load camera settings 42 | */ 43 | UFUNCTION(BlueprintCallable, Category = "Zed") 44 | void LoadCameraSettings(); 45 | 46 | /* 47 | * Load config parameters 48 | */ 49 | UFUNCTION(BlueprintCallable, Category = "Zed") 50 | void SaveParameters(); 51 | 52 | /* 53 | * Load camera settings 54 | */ 55 | UFUNCTION(BlueprintCallable, Category = "Zed") 56 | void SaveCameraSettings(); 57 | 58 | /* 59 | * Reset parameters 60 | */ 61 | UFUNCTION(BlueprintCallable, Category = "Zed") 62 | void ResetParameters(); 63 | 64 | /* 65 | * Reset camera settings 66 | */ 67 | UFUNCTION(BlueprintCallable, Category = "Zed") 68 | void ResetSettings(); 69 | 70 | private: 71 | /* 72 | * Load anti drift parameters 73 | */ 74 | void LoadAntiDriftParameters(); 75 | 76 | public: 77 | /** Init parameters */ 78 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Zed") 79 | FSlInitParameters InitParameters; 80 | 81 | /** Tracking parameters */ 82 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Zed") 83 | FSlPositionalTrackingParameters TrackingParameters; 84 | 85 | /** Init parameters */ 86 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Zed") 87 | FSlSVOParameters SVOParameters; 88 | 89 | /** Runtime parameters */ 90 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Zed") 91 | FSlRuntimeParameters RuntimeParameters; 92 | 93 | /** Rendering parameters */ 94 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Zed") 95 | FSlRenderingParameters RenderingParameters; 96 | 97 | /** Camera settings */ 98 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Zed") 99 | FSlVideoSettings CameraSettings; 100 | 101 | /** Actors that will be attached to the pawn at startup. Actor's Transform will be local, and body weld. */ 102 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Zed") 103 | TArray ChildActors; 104 | 105 | /** Load parameters at runtime from config file and override preset */ 106 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Zed") 107 | uint8 bLoadParametersFromConfigFile:1; 108 | 109 | /** Load camera settings at runtime from config file and override preset */ 110 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Zed") 111 | uint8 bLoadCameraSettingsFromConfigFile:1; 112 | 113 | /* 114 | * Use the HMD transform as tracking origin, else the HMD tracking origin is reset. 115 | * Enable if the player must match his real world location/rotation. 116 | * Not loaded from config file 117 | */ 118 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Zed") 119 | uint8 bUseHMDTrackingAsOrigin:1; 120 | 121 | public: 122 | /** Calibration parameters */ 123 | FSlAntiDriftParameters AntiDriftParameters; 124 | 125 | /** Parameters for external view */ 126 | FZEDExternalViewParameters ExternalViewParameters; 127 | }; -------------------------------------------------------------------------------- /Stereolabs/Source/ZED/Public/Core/ZEDPawn.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "Zed/Public/HUD/ZEDWidget.h" 6 | #include "ZED/Public/Core/ZEDCamera.h" 7 | #include "ZED/Public/Core/ZEDBaseTypes.h" 8 | 9 | #include "ZEDPawn.generated.h" 10 | 11 | /* 12 | * Base class for pawn using the Zed. 13 | * Inherit from this class and set the PawnClassType variable in the controller to spawn a pawn of your type. 14 | */ 15 | UCLASS(Category = "Stereolabs|Zed") 16 | class ZED_API AZEDPawn : public APawn 17 | { 18 | friend class AZEDPlayerController; 19 | 20 | GENERATED_BODY() 21 | 22 | public: 23 | AZEDPawn(); 24 | 25 | private: 26 | /* 27 | * Event binded to OnTrackingDataUpdated 28 | * @param NewTrackingData The new tracking data 29 | */ 30 | UFUNCTION() 31 | void ZedCameraTrackingUpdated(const FZEDTrackingData& NewTrackingData); 32 | 33 | /* 34 | * Initialisation 35 | */ 36 | void InitRemap(FName HMDname, sl::RESOLUTION camRes, float dp); 37 | 38 | public: 39 | /** Custom spring arm that offset the camera */ 40 | UPROPERTY() 41 | USceneComponent* SpringArm; 42 | 43 | /** Main camera */ 44 | UPROPERTY(EditAnywhere, BlueprintReadWrite) 45 | UCameraComponent* Camera; 46 | 47 | /** Zed loading widget */ 48 | UPROPERTY() 49 | UZEDWidget* ZedLoadingWidget; 50 | 51 | /** Zed error widget */ 52 | UPROPERTY() 53 | UZEDWidget* ZedErrorWidget; 54 | 55 | /** Remap material resource */ 56 | UPROPERTY() 57 | UMaterial* RemapSourceMaterial; 58 | 59 | /** Remap material*/ 60 | UPROPERTY(BlueprintReadWrite, Category = "Zed|Rendering") 61 | UMaterialInstanceDynamic* RemapMaterialInstanceDynamic; 62 | 63 | /** Remap Mx */ 64 | UPROPERTY() 65 | UTexture2D* RemapMx; 66 | 67 | /** Remap My */ 68 | UPROPERTY() 69 | UTexture2D* RemapMy; 70 | 71 | private: 72 | /** Zed loading source widget */ 73 | UPROPERTY() 74 | UClass* ZedLoadingSourceWidget; 75 | 76 | /** Zed error source widget */ 77 | UPROPERTY() 78 | UClass* ZedErrorSourceWidget; 79 | 80 | /** Zed widget material */ 81 | UPROPERTY() 82 | UMaterial* ZedWidgetSourceMaterial; 83 | }; 84 | -------------------------------------------------------------------------------- /Stereolabs/Source/ZED/Public/HUD/ZEDWidget.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "ZED/Public/HUD/ZEDWidgetComponent.h" 6 | 7 | #include "ZEDWidget.generated.h" 8 | 9 | UCLASS() 10 | class ZED_API UZEDWidget : public USceneComponent 11 | { 12 | GENERATED_BODY() 13 | 14 | public: 15 | UZEDWidget(); 16 | 17 | public: 18 | /* 19 | * Set the widget visibility 20 | * @param bNewVisibility The new visibility 21 | * @param bPropagateToChildren True to propagate to children 22 | */ 23 | void SetVisibility(bool bNewVisibility, bool bPropagateToChildren=false); 24 | 25 | /* 26 | * @return The current widget space 27 | */ 28 | UFUNCTION(BlueprintCallable, Category = "Zed") 29 | EWidgetSpace GetWidgetSpace(); 30 | 31 | /* 32 | * Set the widget space 33 | * @param NewWidgetSpace The new widget space 34 | */ 35 | UFUNCTION(BlueprintCallable, Category = "Zed") 36 | void SetWidgetSpace(EWidgetSpace NewWidgetSpace); 37 | 38 | /* 39 | * Set the widget text 40 | * @param NewText The new text 41 | */ 42 | UFUNCTION(BlueprintCallable, Category = "Zed") 43 | void SetText(const FText& NewText); 44 | 45 | /* 46 | * Set the widget size 47 | * @param NewSize The new size 48 | */ 49 | UFUNCTION(BlueprintCallable, Category = "Zed") 50 | void SetFontSize(int32 NewSize); 51 | 52 | /* 53 | * Set the color and opacity 54 | * @param NewColor The new color and opacity 55 | */ 56 | UFUNCTION(BlueprintCallable, Category = "Zed") 57 | void SetTextColorAndOpacity(const FLinearColor& NewColor); 58 | 59 | /* 60 | * Fade in the widget 61 | */ 62 | UFUNCTION(BlueprintCallable, Category = "Zed") 63 | void FadeIn(); 64 | 65 | /* 66 | * Fade out the widget 67 | */ 68 | UFUNCTION(BlueprintCallable, Category = "Zed") 69 | void FadeOut(); 70 | 71 | public: 72 | /** Widget component */ 73 | UZEDWidgetComponent* WidgetComponent; 74 | }; -------------------------------------------------------------------------------- /Stereolabs/Source/ZED/Public/HUD/ZEDWidgetComponent.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "Components/WidgetComponent.h" 6 | 7 | #include "ZEDWidgetComponent.generated.h" 8 | 9 | UCLASS() 10 | class ZED_API UZEDWidgetComponent : public UWidgetComponent 11 | { 12 | GENERATED_BODY() 13 | 14 | public: 15 | UZEDWidgetComponent(); 16 | 17 | public: 18 | /** Set the text of the widget */ 19 | void SetText(const FText& NewText); 20 | 21 | /** Set the font size of the widget */ 22 | void SetFontSize(int32 NewSize); 23 | 24 | /** Set Color and opacity */ 25 | void SetTextColorAndOpacity(const FLinearColor& NewColor); 26 | 27 | /** Fade in */ 28 | void FadeIn(); 29 | 30 | /** Fade out */ 31 | void FadeOut(); 32 | 33 | /** Set geometry mode */ 34 | void SetGeometryMode(EWidgetGeometryMode NewGeometryMode); 35 | 36 | /**Set the cylinder arc angle */ 37 | void SetCylinderArcAngle(float NewCylinderArcAngle); 38 | 39 | private: 40 | /* 41 | * Timeline fade function 42 | */ 43 | UFUNCTION() 44 | void Fading(float FadingFactor); 45 | 46 | public: 47 | /** Fade timeline */ 48 | UPROPERTY(BlueprintReadWrite) 49 | UTimelineComponent* FadeTimeline; 50 | 51 | /** Fade timeline curve */ 52 | UPROPERTY(BlueprintReadWrite) 53 | UCurveFloat* FadeTimelineCurve; 54 | 55 | /** Fade function */ 56 | FOnTimelineFloat FadeFunction; 57 | }; -------------------------------------------------------------------------------- /Stereolabs/Source/ZED/Public/ZED.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "ModuleManager.h" 6 | 7 | class FStereolabsZED : public IModuleInterface 8 | { 9 | public: 10 | /** IModuleInterface implementation */ 11 | virtual void StartupModule() override; 12 | virtual void ShutdownModule() override; 13 | }; -------------------------------------------------------------------------------- /Stereolabs/Source/ZED/ZED.Build.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | using UnrealBuildTool; 3 | using System.IO; 4 | using System; 5 | 6 | public class ZED : ModuleRules 7 | { 8 | private string ModulePath 9 | { 10 | get { return ModuleDirectory; } 11 | } 12 | 13 | public string ProjectSavedConfigPathDirectory 14 | { 15 | get { return Path.GetFullPath(Path.Combine(ModulePath, "../../../../Saved/Config/ZED/")); } 16 | } 17 | 18 | public string ProjectConfigPathDirectory 19 | { 20 | get { return Path.GetFullPath(Path.Combine(ModulePath, "../../../../Config/")); } 21 | } 22 | 23 | 24 | public ZED(ReadOnlyTargetRules Target) : base(Target) 25 | { 26 | PrivatePCHHeaderFile = "ZED/Public/ZED.h"; 27 | 28 | PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "Public")); 29 | PrivateIncludePaths.Add(Path.Combine(ModuleDirectory, "Private")); 30 | 31 | PublicDependencyModuleNames.AddRange( 32 | new string[] 33 | { 34 | "Stereolabs", 35 | "MixedReality", 36 | 37 | "UMG", 38 | "Slate", 39 | "SlateCore" 40 | 41 | // ... add other public dependencies that you statically link with here ... 42 | } 43 | ); 44 | 45 | PrivateDependencyModuleNames.AddRange( 46 | new string[] 47 | { 48 | "Core", 49 | "CoreUObject", 50 | 51 | "Engine", 52 | 53 | "RenderCore", 54 | "ShaderCore", 55 | "InputCore", 56 | 57 | "HeadMountedDisplay", 58 | 59 | "RHI", 60 | "D3D11RHI" 61 | } 62 | ); 63 | 64 | string ZedConfigFileName = "ZED.ini"; 65 | string CameraConfigFileName = "Camera.ini"; 66 | string DefaultEngineConfigFileName = "DefaultEngine.ini"; 67 | 68 | string ZedConfigFilePath = ProjectSavedConfigPathDirectory + ZedConfigFileName; 69 | string CameraConfigFilePath = ProjectSavedConfigPathDirectory + CameraConfigFileName; 70 | string DefaultEngineConfigFilePath = ProjectConfigPathDirectory + DefaultEngineConfigFileName; 71 | 72 | // Set default engine settings 73 | if (!Directory.Exists(ProjectConfigPathDirectory)) 74 | { 75 | Directory.CreateDirectory(ProjectConfigPathDirectory); 76 | } 77 | 78 | if(!File.Exists(DefaultEngineConfigFilePath)) 79 | { 80 | File.Copy(Path.Combine(ModulePath, "Defaults", DefaultEngineConfigFileName), DefaultEngineConfigFilePath, true); 81 | } 82 | 83 | // Set default SDK settings 84 | if (!Directory.Exists(ProjectSavedConfigPathDirectory)) 85 | { 86 | Directory.CreateDirectory(ProjectSavedConfigPathDirectory); 87 | } 88 | 89 | // Copy files if they don't exist 90 | if (!File.Exists(ZedConfigFilePath)) 91 | { 92 | File.Copy(Path.Combine(ModulePath, "Defaults", ZedConfigFileName), ZedConfigFilePath, true); 93 | } 94 | if (!File.Exists(CameraConfigFilePath)) 95 | { 96 | File.Copy(Path.Combine(ModulePath, "Defaults", CameraConfigFileName), CameraConfigFilePath, true); 97 | } 98 | 99 | // Copy config file to shipped folder 100 | if (Target.Type != TargetRules.TargetType.Editor) 101 | { 102 | RuntimeDependencies.Add(ZedConfigFilePath, StagedFileType.NonUFS); 103 | RuntimeDependencies.Add(CameraConfigFilePath, StagedFileType.NonUFS); 104 | } 105 | 106 | // Calibration settings 107 | String MRFolderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Stereolabs\\mr"); 108 | 109 | // Create folder if it does not exist 110 | if (!Directory.Exists(MRFolderPath)) 111 | { 112 | Directory.CreateDirectory(MRFolderPath); 113 | } 114 | 115 | // Create the path to the file and the macro for C++ 116 | String CalibrationFilePathDefinition = "ZED_CALIBRAITON_FILE_PATH=" + "\"" + MRFolderPath + "\\Calibration.ini" + "\""; 117 | CalibrationFilePathDefinition = CalibrationFilePathDefinition.Replace("\\", "/"); 118 | 119 | // Add the definition for C++ 120 | PublicDefinitions.Add(CalibrationFilePathDefinition); 121 | 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /Stereolabs/Source/ZEDEditor/Private/ZEDEditorPlugin.cpp: -------------------------------------------------------------------------------- 1 | #include "ZEDEditorPrivatePCH.h" 2 | #include "ZEDEditor/Public/ZEDInitializerDetails.h" 3 | #include "ZEDEditor/Public/ZEDCameraDetails.h" 4 | #include "ZED/Public/Core/ZEDInitializer.h" 5 | #include "ZED/Public/Core/ZEDCamera.h" 6 | 7 | #define LOCTEXT_NAMESPACE "FStereolabsZEDEditor" 8 | 9 | void FStereolabsZEDEditor::StartupModule() 10 | { 11 | // This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module 12 | FPropertyEditorModule& PropertyModule = FModuleManager::LoadModuleChecked("PropertyEditor"); 13 | 14 | PropertyModule.RegisterCustomClassLayout(AZEDInitializer::StaticClass()->GetFName(), FOnGetDetailCustomizationInstance::CreateStatic(&FZEDInitializerDetails::MakeInstance)); 15 | PropertyModule.RegisterCustomClassLayout(AZEDCamera::StaticClass()->GetFName(), FOnGetDetailCustomizationInstance::CreateStatic(&FZEDCameraDetails::MakeInstance)); 16 | } 17 | 18 | void FStereolabsZEDEditor::ShutdownModule() 19 | { 20 | // This function may be called during shutdown to clean up your module. For modules that support dynamic reloading, 21 | // we call this function before unloading the module. 22 | 23 | FPropertyEditorModule& PropertyModule = FModuleManager::LoadModuleChecked("PropertyEditor"); 24 | PropertyModule.UnregisterCustomClassLayout(AZEDCamera::StaticClass()->GetFName()); 25 | PropertyModule.UnregisterCustomClassLayout(AZEDInitializer::StaticClass()->GetFName()); 26 | } 27 | 28 | #undef LOCTEXT_NAMESPACE 29 | 30 | IMPLEMENT_MODULE(FStereolabsZEDEditor, ZEDEditor) -------------------------------------------------------------------------------- /Stereolabs/Source/ZEDEditor/Private/ZEDEditorPrivatePCH.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "ZEDEditorPlugin.h" 6 | 7 | #include "Engine.h" 8 | #include "CoreUObject.h" 9 | #include "UnrealEd.h" 10 | #include "PropertyEditorModule.h" 11 | #include "DetailLayoutBuilder.h" 12 | #include "DetailCategoryBuilder.h" 13 | #include "DetailWidgetRow.h" 14 | #include "IDetailsView.h" -------------------------------------------------------------------------------- /Stereolabs/Source/ZEDEditor/Private/ZEDInitializerDetails.cpp: -------------------------------------------------------------------------------- 1 | #include "ZEDEditor/Private/ZEDEditorPrivatePCH.h" 2 | #include "ZEDEditor/Public/ZEDInitializerDetails.h" 3 | #include "ZED/Public/Core/ZEDInitializer.h" 4 | 5 | TSharedRef FZEDInitializerDetails::MakeInstance() 6 | { 7 | return MakeShareable(new FZEDInitializerDetails); 8 | } 9 | 10 | void FZEDInitializerDetails::CustomizeDetails(IDetailLayoutBuilder& DetailBuilder) 11 | { 12 | IDetailCategoryBuilder& Category = DetailBuilder.EditCategory("Zed"); 13 | 14 | const FText FilterString = FText::FromString("parameters settings"); 15 | 16 | const FText LoadParamettersText = FText::FromString("Load parameters"); 17 | const FText SaveParamettersText = FText::FromString("Save parameters"); 18 | const FText LoadSettingsText = FText::FromString("Load settings"); 19 | const FText SaveSettingsText = FText::FromString("Save settings"); 20 | const FText ResetParamettersText = FText::FromString("Reset parameters"); 21 | const FText ResetSettingsText = FText::FromString("Reset settings"); 22 | 23 | // Cache set of selected things 24 | SelectedObjects = DetailBuilder.GetDetailsView()->GetSelectedObjects(); 25 | 26 | Category.AddCustomRow(FilterString, false) 27 | .NameContent() 28 | [ 29 | SNullWidget::NullWidget 30 | ] 31 | .ValueContent() 32 | .VAlign(VAlign_Center) 33 | .MaxDesiredWidth(350) 34 | [ 35 | SNew(SBox) 36 | .MinDesiredWidth(350) 37 | [ 38 | SNew( SHorizontalBox ) 39 | + SHorizontalBox::Slot() 40 | .VAlign(VAlign_Center) 41 | .Padding(2.0f) 42 | .MaxWidth(150) 43 | [ 44 | SNew(SButton) 45 | .VAlign(VAlign_Center) 46 | .ToolTipText(FText::FromString("Load parameters from config file")) 47 | .OnClicked(this, &FZEDInitializerDetails::OnClickLoadParameters) 48 | .IsEnabled(this, &FZEDInitializerDetails::IsEnabled) 49 | .Content() 50 | [ 51 | SNew(STextBlock) 52 | .Justification(ETextJustify::Center) 53 | .Text(LoadParamettersText) 54 | ] 55 | ] 56 | + SHorizontalBox::Slot() 57 | .VAlign(VAlign_Center) 58 | .Padding(2.0f) 59 | .MaxWidth(150) 60 | [ 61 | SNew(SButton) 62 | .VAlign(VAlign_Center) 63 | .ToolTipText(FText::FromString("Save parameters to config file")) 64 | .OnClicked(this, &FZEDInitializerDetails::OnClickSaveParameters) 65 | .IsEnabled(this, &FZEDInitializerDetails::IsEnabled) 66 | .Content() 67 | [ 68 | SNew(STextBlock) 69 | .Justification(ETextJustify::Center) 70 | .Text(SaveParamettersText) 71 | ] 72 | ] 73 | + SHorizontalBox::Slot() 74 | .VAlign(VAlign_Center) 75 | .Padding(2.0f) 76 | .MaxWidth(150) 77 | [ 78 | SNew(SButton) 79 | .VAlign(VAlign_Center) 80 | .ToolTipText(FText::FromString("Reset parameters")) 81 | .OnClicked(this, &FZEDInitializerDetails::OnClickResetParameters) 82 | .IsEnabled(this, &FZEDInitializerDetails::IsEnabled) 83 | .Content() 84 | [ 85 | SNew(STextBlock) 86 | .Justification(ETextJustify::Center) 87 | .Text(ResetParamettersText) 88 | ] 89 | ] 90 | ] 91 | ]; 92 | 93 | Category.AddCustomRow(FilterString, false) 94 | .NameContent() 95 | [ 96 | SNullWidget::NullWidget 97 | ] 98 | .ValueContent() 99 | .VAlign(VAlign_Center) 100 | .MaxDesiredWidth(350) 101 | [ 102 | SNew(SBox) 103 | .MinDesiredWidth(350) 104 | [ 105 | SNew( SHorizontalBox ) 106 | + SHorizontalBox::Slot() 107 | .VAlign(VAlign_Center) 108 | .Padding(2.0f) 109 | .MaxWidth(150) 110 | [ 111 | SNew(SButton) 112 | .VAlign(VAlign_Center) 113 | .ToolTipText(FText::FromString("Load camera settings from config file")) 114 | .OnClicked(this, &FZEDInitializerDetails::OnClickLoadSettings) 115 | .IsEnabled(this, &FZEDInitializerDetails::IsEnabled) 116 | .Content() 117 | [ 118 | SNew(STextBlock) 119 | .Justification(ETextJustify::Center) 120 | .Text(LoadSettingsText) 121 | ] 122 | ] 123 | + SHorizontalBox::Slot() 124 | .VAlign(VAlign_Center) 125 | .Padding(2.0f) 126 | .MaxWidth(150) 127 | [ 128 | SNew(SButton) 129 | .VAlign(VAlign_Center) 130 | .ToolTipText(FText::FromString("Save camera settings to config file")) 131 | .OnClicked(this, &FZEDInitializerDetails::OnClickSaveSettings) 132 | .IsEnabled(this, &FZEDInitializerDetails::IsEnabled) 133 | .Content() 134 | [ 135 | SNew(STextBlock) 136 | .Justification(ETextJustify::Center) 137 | .Text(SaveSettingsText) 138 | ] 139 | ] 140 | + SHorizontalBox::Slot() 141 | .VAlign(VAlign_Center) 142 | .Padding(2.0f) 143 | .MaxWidth(150) 144 | [ 145 | SNew(SButton) 146 | .VAlign(VAlign_Center) 147 | .ToolTipText(FText::FromString("Reset camera settings")) 148 | .OnClicked(this, &FZEDInitializerDetails::OnClickResetSettings) 149 | .IsEnabled(this, &FZEDInitializerDetails::IsEnabled) 150 | .Content() 151 | [ 152 | SNew(STextBlock) 153 | .Justification(ETextJustify::Center) 154 | .Text(ResetSettingsText) 155 | ] 156 | ] 157 | ] 158 | ]; 159 | } 160 | 161 | FReply FZEDInitializerDetails::OnClickResetParameters() 162 | { 163 | AZEDInitializer* Initializer = static_cast(SelectedObjects[0].Get()); 164 | 165 | Initializer->ResetParameters(); 166 | 167 | return FReply::Handled(); 168 | } 169 | 170 | FReply FZEDInitializerDetails::OnClickResetSettings() 171 | { 172 | AZEDInitializer* Initializer = static_cast(SelectedObjects[0].Get()); 173 | 174 | Initializer->ResetSettings(); 175 | 176 | return FReply::Handled(); 177 | } 178 | 179 | FReply FZEDInitializerDetails::OnClickSaveParameters() 180 | { 181 | AZEDInitializer* Initializer = static_cast(SelectedObjects[0].Get()); 182 | 183 | Initializer->SaveParameters(); 184 | 185 | return FReply::Handled(); 186 | } 187 | 188 | FReply FZEDInitializerDetails::OnClickLoadParameters() 189 | { 190 | AZEDInitializer* Initializer = static_cast(SelectedObjects[0].Get()); 191 | 192 | Initializer->LoadParameters(); 193 | 194 | return FReply::Handled(); 195 | } 196 | 197 | FReply FZEDInitializerDetails::OnClickSaveSettings() 198 | { 199 | AZEDInitializer* Initializer = static_cast(SelectedObjects[0].Get()); 200 | 201 | Initializer->SaveCameraSettings(); 202 | 203 | return FReply::Handled(); 204 | } 205 | 206 | FReply FZEDInitializerDetails::OnClickLoadSettings() 207 | { 208 | AZEDInitializer* Initializer = static_cast(SelectedObjects[0].Get()); 209 | 210 | Initializer->LoadCameraSettings(); 211 | 212 | return FReply::Handled(); 213 | } 214 | -------------------------------------------------------------------------------- /Stereolabs/Source/ZEDEditor/Public/ZEDCameraDetails.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "Stereolabs/Public/Core/StereolabsCameraProxy.h" 6 | #include "IDetailCustomization.h" 7 | #include "DetailLayoutBuilder.h" 8 | 9 | class FZEDCameraDetails : public IDetailCustomization 10 | { 11 | public: 12 | ~FZEDCameraDetails(); 13 | 14 | /** Makes a new instance of this detail layout class for a specific detail view requesting it */ 15 | static TSharedRef MakeInstance(); 16 | 17 | /** IDetailCustomization interface */ 18 | virtual void CustomizeDetails(IDetailLayoutBuilder& DetailBuilder) override; 19 | 20 | /** Button enabled */ 21 | bool IsSVORecordingEnabled() const { return GSlCameraProxy && GSlCameraProxy->bSVORecordingEnabled && GSlCameraProxy->GetSVONumberOfFrames() == -1; } 22 | 23 | /** Button enabled */ 24 | bool IsSVORecordingDisabled() const { return GSlCameraProxy && !GSlCameraProxy->bSVORecordingEnabled && GSlCameraProxy->GetSVONumberOfFrames() == -1; } 25 | 26 | /** Button enabled */ 27 | bool IsSVORecordingStarted() const { return IsSVORecordingEnabled() && GSlCameraProxy->bSVORecordingFrames; } 28 | 29 | /** Button enabled */ 30 | bool IsSVORecordingStopped() const { return IsSVORecordingEnabled() && !GSlCameraProxy->bSVORecordingFrames; } 31 | 32 | /** Clicking the enable SVO recording button */ 33 | FReply OnClickEnableSVORecording(); 34 | 35 | /** Clicking the disable SVO recording button */ 36 | FReply OnClickDisableSVORecording(); 37 | 38 | /** Clicking the start SVO recording button */ 39 | FReply OnClickStartSVORecording(); 40 | 41 | /** Clicking the stop SVO recording button */ 42 | FReply OnClickStopSVORecording(); 43 | 44 | /** Button enabled */ 45 | bool IsSVOPlaybackEnabled() const { return GSlCameraProxy && GSlCameraProxy->GetSVONumberOfFrames() > -1; } 46 | 47 | /** Button enabled */ 48 | bool IsSVOPlaybackPaused() const { return IsSVOPlaybackEnabled() && GSlCameraProxy->bSVOPlaybackPaused; } 49 | 50 | /** Button enabled */ 51 | bool IsSVOPlaybackNotPaused() const { return IsSVOPlaybackEnabled() && !GSlCameraProxy->bSVOPlaybackPaused; } 52 | 53 | /** Clicking the pause SVO playback button */ 54 | FReply OnClickPauseSVOPlayback(); 55 | 56 | /** Clicking the resume SVO playback button */ 57 | FReply OnClickResumeSVOPlayback(); 58 | 59 | /** Clicking the resume SVO playback button */ 60 | FReply OnClickNextFrameSVOPlayback(); 61 | 62 | /** Clicking the resume SVO playback button */ 63 | FReply OnClickPreviousFrameSVOPlayback(); 64 | 65 | /** Button enabled */ 66 | bool IsTrackingEnabled() const { return GSlCameraProxy && GSlCameraProxy->IsTrackingEnabled(); } 67 | 68 | /** Button enabled */ 69 | bool IsTrackingDisabled() const { return GSlCameraProxy && !GSlCameraProxy->IsTrackingEnabled(); } 70 | 71 | /** Button enabled */ 72 | bool IsSpatialMappingEnabled() const { return GSlCameraProxy && GSlCameraProxy->bSpatialMappingEnabled; } 73 | 74 | /** Clicking the reset tracking button */ 75 | FReply OnClickResetTracking(); 76 | 77 | /** Clicking the enable tracking button */ 78 | FReply OnClickEnableTracking(); 79 | 80 | /** Clicking the disable tracking button */ 81 | FReply OnClickDisableTracking(); 82 | 83 | /** Clicking the save tracking area button */ 84 | FReply OnClickSaveTrackingArea(); 85 | 86 | private: 87 | void OnMouseCaptureSVOPlaybackSlider(); 88 | void OnMouseCaptureEndSVOPlaybackSlider(); 89 | void OnValueChangedSVOPlaybackSlider(float Value); 90 | 91 | void OnValueChangedSVOPlaybackSpinBox(int Value); 92 | void OnValueCommitedSVOPlaybackSpinBox(int Value, ETextCommit::Type TextCommitType); 93 | 94 | private: 95 | /** Can only be one camera actor */ 96 | TArray> SelectedObjects; 97 | 98 | /** Detail builder used to draw */ 99 | IDetailLayoutBuilder* CachedDetailBuilder; 100 | 101 | bool bIsSVOplaybackPaused; 102 | 103 | int SVOPlaybackSliderValue; 104 | 105 | int SVOPlaybackSpinBoxValue; 106 | }; -------------------------------------------------------------------------------- /Stereolabs/Source/ZEDEditor/Public/ZEDEditorPlugin.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "ModuleManager.h" 6 | 7 | class FStereolabsZEDEditor : public IModuleInterface 8 | { 9 | public: 10 | /** IModuleInterface implementation */ 11 | virtual void StartupModule() override; 12 | virtual void ShutdownModule() override; 13 | }; -------------------------------------------------------------------------------- /Stereolabs/Source/ZEDEditor/Public/ZEDInitializerDetails.h: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | #pragma once 4 | 5 | #include "IDetailCustomization.h" 6 | #include "DetailLayoutBuilder.h" 7 | 8 | class FZEDInitializerDetails : public IDetailCustomization 9 | { 10 | public: 11 | /** Makes a new instance of this detail layout class for a specific detail view requesting it */ 12 | static TSharedRef MakeInstance(); 13 | 14 | /** IDetailCustomization interface */ 15 | virtual void CustomizeDetails(IDetailLayoutBuilder& DetailBuilder) override; 16 | 17 | /** Button enabled */ 18 | bool IsEnabled() const { return true; } 19 | 20 | /** Clicking the reset parameters button */ 21 | FReply OnClickResetParameters(); 22 | 23 | /** Clicking the reset camera settings button */ 24 | FReply OnClickResetSettings(); 25 | 26 | /** Clicking the save parameters button */ 27 | FReply OnClickSaveParameters(); 28 | 29 | /** Clicking the load parameters button */ 30 | FReply OnClickLoadParameters(); 31 | 32 | /** Clicking the save camera settings button */ 33 | FReply OnClickSaveSettings(); 34 | 35 | /** Clicking the load camera settings button */ 36 | FReply OnClickLoadSettings(); 37 | 38 | private: 39 | /** Can only be one initializer selected */ 40 | TArray> SelectedObjects; 41 | }; -------------------------------------------------------------------------------- /Stereolabs/Source/ZEDEditor/ZEDEditor.Build.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Stereolabs Corporation, All rights reserved. =============== 2 | 3 | using System.IO; 4 | 5 | namespace UnrealBuildTool.Rules 6 | { 7 | public class ZEDEditor : ModuleRules 8 | { 9 | public ZEDEditor(ReadOnlyTargetRules Target) : base(Target) 10 | { 11 | PrivatePCHHeaderFile = "ZEDEditor/Public/ZEDEditor.h"; 12 | 13 | PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "Public")); 14 | PrivateIncludePaths.Add(Path.Combine(ModuleDirectory, "Private")); 15 | 16 | PrivateDependencyModuleNames.AddRange(new string[] 17 | {"Slate", 18 | "SlateCore" }); 19 | 20 | PublicDependencyModuleNames.AddRange( 21 | new string[] 22 | { 23 | "Stereolabs", 24 | "ZED" 25 | } 26 | ); 27 | 28 | PublicDependencyModuleNames.AddRange( 29 | new string[] 30 | { 31 | "Core", 32 | "CoreUObject", 33 | "Slate", 34 | "SlateCore", 35 | "Engine", 36 | "UnrealEd", 37 | "HeadMountedDisplay", 38 | "DesktopPlatform", 39 | "InputCore" 40 | } 41 | ); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /Stereolabs/Stereolabs.uplugin: -------------------------------------------------------------------------------- 1 | { 2 | "FileVersion": 3, 3 | "Version": 1, 4 | "VersionName": "1.0", 5 | "FriendlyName": "Stereolabs", 6 | "Description": "Stereolabs plugin supporting ZED stereo camera", 7 | "Category": "Mixed Reality", 8 | "CreatedBy": "Stereolabs", 9 | "CreatedByURL": "http://stereolabs.com", 10 | "DocsURL": "https://www.stereolabs.com/blog/index.php/category/news/", 11 | "MarketplaceURL": "", 12 | "SupportURL": "https://www.stereolabs.com/company/", 13 | "EnabledByDefault": true, 14 | "CanContainContent": true, 15 | "IsBetaVersion": false, 16 | "Installed": true, 17 | "Modules": 18 | [ 19 | { 20 | "Name": "Stereolabs", 21 | "Type": "Runtime", 22 | "LoadingPhase": "Default", 23 | "WhitelistPlatforms": 24 | [ 25 | "Win64" 26 | ] 27 | }, 28 | { 29 | "Name": "ZED", 30 | "Type": "Runtime", 31 | "LoadingPhase": "Default", 32 | "WhitelistPlatforms": 33 | [ 34 | "Win64" 35 | ] 36 | }, 37 | { 38 | "Name": "SpatialMapping", 39 | "Type": "Runtime", 40 | "LoadingPhase": "Default", 41 | "WhitelistPlatforms": 42 | [ 43 | "Win64" 44 | ] 45 | }, 46 | { 47 | "Name": "EnvironmentalLighting", 48 | "Type": "Runtime", 49 | "LoadingPhase": "Default", 50 | "WhitelistPlatforms": 51 | [ 52 | "Win64" 53 | ] 54 | }, 55 | { 56 | "Name": "Devices", 57 | "Type": "Runtime", 58 | "LoadingPhase": "Default", 59 | "WhitelistPlatforms": 60 | [ 61 | "Win64" 62 | ] 63 | }, 64 | { 65 | "Name": "SpatialMappingEditor", 66 | "Type": "Editor", 67 | "LoadingPhase": "Default" 68 | }, 69 | { 70 | "Name": "ZEDEditor", 71 | "Type": "Editor", 72 | "LoadingPhase": "Default" 73 | } 74 | ] 75 | } --------------------------------------------------------------------------------