BearishSun 9 лет назад
Родитель
Сommit
36cb81dc6d

+ 36 - 14
Source/MBansheeEditor/Windows/Scene/Gizmos/JointGizmos.cs

@@ -156,12 +156,23 @@ namespace BansheeEditor
         [DrawGizmo(DrawGizmoFlags.Selected | DrawGizmoFlags.ParentSelected)]
         private static void DrawSphericalJoint(SphericalJoint joint)
         {
-            Vector3 anchorA = GetAnchor(joint, JointBody.Target);
-            Vector3 anchorB = GetAnchor(joint, JointBody.Anchor);
+            Vector3 target = GetAnchor(joint, JointBody.Target);
+            Vector3 anchor = GetAnchor(joint, JointBody.Anchor);
+            Vector3 center = target;
+
+            Rigidbody rigidbody = joint.GetRigidbody(JointBody.Target);
+            if (rigidbody != null)
+                center = rigidbody.SceneObject.Position;
 
             Gizmos.Color = Color.White;
-            Gizmos.DrawSphere(anchorA, 0.05f);
-            Gizmos.DrawSphere(anchorB, 0.05f);
+            Gizmos.DrawSphere(center, 0.05f);
+
+            Gizmos.Color = Color.Yellow;
+            Gizmos.DrawSphere(target, 0.05f);
+            Gizmos.DrawSphere(anchor, 0.05f);
+
+            Gizmos.Color = Color.Green;
+            Gizmos.DrawLine(target, center);
 
             Gizmos.Color = Color.Green;
             if (joint.EnableLimit)
@@ -172,15 +183,15 @@ namespace BansheeEditor
                 Radian yAngle = MathEx.Min(new Degree(360), limit.YLimitAngle*2.0f);
 
                 Gizmos.Transform = joint.SceneObject.WorldTransform;
-                Gizmos.DrawWireArc(Vector3.Zero, Vector3.ZAxis, 0.25f, zAngle * -0.5f, zAngle);
-                Gizmos.DrawWireArc(Vector3.Zero, Vector3.YAxis, 0.25f, yAngle * -0.5f, yAngle);
+                Gizmos.DrawWireArc(Vector3.Zero, Vector3.ZAxis, 0.25f, zAngle * -0.5f + new Degree(90), zAngle);
+                Gizmos.DrawWireArc(Vector3.Zero, Vector3.YAxis, 0.25f, yAngle * -0.5f + new Degree(90), yAngle);
 
                 Gizmos.Color = Color.Red;
                 Radian remainingZAngle = new Degree(360) - zAngle;
                 Radian remainingYAngle = new Degree(360) - yAngle;
 
-                Gizmos.DrawWireArc(Vector3.Zero, Vector3.ZAxis, 0.25f, zAngle * 0.5f, remainingZAngle);
-                Gizmos.DrawWireArc(Vector3.Zero, Vector3.YAxis, 0.25f, yAngle * 0.5f, remainingYAngle);
+                Gizmos.DrawWireArc(Vector3.Zero, Vector3.ZAxis, 0.25f, zAngle * 0.5f + new Degree(90), remainingZAngle);
+                Gizmos.DrawWireArc(Vector3.Zero, Vector3.YAxis, 0.25f, yAngle * 0.5f + new Degree(90), remainingYAngle);
             }
             else
             {
@@ -199,15 +210,26 @@ namespace BansheeEditor
         [DrawGizmo(DrawGizmoFlags.Selected | DrawGizmoFlags.ParentSelected)]
         private static void DrawHingeJoint(HingeJoint joint)
         {
-            Vector3 anchorA = GetAnchor(joint, JointBody.Target);
-            Vector3 anchorB = GetAnchor(joint, JointBody.Anchor);
+            Vector3 target = GetAnchor(joint, JointBody.Target);
+            Vector3 anchor = GetAnchor(joint, JointBody.Anchor);
+            Vector3 center = target;
+
+            Rigidbody rigidbody = joint.GetRigidbody(JointBody.Target);
+            if (rigidbody != null)
+                center = rigidbody.SceneObject.Position;
 
             Gizmos.Color = Color.White;
-            Gizmos.DrawSphere(anchorA, 0.05f);
-            Gizmos.DrawSphere(anchorB, 0.05f);
+            Gizmos.DrawSphere(center, 0.05f);
+
+            Gizmos.Color = Color.Yellow;
+            Gizmos.DrawSphere(target, 0.05f);
+            Gizmos.DrawSphere(anchor, 0.05f);
+
+            Gizmos.Color = Color.Green;
+            Gizmos.DrawLine(target, center);
 
-            const float radius = 0.05f;
-            const float height = 0.25f;
+            const float radius = 0.25f;
+            const float height = 0.5f;
 
             if (joint.EnableLimit)
             {

+ 4 - 1
Source/MBansheeEngine/Physics/D6Joint.cs

@@ -8,7 +8,7 @@ namespace BansheeEngine
 
     /// <summary>
     /// Represents the most customizable type of joint. This joint type can be used to create all other built-in joint 
-    /// types, and to design your own custom ones, but is less intuitive to use.Allows a specification of a linear
+    /// types, and to design your own custom ones, but is less intuitive to use. Allows a specification of a linear
     /// constraint (for example for slider), twist constraint(rotating around X) and swing constraint(rotating around Y and
     /// Z). It also allows you to constrain limits to only specific axes or completely lock specific axes.
     /// </summary>
@@ -288,6 +288,9 @@ namespace BansheeEngine
                 @internal.driveRotation = Quaternion.Identity;
                 @internal.driveLinearVelocity = Vector3.Zero;
                 @internal.driveAngularVelocity = Vector3.Zero;
+
+                for (int i = 0; i < (int) D6JointAxis.Count; i++)
+                    @internal.drives[i] = new D6JointDrive();
             }
         }
     }

+ 13 - 1
Source/MBansheeEngine/Physics/Joint.cs

@@ -266,7 +266,7 @@ namespace BansheeEngine
         /// Creates the internal representation of the Joint and restores the values saved by the Component.
         /// </summary>
         private void RestoreNative()
-	    {
+        {
             [email protected][0] = IntPtr.Zero;
             [email protected][1] = IntPtr.Zero;
 
@@ -582,6 +582,12 @@ namespace BansheeEngine
             get { return data; }
         }
 
+        /// <summary>
+        /// Constructor for deserialization only.
+        /// </summary>
+        private D6JointDrive()
+        { }
+
         /// <summary>
         /// Constructs a new D6 joint drive.
         /// </summary>
@@ -684,6 +690,12 @@ namespace BansheeEngine
             get { return data; }
         }
 
+        /// <summary>
+        /// Constructor for deserialization only.
+        /// </summary>
+        private HingeJointDrive()
+        { }
+
         /// <summary>
         /// Constructs a new hinge joint drive.
         /// </summary>

+ 4 - 2
Source/SBansheeEngine/Source/BsManagedSerializableObject.cpp

@@ -72,8 +72,10 @@ namespace BansheeEngine
 		if (!ScriptAssemblyManager::instance().getSerializableObjectInfo(type->mTypeNamespace, type->mTypeName, currentObjInfo))
 			return nullptr;
 
-		// Don't construct as we have no guarantees that objects will have parameterless constructors
-		return currentObjInfo->mMonoClass->createInstance(false);
+		if (type->mValueType)
+			return currentObjInfo->mMonoClass->createInstance(false);
+		else
+			return currentObjInfo->mMonoClass->createInstance();
 	}
 
 	SPtr<ManagedSerializableObject> ManagedSerializableObject::createEmpty()

+ 2 - 2
Source/SBansheeEngine/Source/BsScriptD6Joint.cpp

@@ -117,12 +117,12 @@ namespace BansheeEngine
 	void ScriptD6JointData::toDesc(D6_JOINT_DESC& desc) const
 	{
 		ScriptArray motionArray(motion);
-
 		for (UINT32 i = 0; i < (UINT32)D6Joint::Axis::Count; i++)
 			desc.motion[i] = motionArray.get<D6Joint::Motion>(i);
 
+		ScriptArray driveArray(drives);
 		for (UINT32 i = 0; i < (UINT32)D6Joint::DriveType::Count; i++)
-			desc.drive[i] = ScriptD6JointDrive::convert(motionArray.get<MonoObject*>(i));
+			desc.drive[i] = ScriptD6JointDrive::convert(driveArray.get<MonoObject*>(i));
 
 		desc.limitLinear = ScriptLimitLinear::convert(linearLimit);
 		desc.limitTwist = ScriptLimitAngularRange::convert(twistLimit);

+ 3 - 0
Source/SBansheeEngine/Source/BsScriptJointCommon.cpp

@@ -5,6 +5,9 @@
 #include "BsMonoMethod.h"
 #include "BsMonoUtil.h"
 
+// DEBUG ONLY
+#include "BsMonoProperty.h"
+
 namespace BansheeEngine
 {
 	ScriptD6JointDrive::GetNativeDataThunkDef ScriptD6JointDrive::getNativeDataThunk = nullptr;