meshComponent_ScriptBinding.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "console/engineAPI.h"
  23. #include "T3D/components/render/meshcomponent.h"
  24. #include "scene/sceneObject.h"
  25. #include "math/mTransform.h"
  26. DefineEngineMethod(MeshComponent, getShapeBounds, Box3F, (), ,
  27. "@brief Get the cobject we're in contact with.\n\n"
  28. "The controlling client is the one that will send moves to us to act on.\n"
  29. "@return the ID of the controlling GameConnection, or 0 if this object is not "
  30. "controlled by any client.\n"
  31. "@see GameConnection\n")
  32. {
  33. return object->getShapeBounds();
  34. }
  35. DefineEngineMethod(MeshComponent, mountObject, bool,
  36. (SceneObject* objB, String node, TransformF txfm), (MatrixF::Identity),
  37. "@brief Mount objB to this object at the desired slot with optional transform.\n\n"
  38. "@param objB Object to mount onto us\n"
  39. "@param slot Mount slot ID\n"
  40. "@param txfm (optional) mount offset transform\n"
  41. "@return true if successful, false if failed (objB is not valid)")
  42. {
  43. if (objB)
  44. {
  45. //BUG: Unsure how it broke, but atm the default transform passed in here is rotated 180 degrees. This doesn't happen
  46. //for the SceneObject mountobject method. Hackish, but for now, just default to a clean MatrixF::Identity
  47. object->mountObjectToNode(objB, node, /*MatrixF::Identity*/txfm.getMatrix());
  48. return true;
  49. }
  50. return false;
  51. }
  52. DefineEngineMethod(MeshComponent, getNodeTransform, TransformF,
  53. (S32 node), (-1),
  54. "@brief Mount objB to this object at the desired slot with optional transform.\n\n"
  55. "@param objB Object to mount onto us\n"
  56. "@param slot Mount slot ID\n"
  57. "@param txfm (optional) mount offset transform\n"
  58. "@return true if successful, false if failed (objB is not valid)")
  59. {
  60. if (node != -1)
  61. {
  62. //BUG: Unsure how it broke, but atm the default transform passed in here is rotated 180 degrees. This doesn't happen
  63. //for the SceneObject mountobject method. Hackish, but for now, just default to a clean MatrixF::Identity
  64. //object->mountObjectToNode( objB, node, /*MatrixF::Identity*/txfm.getMatrix() );
  65. MatrixF mat = object->getNodeTransform(node);
  66. return mat;
  67. }
  68. return TransformF::Identity;
  69. }
  70. DefineEngineMethod(MeshComponent, getNodeEulerRot, EulerF,
  71. (S32 node, bool radToDeg), (-1, true),
  72. "@brief Mount objB to this object at the desired slot with optional transform.\n\n"
  73. "@param objB Object to mount onto us\n"
  74. "@param slot Mount slot ID\n"
  75. "@param txfm (optional) mount offset transform\n"
  76. "@return true if successful, false if failed (objB is not valid)")
  77. {
  78. if (node != -1)
  79. {
  80. //BUG: Unsure how it broke, but atm the default transform passed in here is rotated 180 degrees. This doesn't happen
  81. //for the SceneObject mountobject method. Hackish, but for now, just default to a clean MatrixF::Identity
  82. //object->mountObjectToNode( objB, node, /*MatrixF::Identity*/txfm.getMatrix() );
  83. MatrixF mat = object->getNodeTransform(node);
  84. EulerF eul = mat.toEuler();
  85. if (radToDeg)
  86. eul = EulerF(mRadToDeg(eul.x), mRadToDeg(eul.y), mRadToDeg(eul.z));
  87. return eul;
  88. }
  89. return EulerF(0, 0, 0);
  90. }
  91. DefineEngineMethod(MeshComponent, getNodePosition, Point3F,
  92. (S32 node), (-1),
  93. "@brief Mount objB to this object at the desired slot with optional transform.\n\n"
  94. "@param objB Object to mount onto us\n"
  95. "@param slot Mount slot ID\n"
  96. "@param txfm (optional) mount offset transform\n"
  97. "@return true if successful, false if failed (objB is not valid)")
  98. {
  99. if (node != -1)
  100. {
  101. //BUG: Unsure how it broke, but atm the default transform passed in here is rotated 180 degrees. This doesn't happen
  102. //for the SceneObject mountobject method. Hackish, but for now, just default to a clean MatrixF::Identity
  103. //object->mountObjectToNode( objB, node, /*MatrixF::Identity*/txfm.getMatrix() );
  104. MatrixF mat = object->getNodeTransform(node);
  105. return mat.getPosition();
  106. }
  107. return Point3F(0, 0, 0);
  108. }
  109. DefineEngineMethod(MeshComponent, getNodeByName, S32,
  110. (String nodeName), ,
  111. "@brief Mount objB to this object at the desired slot with optional transform.\n\n"
  112. "@param objB Object to mount onto us\n"
  113. "@param slot Mount slot ID\n"
  114. "@param txfm (optional) mount offset transform\n"
  115. "@return true if successful, false if failed (objB is not valid)")
  116. {
  117. if (!nodeName.isEmpty())
  118. {
  119. //BUG: Unsure how it broke, but atm the default transform passed in here is rotated 180 degrees. This doesn't happen
  120. //for the SceneObject mountobject method. Hackish, but for now, just default to a clean MatrixF::Identity
  121. //object->mountObjectToNode( objB, node, /*MatrixF::Identity*/txfm.getMatrix() );
  122. S32 node = object->getNodeByName(nodeName);
  123. return node;
  124. }
  125. return -1;
  126. }
  127. DefineEngineMethod(MeshComponent, changeMaterial, void, (U32 slot, const char* newMat), (0, ""),
  128. "@brief Change one of the materials on the shape.\n\n")
  129. {
  130. object->changeMaterial(slot, newMat);
  131. }