1 //-----------------------------------------------------------------------------
2 // Copyright (c) 2012 GarageGames, LLC
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:
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
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
21 //-----------------------------------------------------------------------------
23 #include "console/engineAPI.h"
24 #include "T3D/components/render/meshcomponent.h"
25 #include "scene/sceneObject.h"
26 #include "math/mTransform.h"
28 DefineEngineMethod(MeshComponent
, getShapeBounds
, Box3F
, (), ,
29 "@brief Get the cobject we're in contact with.\n\n"
31 "The controlling client is the one that will send moves to us to act on.\n"
33 "@return the ID of the controlling GameConnection, or 0 if this object is not "
34 "controlled by any client.\n"
36 "@see GameConnection\n")
38 return object
->getShapeBounds();
41 DefineEngineMethod(MeshComponent
, mountObject
, bool,
42 (SceneObject
* objB
, String node
, TransformF txfm
), (MatrixF::Identity
),
43 "@brief Mount objB to this object at the desired slot with optional transform.\n\n"
45 "@param objB Object to mount onto us\n"
46 "@param slot Mount slot ID\n"
47 "@param txfm (optional) mount offset transform\n"
48 "@return true if successful, false if failed (objB is not valid)")
52 //BUG: Unsure how it broke, but atm the default transform passed in here is rotated 180 degrees. This doesn't happen
53 //for the SceneObject mountobject method. Hackish, but for now, just default to a clean MatrixF::Identity
54 object
->mountObjectToNode(objB
, node
, /*MatrixF::Identity*/txfm
.getMatrix());
60 DefineEngineMethod(MeshComponent
, getNodeTransform
, TransformF
,
62 "@brief Mount objB to this object at the desired slot with optional transform.\n\n"
64 "@param objB Object to mount onto us\n"
65 "@param slot Mount slot ID\n"
66 "@param txfm (optional) mount offset transform\n"
67 "@return true if successful, false if failed (objB is not valid)")
71 //BUG: Unsure how it broke, but atm the default transform passed in here is rotated 180 degrees. This doesn't happen
72 //for the SceneObject mountobject method. Hackish, but for now, just default to a clean MatrixF::Identity
73 //object->mountObjectToNode( objB, node, /*MatrixF::Identity*/txfm.getMatrix() );
74 MatrixF mat
= object
->getNodeTransform(node
);
78 return TransformF::Identity
;
81 DefineEngineMethod(MeshComponent
, getNodeEulerRot
, EulerF
,
82 (S32 node
, bool radToDeg
), (-1, true),
83 "@brief Mount objB to this object at the desired slot with optional transform.\n\n"
85 "@param objB Object to mount onto us\n"
86 "@param slot Mount slot ID\n"
87 "@param txfm (optional) mount offset transform\n"
88 "@return true if successful, false if failed (objB is not valid)")
92 //BUG: Unsure how it broke, but atm the default transform passed in here is rotated 180 degrees. This doesn't happen
93 //for the SceneObject mountobject method. Hackish, but for now, just default to a clean MatrixF::Identity
94 //object->mountObjectToNode( objB, node, /*MatrixF::Identity*/txfm.getMatrix() );
95 MatrixF mat
= object
->getNodeTransform(node
);
97 EulerF eul
= mat
.toEuler();
99 eul
= EulerF(mRadToDeg(eul
.x
), mRadToDeg(eul
.y
), mRadToDeg(eul
.z
));
104 return EulerF(0, 0, 0);
107 DefineEngineMethod(MeshComponent
, getNodePosition
, Point3F
,
109 "@brief Mount objB to this object at the desired slot with optional transform.\n\n"
111 "@param objB Object to mount onto us\n"
112 "@param slot Mount slot ID\n"
113 "@param txfm (optional) mount offset transform\n"
114 "@return true if successful, false if failed (objB is not valid)")
118 //BUG: Unsure how it broke, but atm the default transform passed in here is rotated 180 degrees. This doesn't happen
119 //for the SceneObject mountobject method. Hackish, but for now, just default to a clean MatrixF::Identity
120 //object->mountObjectToNode( objB, node, /*MatrixF::Identity*/txfm.getMatrix() );
121 MatrixF mat
= object
->getNodeTransform(node
);
123 return mat
.getPosition();
126 return Point3F(0, 0, 0);
129 DefineEngineMethod(MeshComponent
, getNodeByName
, S32
,
131 "@brief Mount objB to this object at the desired slot with optional transform.\n\n"
133 "@param objB Object to mount onto us\n"
134 "@param slot Mount slot ID\n"
135 "@param txfm (optional) mount offset transform\n"
136 "@return true if successful, false if failed (objB is not valid)")
138 if (!nodeName
.isEmpty())
140 //BUG: Unsure how it broke, but atm the default transform passed in here is rotated 180 degrees. This doesn't happen
141 //for the SceneObject mountobject method. Hackish, but for now, just default to a clean MatrixF::Identity
142 //object->mountObjectToNode( objB, node, /*MatrixF::Identity*/txfm.getMatrix() );
143 S32 node
= object
->getNodeByName(nodeName
);
151 DefineEngineMethod(MeshComponent
, changeMaterial
, void, (U32 slot
, const char* newMat
), (0, ""),
152 "@brief Change one of the materials on the shape.\n\n")
154 object
->changeMaterial(slot
, newMat
);