pivot_transform.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*************************************************************************/
  2. /* pivot_transform.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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 PIVOT_TRANSFORM_H
  31. #define PIVOT_TRANSFORM_H
  32. #include "core/math/transform.h"
  33. #include "core/object/reference.h"
  34. #include "model_abstraction.h"
  35. #include "fbx_parser/FBXDocument.h"
  36. #include "tools/import_utils.h"
  37. enum TransformationComp {
  38. TransformationComp_Translation,
  39. TransformationComp_Scaling,
  40. TransformationComp_Rotation,
  41. TransformationComp_RotationOffset,
  42. TransformationComp_RotationPivot,
  43. TransformationComp_PreRotation,
  44. TransformationComp_PostRotation,
  45. TransformationComp_ScalingOffset,
  46. TransformationComp_ScalingPivot,
  47. TransformationComp_GeometricTranslation,
  48. TransformationComp_GeometricRotation,
  49. TransformationComp_GeometricScaling,
  50. TransformationComp_MAXIMUM
  51. };
  52. // Abstract away pivot data so its simpler to handle
  53. struct PivotTransform : Reference, ModelAbstraction {
  54. // at the end we want to keep geometric_ everything, post and pre rotation
  55. // these are used during animation data processing / keyframe ingestion the rest can be simplified down / out.
  56. Quat pre_rotation = Quat();
  57. Quat post_rotation = Quat();
  58. Quat rotation = Quat();
  59. Quat geometric_rotation = Quat();
  60. Vector3 rotation_pivot = Vector3();
  61. Vector3 rotation_offset = Vector3();
  62. Vector3 scaling_offset = Vector3(1.0, 1.0, 1.0);
  63. Vector3 scaling_pivot = Vector3(1.0, 1.0, 1.0);
  64. Vector3 translation = Vector3();
  65. Vector3 scaling = Vector3(1.0, 1.0, 1.0);
  66. Vector3 geometric_scaling = Vector3(1.0, 1.0, 1.0);
  67. Vector3 geometric_translation = Vector3();
  68. Vector3 raw_rotation = Vector3();
  69. Vector3 raw_post_rotation = Vector3();
  70. Vector3 raw_pre_rotation = Vector3();
  71. /* Read pivots from the document */
  72. void ReadTransformChain();
  73. void debug_pivot_xform(String p_name) {
  74. print_verbose("debugging node name: " + p_name);
  75. print_verbose("raw rotation: " + raw_rotation * (180 / Math_PI));
  76. print_verbose("raw pre_rotation " + raw_pre_rotation * (180 / Math_PI));
  77. print_verbose("raw post_rotation " + raw_post_rotation * (180 / Math_PI));
  78. }
  79. Transform ComputeGlobalTransform(Transform t) const;
  80. Transform ComputeLocalTransform(Transform t) const;
  81. Transform ComputeGlobalTransform(Vector3 p_translation, Quat p_rotation, Vector3 p_scaling) const;
  82. Transform ComputeLocalTransform(Vector3 p_translation, Quat p_rotation, Vector3 p_scaling) const;
  83. /* Extract into xforms and calculate once */
  84. void ComputePivotTransform();
  85. /* Execute the command for the pivot generation */
  86. void Execute();
  87. void set_parent(Ref<PivotTransform> p_parent) {
  88. parent_transform = p_parent;
  89. }
  90. bool computed_global_xform = false;
  91. Ref<PivotTransform> parent_transform = Ref<PivotTransform>();
  92. //Transform chain[TransformationComp_MAXIMUM];
  93. // cached for later use
  94. Transform GlobalTransform = Transform();
  95. Transform LocalTransform = Transform();
  96. Transform Local_Scaling_Matrix = Transform(); // used for inherit type.
  97. Transform GeometricTransform = Transform(); // 3DS max only
  98. FBXDocParser::TransformInheritance inherit_type = FBXDocParser::TransformInheritance_MAX; // maya fbx requires this - sorry <3
  99. };
  100. #endif // PIVOT_TRANSFORM_H