XRRPIExampleComponent.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/Component/TickBus.h>
  10. #include <Atom/Component/DebugCamera/CameraComponent.h>
  11. #include <Atom/Feature/Mesh/MeshFeatureProcessorInterface.h>
  12. #include <Atom/Feature/ImGui/ImGuiUtils.h>
  13. #include <CommonSampleComponentBase.h>
  14. #include <Utils/ImGuiSidebar.h>
  15. #include <Utils/Utils.h>
  16. namespace AtomSampleViewer
  17. {
  18. //!
  19. //! This component creates a simple scene that tests VR using a special multi-view VR pipeline. We setup two pipelines, one for each eye and use stereoscopic view for this pipeline.
  20. //! This sample supports Quest 2 controllers to fly around the world. It also has support to use button presses for specific functionality
  21. //! in the scene. The schema for each controller is below
  22. //! Left controller
  23. //! Joystick - Camera movement, Button X - Camera Up (View space y-axis), Button Y - Camera Down (View space Y axis), Squeeze - Scales Controller model
  24. //! Right controller
  25. //! Joystick - View Orientation if Trigger button is pressed, otherwise it will use device for view tracking,
  26. //! Button B - Iterate through lighting preset, Button B - Iterate through ground plane material, Squeeze - Scales Controller model
  27. //!
  28. class XRRPIExampleComponent final
  29. : public CommonSampleComponentBase
  30. , public AZ::TickBus::Handler
  31. {
  32. public:
  33. AZ_COMPONENT(AtomSampleViewer::XRRPIExampleComponent, "{3122B48E-2553-4568-8B8B-532C105CB83B}", CommonSampleComponentBase);
  34. static void Reflect(AZ::ReflectContext* context);
  35. XRRPIExampleComponent() = default;
  36. ~XRRPIExampleComponent() override = default;
  37. void Activate() override;
  38. void Deactivate() override;
  39. private:
  40. AZ_DISABLE_COPY_MOVE(XRRPIExampleComponent);
  41. void CreateModels();
  42. void CreateGroundPlane();
  43. // AZ::TickBus::Handler
  44. void OnTick(float deltaTime, AZ::ScriptTimePoint timePoint) override;
  45. void OnModelReady(AZ::Data::Instance<AZ::RPI::Model> model);
  46. // meshes
  47. AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_statueMeshHandle;
  48. AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_boxMeshHandle;
  49. AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_shaderBallMeshHandle;
  50. AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_groundMeshHandle;
  51. AZ::Data::Asset<AZ::RPI::MaterialAsset> m_groundMaterialAsset;
  52. AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_leftControllerMeshHandle;
  53. AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_rightControllerMeshHandle;
  54. // ground plane default material setting index
  55. int m_groundPlaneMaterial = 2;
  56. // IBL and skybox
  57. Utils::DefaultIBL m_defaultIbl;
  58. AZ::Data::Asset<AZ::RPI::StreamingImageAsset> m_skyboxImageAsset;
  59. bool m_resetCamera = true;
  60. float m_originalFarClipDistance = 0.0f;
  61. bool m_xButtonPressed = false;
  62. bool m_yButtonPressed = false;
  63. bool m_aButtonPressed = false;
  64. bool m_bButtonPressed = false;
  65. bool m_rightTriggerButtonPressed = false;
  66. AZ::RPI::XRRenderingInterface* m_xrSystem = nullptr;
  67. AZ::u32 m_numXrViews = 0;
  68. };
  69. } // namespace AtomSampleViewer