diff --git a/UnityProject/Assets/BulletUnity/Examples/Scenes/Constraints/Constraints.unity b/UnityProject/Assets/BulletUnity/Examples/Scenes/Constraints/Constraints.unity index 45044c2..a3ee1d6 100644 Binary files a/UnityProject/Assets/BulletUnity/Examples/Scenes/Constraints/Constraints.unity and b/UnityProject/Assets/BulletUnity/Examples/Scenes/Constraints/Constraints.unity differ diff --git a/UnityProject/Assets/BulletUnity/Examples/Scenes/Ragdoll/Ragdoll.unity b/UnityProject/Assets/BulletUnity/Examples/Scenes/Ragdoll/Ragdoll.unity index da598c5..7164c1d 100644 Binary files a/UnityProject/Assets/BulletUnity/Examples/Scenes/Ragdoll/Ragdoll.unity and b/UnityProject/Assets/BulletUnity/Examples/Scenes/Ragdoll/Ragdoll.unity differ diff --git a/UnityProject/Assets/BulletUnity/Examples/Scenes/SoftBody/RatherGoodPlayground.unity b/UnityProject/Assets/BulletUnity/Examples/Scenes/SoftBody/RatherGoodPlayground.unity index c836be1..83f9fdd 100644 Binary files a/UnityProject/Assets/BulletUnity/Examples/Scenes/SoftBody/RatherGoodPlayground.unity and b/UnityProject/Assets/BulletUnity/Examples/Scenes/SoftBody/RatherGoodPlayground.unity differ diff --git a/UnityProject/Assets/BulletUnity/Scripts/Constraints/B6DOFConstraint.cs b/UnityProject/Assets/BulletUnity/Scripts/Constraints/B6DOFConstraint.cs index fa7f579..46e4dc1 100644 --- a/UnityProject/Assets/BulletUnity/Scripts/Constraints/B6DOFConstraint.cs +++ b/UnityProject/Assets/BulletUnity/Scripts/Constraints/B6DOFConstraint.cs @@ -10,11 +10,12 @@ public class B6DOFConstraint : BTypedConstraint { //Todo not sure if this is working //Todo breaking strength //todo should be properties so can capture changes and propagate to scene + public static string HelpMessage = "\n" + + "\nTIP: To see constraint limits:\n" + + " - In BulletPhysicsWorld turn on 'Do Debug Draw' and set 'Debug Draw Mode' flags\n" + + " - On Constraint set 'Debug Draw Size'\n" + + " - Press play"; - [Header("Reference Frame Local To This Object")] - public Vector3 m_localConstraintPoint = Vector3.zero; - public Vector3 m_localConstraintForwardDir = Vector3.forward; - public Vector3 m_localConstraintUpDir = Vector3.up; [Header("Limits")] public Vector3 m_linearLimitLower; @@ -72,7 +73,7 @@ internal override bool _BuildConstraint() { BM.Matrix frameInA, frameInOther; string errormsg = ""; - if (CreateFramesA_B(m_localConstraintForwardDir, m_localConstraintUpDir, m_localConstraintPoint, out frameInA, out frameInOther, ref errormsg)) + if (CreateFramesA_B(m_localConstraintAxisX, m_localConstraintAxisY, m_localConstraintPoint, out frameInA, out frameInOther, ref errormsg)) { m_constraintPtr = new Generic6DofConstraint(rbb, rba, frameInOther, frameInA, true); } else diff --git a/UnityProject/Assets/BulletUnity/Scripts/Constraints/BBallSocketConstraint.cs b/UnityProject/Assets/BulletUnity/Scripts/Constraints/BBallSocketConstraint.cs index 1c87ffa..8e937f1 100644 --- a/UnityProject/Assets/BulletUnity/Scripts/Constraints/BBallSocketConstraint.cs +++ b/UnityProject/Assets/BulletUnity/Scripts/Constraints/BBallSocketConstraint.cs @@ -10,9 +10,11 @@ public class BBallSocketConstraint : BTypedConstraint { //todo should be properties so can capture changes and propagate to scene - - [Header("Constraint Point Local To This Object")] - public Vector3 m_localConstraintPoint = Vector3.zero; + public static string HelpMessage = "Only the 'Local Constraint Point' is used. X and Y are ignored.\n" + + "\nTIP: To see constraint limits:\n" + + " - In BulletPhysicsWorld turn on 'Do Debug Draw' and set 'Debug Draw Mode' flags\n" + + " - On Constraint set 'Debug Draw Size'\n" + + " - Press play"; //called by Physics World just before constraint is added to world. //the current constraint properties are used to rebuild the constraint. diff --git a/UnityProject/Assets/BulletUnity/Scripts/Constraints/BConeTwistConstraint.cs b/UnityProject/Assets/BulletUnity/Scripts/Constraints/BConeTwistConstraint.cs index df068b2..437b0d7 100644 --- a/UnityProject/Assets/BulletUnity/Scripts/Constraints/BConeTwistConstraint.cs +++ b/UnityProject/Assets/BulletUnity/Scripts/Constraints/BConeTwistConstraint.cs @@ -5,7 +5,6 @@ using BM = BulletSharp.Math; namespace BulletUnity { - //TODO script execution order, rigid bodies before constraints & other stuff that might use them [System.Serializable] public class BConeTwistConstraint : BTypedConstraint { public static string HelpMessage = "btConeTwistConstraint can be used to simulate ragdoll joints (upper arm, leg etc)." + @@ -14,14 +13,14 @@ public class BConeTwistConstraint : BTypedConstraint { "Swing is divided into swing1 and swing2 which can have different limits, giving an elliptical shape."+ "(Note: the cone's base isn't flat, so this ellipse is 'embedded' on the surface of a sphere.)\n\n"+ "In the contraint's frame of reference:\n"+ - " - twist is along the forward\n"+ - " - and swing 1 and 2 are along the right and up axes respectively.\n"; + " - twist is along the X (blue) twist limit is about Y (green) \n"+ + " - and swing 1 and 2 are along the Y (green) and Z (red) axes respectively.\n" + + "\nTIP: To see constraint limits:\n" + + " - In BulletPhysicsWorld turn on 'Do Debug Draw' and set 'Debug Draw Mode' flags\n" + + " - On Constraint set 'Debug Draw Size'\n" + + " - Press play"; - [Header("Reference Frame Local To This Object")] - public Vector3 m_localConstraintPoint = Vector3.zero; - public Vector3 m_localConstraintForwardDir = Vector3.forward; - public Vector3 m_localConstraintUpDir = Vector3.up; [Header("Limits")] public float m_swingSpan1Radians = Mathf.PI; @@ -66,7 +65,7 @@ internal override bool _BuildConstraint() { } BM.Matrix frameInA, frameInOther; string errormsg = ""; - if (CreateFramesA_B(m_localConstraintForwardDir, m_localConstraintUpDir, m_localConstraintPoint, out frameInA, out frameInOther, ref errormsg)) + if (CreateFramesA_B(m_localConstraintAxisX, m_localConstraintAxisY, m_localConstraintPoint, out frameInA, out frameInOther, ref errormsg)) { m_constraintPtr = new ConeTwistConstraint((RigidBody)m_otherRigidBody.GetCollisionObject(), (RigidBody)targetRigidBodyA.GetCollisionObject(), frameInOther, frameInA); } else @@ -81,7 +80,7 @@ internal override bool _BuildConstraint() { //TODO this is broken string errormsg = ""; BM.Matrix frameInB = BM.Matrix.Identity; - if (CreateFrame(m_localConstraintForwardDir, m_localConstraintUpDir, m_localConstraintPoint, ref frameInB, ref errormsg)) + if (CreateFrame(m_localConstraintAxisX, m_localConstraintAxisY, m_localConstraintPoint, ref frameInB, ref errormsg)) { m_constraintPtr = new ConeTwistConstraint((RigidBody)targetRigidBodyA.GetCollisionObject(), frameInB); } else diff --git a/UnityProject/Assets/BulletUnity/Scripts/Constraints/BFixedConstraint.cs b/UnityProject/Assets/BulletUnity/Scripts/Constraints/BFixedConstraint.cs index 72c8596..54b385c 100644 --- a/UnityProject/Assets/BulletUnity/Scripts/Constraints/BFixedConstraint.cs +++ b/UnityProject/Assets/BulletUnity/Scripts/Constraints/BFixedConstraint.cs @@ -9,10 +9,6 @@ namespace BulletUnity { public class BFixedConstraint : BTypedConstraint { //todo should be properties so can capture changes and propagate to scene - [Header("Reference Frame Local To This Object")] - public Vector3 m_localConstraintPoint = Vector3.zero; - public Vector3 m_localConstraintForwardDir = Vector3.forward; - public Vector3 m_localConstraintUpDir = Vector3.up; //called by Physics World just before constraint is added to world. //the current constraint properties are used to rebuild the constraint. @@ -62,7 +58,7 @@ internal override bool _BuildConstraint() { } BM.Matrix frameInA, frameInOther; string errormsg = ""; - if (CreateFramesA_B(m_localConstraintForwardDir, m_localConstraintUpDir, m_localConstraintPoint, out frameInA, out frameInOther, ref errormsg)) + if (CreateFramesA_B(m_localConstraintAxisX, m_localConstraintAxisY, m_localConstraintPoint, out frameInA, out frameInOther, ref errormsg)) { m_constraintPtr = new FixedConstraint(rbb, rba, frameInOther, frameInA); } else diff --git a/UnityProject/Assets/BulletUnity/Scripts/Constraints/BHingedConstraint.cs b/UnityProject/Assets/BulletUnity/Scripts/Constraints/BHingedConstraint.cs index 05df725..9c356dc 100644 --- a/UnityProject/Assets/BulletUnity/Scripts/Constraints/BHingedConstraint.cs +++ b/UnityProject/Assets/BulletUnity/Scripts/Constraints/BHingedConstraint.cs @@ -9,13 +9,11 @@ namespace BulletUnity { public class BHingedConstraint : BTypedConstraint { //todo should be properties so can capture changes and propagate to scene - /// - /// In targetRigidbody local coordinates - /// - [Header("Reference Frame Local To This Object")] - public Vector3 m_localConstraintPoint = Vector3.zero; - public Vector3 m_localConstraintForwardDir = Vector3.forward; - public Vector3 m_localConstraintUpDir = Vector3.up; + public static string HelpMessage = "X (red) is axis of the hinge.\n" + + "\nTIP: To see constraint limits:\n" + + " - In BulletPhysicsWorld turn on 'Do Debug Draw' and set 'Debug Draw Mode' flags\n" + + " - On Constraint set 'Debug Draw Size'\n" + + " - Press play"; public bool m_enableMotor; public float m_targetMotorAngularVelocity = 0f; @@ -54,7 +52,7 @@ internal override bool _BuildConstraint() { { world.AddRigidBody(targetRigidBodyA); } - if (m_localConstraintForwardDir == Vector3.zero) + if (m_localConstraintAxisX == Vector3.zero) { Debug.LogError("Constaint axis cannot be zero vector"); return false; @@ -83,7 +81,7 @@ internal override bool _BuildConstraint() { } BM.Matrix frameInA, frameInOther; string errormsg = ""; - if (CreateFramesA_B(m_localConstraintForwardDir, m_localConstraintUpDir, m_localConstraintPoint, out frameInA, out frameInOther, ref errormsg)) + if (CreateFramesA_B(m_localConstraintAxisX, m_localConstraintAxisY, m_localConstraintPoint, out frameInA, out frameInOther, ref errormsg)) { //warning the frameInA, frameInB version of the constructor is broken m_constraintPtr = new HingeConstraint(rbb, rba, frameInOther.Origin, frameInA.Origin, (BM.Vector3)frameInOther.Basis.Column1, (BM.Vector3)frameInA.Basis.Column1); @@ -96,7 +94,7 @@ internal override bool _BuildConstraint() { else { //BM.Matrix frameInA = BM.Matrix.Identity; //CreateFrame(m_localConstraintForwardDir, m_localConstraintUpDir, m_localConstraintPoint, ref frameInA); - m_constraintPtr = new HingeConstraint(rba, m_localConstraintPoint.ToBullet(),m_localConstraintForwardDir.ToBullet(), false); + m_constraintPtr = new HingeConstraint(rba, m_localConstraintPoint.ToBullet(),m_localConstraintAxisX.ToBullet(), false); } if (m_enableMotor) { diff --git a/UnityProject/Assets/BulletUnity/Scripts/Constraints/BSliderConstraint.cs b/UnityProject/Assets/BulletUnity/Scripts/Constraints/BSliderConstraint.cs index 73f3c7d..11195d9 100644 --- a/UnityProject/Assets/BulletUnity/Scripts/Constraints/BSliderConstraint.cs +++ b/UnityProject/Assets/BulletUnity/Scripts/Constraints/BSliderConstraint.cs @@ -7,11 +7,11 @@ namespace BulletUnity { [System.Serializable] public class BSliderConstraint : BTypedConstraint { - - [Header("Reference Frame Local To This Object")] - public Vector3 m_localConstraintPoint = Vector3.zero; - public Vector3 m_localConstraintForwardDir = Vector3.forward; - public Vector3 m_localConstraintUpDir = Vector3.up; + public static string HelpMessage = "X (red) is slide axis. Angular limits are measured from Y (green) toward Z. \n" + + "\nTIP: To see constraint limits:\n" + + " - In BulletPhysicsWorld turn on 'Do Debug Draw' and set 'Debug Draw Mode' flags\n" + + " - On Constraint set 'Debug Draw Size'\n" + + " - Press play"; [Header("Limits")] public float m_lowerLinearLimit = -10f; @@ -19,11 +19,6 @@ public class BSliderConstraint : BTypedConstraint { public float m_lowerAngularLimitRadians = -Mathf.PI; public float m_upperAngularLimitRadians = Mathf.PI; - public void OnDrawGizmosSelected() - { - DrawTransformGizmos(transform, m_localConstraintPoint, m_localConstraintForwardDir, m_localConstraintUpDir); - } - //called by Physics World just before constraint is added to world. //the current constraint properties are used to rebuild the constraint. internal override bool _BuildConstraint() { @@ -69,7 +64,7 @@ internal override bool _BuildConstraint() { BM.Matrix frameInA, frameInOther; string errormsg = ""; - if (CreateFramesA_B(m_localConstraintForwardDir, m_localConstraintUpDir, m_localConstraintPoint, out frameInA, out frameInOther, ref errormsg)) + if (CreateFramesA_B(m_localConstraintAxisX, m_localConstraintAxisY, m_localConstraintPoint, out frameInA, out frameInOther, ref errormsg)) { m_constraintPtr = new SliderConstraint(rbb, rba, frameInOther, frameInA, true); } else @@ -81,7 +76,7 @@ internal override bool _BuildConstraint() { { BulletSharp.Math.Matrix frameInA = BM.Matrix.Identity; string errormsg = ""; - if (CreateFrame(m_localConstraintForwardDir, m_localConstraintUpDir, m_localConstraintPoint, ref frameInA, ref errormsg)) + if (CreateFrame(m_localConstraintAxisX, m_localConstraintAxisY, m_localConstraintPoint, ref frameInA, ref errormsg)) { m_constraintPtr = new SliderConstraint(rba, frameInA, true); } else diff --git a/UnityProject/Assets/BulletUnity/Scripts/Constraints/BTypedConstraint.cs b/UnityProject/Assets/BulletUnity/Scripts/Constraints/BTypedConstraint.cs index b5cee5e..8c9379e 100644 --- a/UnityProject/Assets/BulletUnity/Scripts/Constraints/BTypedConstraint.cs +++ b/UnityProject/Assets/BulletUnity/Scripts/Constraints/BTypedConstraint.cs @@ -16,6 +16,13 @@ public enum ConstraintType constrainToAnotherBody } + [Header("Reference Frame Local To This Object")] + public Vector3 m_localConstraintPoint = Vector3.zero; + public Vector3 m_localConstraintAxisX = Vector3.forward; + public Vector3 m_localConstraintAxisY = Vector3.up; + + + public float m_breakingImpulseThreshold = Mathf.Infinity; public bool m_disableCollisionsBetweenConstrainedBodies = true; public ConstraintType m_constraintType; @@ -30,18 +37,18 @@ public enum ConstraintType public void DrawTransformGizmos(Transform t, Vector3 pivotPoint, Vector3 forward, Vector3 up) { Vector3 pivotWorld = t.TransformPoint(pivotPoint); - Vector3 forwardWorld = t.TransformDirection(forward).normalized; - Vector3 upWorld = t.TransformDirection(up).normalized; - Vector3 rightWorld = Vector3.Cross(forwardWorld, upWorld); - upWorld = Vector3.Cross(rightWorld, forwardWorld); - upWorld.Normalize(); - forwardWorld.Normalize(); + Vector3 xWorld = t.TransformDirection(forward).normalized; + Vector3 yWorld = t.TransformDirection(up).normalized; + Vector3 zWorld = Vector3.Cross(xWorld, yWorld); + yWorld = Vector3.Cross(zWorld, xWorld); + yWorld.Normalize(); + xWorld.Normalize(); Gizmos.color = Color.red; - Gizmos.DrawLine(pivotWorld, pivotWorld + rightWorld); + Gizmos.DrawLine(pivotWorld, pivotWorld + xWorld); Gizmos.color = Color.green; - Gizmos.DrawLine(pivotWorld, pivotWorld + upWorld); + Gizmos.DrawLine(pivotWorld, pivotWorld + yWorld); Gizmos.color = Color.blue; - Gizmos.DrawLine(pivotWorld, pivotWorld + forwardWorld); + Gizmos.DrawLine(pivotWorld, pivotWorld + zWorld); } public bool CreateFrame(UnityEngine.Vector3 forward, UnityEngine.Vector3 up, UnityEngine.Vector3 constraintPoint, ref BulletSharp.Math.Matrix m, ref string errorMsg) @@ -109,6 +116,13 @@ public bool CreateFramesA_B(UnityEngine.Vector3 forwardInA, UnityEngine.Vector3 return true; } + public virtual void OnDrawGizmosSelected() + { + DrawTransformGizmos(transform, m_localConstraintPoint, m_localConstraintAxisX, m_localConstraintAxisY); + } + + + protected virtual void AddToBulletWorld() { if (!m_isInWorld) diff --git a/UnityProject/Assets/BulletUnity/Scripts/Constraints/Editor/B6DOFConstraintEditor.cs b/UnityProject/Assets/BulletUnity/Scripts/Constraints/Editor/B6DOFConstraintEditor.cs new file mode 100644 index 0000000..d29b6f0 --- /dev/null +++ b/UnityProject/Assets/BulletUnity/Scripts/Constraints/Editor/B6DOFConstraintEditor.cs @@ -0,0 +1,14 @@ +using UnityEditor; +using UnityEngine; +using BulletUnity; + +[CustomEditor(typeof(B6DOFConstraint))] +public class B6DOFConstraintEditor : Editor { + + + + public override void OnInspectorGUI() { + EditorGUILayout.HelpBox(B6DOFConstraint.HelpMessage, MessageType.Info); + DrawDefaultInspector(); + } +} diff --git a/UnityProject/Assets/BulletUnity/Scripts/Constraints/Editor/B6DOFConstraintEditor.cs.meta b/UnityProject/Assets/BulletUnity/Scripts/Constraints/Editor/B6DOFConstraintEditor.cs.meta new file mode 100644 index 0000000..93b73c1 --- /dev/null +++ b/UnityProject/Assets/BulletUnity/Scripts/Constraints/Editor/B6DOFConstraintEditor.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 41d08d8e2a6c39248bbd36b6e0aed14b +timeCreated: 1462408942 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityProject/Assets/BulletUnity/Scripts/Constraints/Editor/BBallSocketConstraintEditor.cs b/UnityProject/Assets/BulletUnity/Scripts/Constraints/Editor/BBallSocketConstraintEditor.cs new file mode 100644 index 0000000..3e2cc9b --- /dev/null +++ b/UnityProject/Assets/BulletUnity/Scripts/Constraints/Editor/BBallSocketConstraintEditor.cs @@ -0,0 +1,14 @@ +using UnityEditor; +using UnityEngine; +using BulletUnity; + +[CustomEditor(typeof(BBallSocketConstraint))] +public class BBallSocketConstraintEditor : Editor { + + + + public override void OnInspectorGUI() { + EditorGUILayout.HelpBox(BBallSocketConstraint.HelpMessage, MessageType.Info); + DrawDefaultInspector(); + } +} diff --git a/UnityProject/Assets/BulletUnity/Scripts/Constraints/Editor/BBallSocketConstraintEditor.cs.meta b/UnityProject/Assets/BulletUnity/Scripts/Constraints/Editor/BBallSocketConstraintEditor.cs.meta new file mode 100644 index 0000000..1198945 --- /dev/null +++ b/UnityProject/Assets/BulletUnity/Scripts/Constraints/Editor/BBallSocketConstraintEditor.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 39ed6fdd6914e5542ab2723cd296819f +timeCreated: 1462409147 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityProject/Assets/BulletUnity/Scripts/Constraints/Editor/BHingedConstraintEditor.cs b/UnityProject/Assets/BulletUnity/Scripts/Constraints/Editor/BHingedConstraintEditor.cs index 3111d30..315c625 100644 --- a/UnityProject/Assets/BulletUnity/Scripts/Constraints/Editor/BHingedConstraintEditor.cs +++ b/UnityProject/Assets/BulletUnity/Scripts/Constraints/Editor/BHingedConstraintEditor.cs @@ -9,6 +9,7 @@ public class BHingedConstraintEditor : Editor { public override void OnInspectorGUI() { BHingedConstraint hc = (BHingedConstraint)target; + EditorGUILayout.HelpBox(BHingedConstraint.HelpMessage, MessageType.Info); EditorGUILayout.LabelField("Hinge Angle " + hc.GetAngle()); DrawDefaultInspector(); } diff --git a/UnityProject/Assets/BulletUnity/Scripts/Constraints/Editor/BSliderConstraintEditor.cs b/UnityProject/Assets/BulletUnity/Scripts/Constraints/Editor/BSliderConstraintEditor.cs new file mode 100644 index 0000000..c570e2a --- /dev/null +++ b/UnityProject/Assets/BulletUnity/Scripts/Constraints/Editor/BSliderConstraintEditor.cs @@ -0,0 +1,15 @@ +using UnityEditor; +using UnityEngine; +using BulletUnity; + +[CustomEditor(typeof(BSliderConstraint))] +public class BSliderConstraintEditor : Editor { + + + + public override void OnInspectorGUI() { + BSliderConstraint hc = (BSliderConstraint)target; + EditorGUILayout.HelpBox(BSliderConstraint.HelpMessage, MessageType.Info); + DrawDefaultInspector(); + } +} diff --git a/UnityProject/Assets/BulletUnity/Scripts/Constraints/Editor/BSliderConstraintEditor.cs.meta b/UnityProject/Assets/BulletUnity/Scripts/Constraints/Editor/BSliderConstraintEditor.cs.meta new file mode 100644 index 0000000..96c3e7a --- /dev/null +++ b/UnityProject/Assets/BulletUnity/Scripts/Constraints/Editor/BSliderConstraintEditor.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 98010cb2fa07acd419e07fd198cc57ce +timeCreated: 1462410578 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: