xr_body_modifier_3d.h 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**************************************************************************/
  2. /* xr_body_modifier_3d.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef XR_BODY_MODIFIER_3D_H
  31. #define XR_BODY_MODIFIER_3D_H
  32. #include "scene/3d/skeleton_modifier_3d.h"
  33. #include "servers/xr/xr_body_tracker.h"
  34. class Skeleton3D;
  35. /**
  36. The XRBodyModifier3D node drives a body skeleton using body tracking
  37. data from an XRBodyTracker instance.
  38. */
  39. class XRBodyModifier3D : public SkeletonModifier3D {
  40. GDCLASS(XRBodyModifier3D, SkeletonModifier3D);
  41. public:
  42. enum BodyUpdate {
  43. BODY_UPDATE_UPPER_BODY = 1,
  44. BODY_UPDATE_LOWER_BODY = 2,
  45. BODY_UPDATE_HANDS = 4,
  46. };
  47. enum BoneUpdate {
  48. BONE_UPDATE_FULL,
  49. BONE_UPDATE_ROTATION_ONLY,
  50. BONE_UPDATE_MAX
  51. };
  52. void set_body_tracker(const StringName &p_tracker_name);
  53. StringName get_body_tracker() const;
  54. void set_body_update(BitField<BodyUpdate> p_body_update);
  55. BitField<BodyUpdate> get_body_update() const;
  56. void set_bone_update(BoneUpdate p_bone_update);
  57. BoneUpdate get_bone_update() const;
  58. void _notification(int p_what);
  59. protected:
  60. static void _bind_methods();
  61. virtual void _skeleton_changed(Skeleton3D *p_old, Skeleton3D *p_new) override;
  62. virtual void _process_modification() override;
  63. private:
  64. struct JointData {
  65. int bone = -1;
  66. int parent_joint = -1;
  67. };
  68. StringName tracker_name = "/user/body_tracker";
  69. BitField<BodyUpdate> body_update = BODY_UPDATE_UPPER_BODY | BODY_UPDATE_LOWER_BODY | BODY_UPDATE_HANDS;
  70. BoneUpdate bone_update = BONE_UPDATE_FULL;
  71. JointData joints[XRBodyTracker::JOINT_MAX];
  72. void _get_joint_data();
  73. void _tracker_changed(const StringName &p_tracker_name, XRServer::TrackerType p_tracker_type);
  74. };
  75. VARIANT_BITFIELD_CAST(XRBodyModifier3D::BodyUpdate)
  76. VARIANT_ENUM_CAST(XRBodyModifier3D::BoneUpdate)
  77. #endif // XR_BODY_MODIFIER_3D_H