14 int SNAP_TO_PARENT_BONE;
17 [
Attribute(
"1",
UIWidgets.CheckBox,
"Whether to create collision blocker between parent and child" )]
18 bool m_CollisionBlocker;
31 void MoveJointToParentBone()
36 if (SNAP_TO_PARENT_BONE <= 0)
41 m_JointParent.GetAnimation().GetBoneMatrix(SNAP_TO_PARENT_BONE, boneMat);
49 worldEditorAPI.BeginEntityAction(
"Move to parent bone",
"");
50 worldEditorAPI.ClearEntitySelection();
53 worldEditorAPI.SetVariableValue(src, null,
"coords", pos.ToString(
false));
54 worldEditorAPI.SetVariableValue(src, null,
"angles",
string.Format(
"%1 %2 %3",
angles[1],
angles[0],
angles[2]));
55 worldEditorAPI.SetVariableValue(src, null,
"SNAP_TO_PARENT_BONE",
"-1");
56 worldEditorAPI.EndEntityAction(
"Move to parent bone");
110 if (varName ==
"SNAP_TO_PARENT_BONE" && m_JointParent)
111 return SCR_Global.GetBonesAsParamEnums(m_JointParent);
125 return EEntityFrameUpdateSpecs.CALL_WHEN_ENTITY_VISIBLE;
145 if (m_JointParent || m_JointChild)
156 void TryCreateJoint(
bool showErrors)
160 if (!m_JointParent && !m_JointChild)
164 Print(
"JointHingeEntity::CreateJoint: ERROR - cannot create joint, no parent and no child!");
165 CreateFailedJointDebug(128, 255, 0, 0);
173 parentPhysics = m_JointParent.GetPhysics();
175 childPhysics = m_JointChild.GetPhysics();
176 if (!parentPhysics && !childPhysics)
180 Print(
"JointHingeEntity::CreateJoint: ERROR - cannot create joint, neither parent nor child have physics!");
181 CreateFailedJointDebug(128, 255, 0, 0);
186 if (parentPhysics && childPhysics && !parentPhysics.IsDynamic() && !childPhysics.IsDynamic())
190 Print(
"JointHingeEntity::CreateJoint: ERROR - cannot create joint, neither parent nor child are dynamic!");
191 CreateFailedJointDebug(128, 255, 0, 0);
196 IEntity parent = m_JointParent;
200 if (parent && parentPhysics && !parentPhysics.IsDynamic())
202 if (child && childPhysics && !childPhysics.IsDynamic())
205 if (showErrors && !parent && !child)
207 Print(
"JointHingeEntity::CreateJoint: ERROR - cannot create joint, no connected dynamic entities!");
208 CreateFailedJointDebug(128, 255, 128, 0);
211 if (!parent || !child)
217 m_JointDummy.SetDummyTransform(jointDummyMat);
221 mass = parentPhysics.GetMass();
223 mass = childPhysics.GetMass();
225 m_JointDummy.GetPhysics().SetMass(mass * 1000);
230 child = m_JointDummy;
232 parent = m_JointDummy;
236 if (!parentPhysics || !parentPhysics.IsDynamic())
244 vector parentMat[4], childMat[4], jointMat[4];
250 RotateJoint(jointMat);
253 vector jointMatParentLocal[4], jointMatChildLocal[4];
254 Math3D.MatrixInvMultiply4(parentMat, jointMat, jointMatParentLocal);
255 Math3D.MatrixInvMultiply4(childMat, jointMat, jointMatChildLocal);
259 jointMatParentLocal[3] = jointMatParentLocal[3] - parentPhysics.GetCenterOfMass();
261 jointMatParentLocal[3] = jointMatParentLocal[3];
263 jointMatChildLocal[3] = jointMatChildLocal[3] - childPhysics.GetCenterOfMass();
265 jointMatChildLocal[3] = jointMatChildLocal[3];
268 CreateJoint(parent, child, jointMatParentLocal, jointMatChildLocal);
272 void RotateJoint(inout
vector jointMat[4])
282 void CreateFailedJointDebug(
int a,
int r,
int g,
int b)
284 int color =
ARGB(a, r, g, b);
296 override event void EOnInit(
IEntity owner)
302 MoveJointToParentBone();
309 m_JointParent = parent;
315 void ~SCR_JointBaseEntity()