Преглед изворни кода

Fixing collider gizmos scale
Fixing convex mesh collider import
Fixing retrieving mesh data from a convex mesh
Fixing default orientation for the capsule collider

BearishSun пре 9 година
родитељ
комит
0edcf18610

+ 0 - 6
Source/BansheePhysX/Source/BsPhysX.cpp

@@ -558,12 +558,6 @@ namespace BansheeEngine
 			iterationCount++;
 		}
 
-		if(iterationCount == 0)
-		{
-			LOGWRN(toString(step) + " - " + toString(mSimulationStep) + " - " + 
-				toString(numIterations) + " - " + toString(curFrameTime) + " - " + toString(mLastSimulationTime) + " - " + toString(nextFrameTime));
-		}
-
 		// Update rigidbodies with new transforms
 		PxU32 numActiveTransforms;
 		const PxActiveTransform* activeTransforms = mScene->getActiveTransforms(numActiveTransforms);

+ 7 - 80
Source/BansheePhysX/Source/BsPhysXMesh.cpp

@@ -23,77 +23,7 @@ namespace BansheeEngine
 	bool cookConvex(PxCooking* cooking, const MeshDataPtr& meshData, UINT8** data, UINT32& size)
 	{
 		VertexDataDescPtr vertexDesc = meshData->getVertexDesc();
-
-		// Generate hull polygons
-		PxSimpleTriangleMesh meshDesc;
-		meshDesc.points.count = meshData->getNumVertices();
-		meshDesc.points.stride = vertexDesc->getVertexStride();
-		meshDesc.points.data = meshData->getElementData(VES_POSITION);
-
-		meshDesc.triangles.count = meshData->getNumIndices() / 3;
-		meshDesc.triangles.stride = 3 * sizeof(PxU32);
-
-		IndexType indexType = meshData->getIndexType();
-		if (indexType == IT_32BIT)
-		{
-			meshDesc.triangles.stride = 4;
-			meshDesc.triangles.data = meshData->getIndices32();
-		}
-		else
-		{
-			meshDesc.triangles.stride = 2;
-			meshDesc.triangles.data = meshData->getIndices16();
-			meshDesc.flags |= PxMeshFlag::e16_BIT_INDICES;
-		}
-
-		PxAllocatorCallback& allocator = PxGetFoundation().getAllocatorCallback();
-
-		PxU32 numVertices = 0;
-		PxU32 numIndices = 0;
-		PxU32 numPolygons = 0;
-		PxVec3* vertices = nullptr;
-		PxU32* indices = nullptr;
-		PxHullPolygon* polygons = nullptr;
-
-		bool gotPolygons = cooking->computeHullPolygons(meshDesc, allocator,
-			numVertices, vertices, numIndices, indices, numPolygons, polygons);
-
-		// If we have polygons try to create hull directly from them
-		if(gotPolygons)
-		{
-			PxConvexMeshDesc convexPolyDesc;
-			convexPolyDesc.points.count = numVertices;
-			convexPolyDesc.points.stride = sizeof(PxVec3);
-			convexPolyDesc.points.data = vertices;
-
-			convexPolyDesc.indices.count = numIndices;
-			convexPolyDesc.indices.stride = sizeof(PxU32);
-			convexPolyDesc.indices.data = indices;
-
-			convexPolyDesc.polygons.count = numPolygons;
-			convexPolyDesc.polygons.stride = sizeof(PxHullPolygon);
-			convexPolyDesc.polygons.data = polygons;
-
-			PxDefaultMemoryOutputStream output;
-			if (cooking->cookConvexMesh(convexPolyDesc, output))
-			{
-				size = output.getSize();
-				*data = (UINT8*)bs_alloc(size);
-
-				memcpy(*data, output.getData(), size);
-
-				allocator.deallocate(vertices);
-				allocator.deallocate(indices);
-				allocator.deallocate(polygons);
-
-				return true;
-			}
-
-			allocator.deallocate(vertices);
-			allocator.deallocate(indices);
-			allocator.deallocate(polygons);
-		}
-
+		
 		// Try to create hull from points
 		PxConvexMeshDesc convexDesc;
 		convexDesc.points.count = meshData->getNumVertices();
@@ -342,8 +272,10 @@ namespace BansheeEngine
 			const PxVec3* convexVertices = mConvexMesh->getVertices();
 			const UINT8* convexIndices = mConvexMesh->getIndexBuffer();
 
+			for (UINT32 i = 0; i < numVertices; i++)
+				posIter.addValue(fromPxVector(convexVertices[i]));
+
 			UINT32 numPolygons = mConvexMesh->getNbPolygons();
-			UINT32 offset = 0;
 			for (UINT32 i = 0; i < numPolygons; i++)
 			{
 				PxHullPolygon face;
@@ -351,17 +283,12 @@ namespace BansheeEngine
 				assert(status);
 
 				const PxU8* faceIndices = convexIndices + face.mIndexBase;
-				for (UINT32 j = 0; j < face.mNbVerts; j++)
-					posIter.addValue(fromPxVector(convexVertices[faceIndices[j]]));
-
 				for (UINT32 j = 2; j < face.mNbVerts; j++)
 				{
-					*outIndices++ = offset;
-					*outIndices++ = offset + j;
-					*outIndices++ = offset + j - 1;
+					*outIndices++ = faceIndices[0];
+					*outIndices++ = faceIndices[j];
+					*outIndices++ = faceIndices[j - 1];
 				}
-
-				offset += face.mNbVerts;
 			}
 		}
 		else

+ 4 - 4
Source/MBansheeEditor/Scene/Gizmos/ColliderGizmos.cs

@@ -19,7 +19,7 @@ namespace BansheeEditor
             SceneObject so = collider.SceneObject;
 
             Gizmos.Color = Color.Green;
-            Gizmos.Transform = so.WorldTransform;
+            Gizmos.Transform = Matrix4.TRS(so.Position, so.Rotation, Vector3.One);
 
             Vector3 scaledExtents = collider.Extents*so.Scale;
             Gizmos.DrawWireCube(collider.Center, scaledExtents);
@@ -35,7 +35,7 @@ namespace BansheeEditor
             SceneObject so = collider.SceneObject;
 
             Gizmos.Color = Color.Green;
-            Gizmos.Transform = so.WorldTransform;
+            Gizmos.Transform = Matrix4.TRS(so.Position, so.Rotation, Vector3.One);
 
             Vector3 scale = so.Scale;
             float scaledRadius = collider.Radius * MathEx.Max(scale.x, scale.y, scale.z);
@@ -61,7 +61,7 @@ namespace BansheeEditor
                 Matrix4.TRS(-offset, Quaternion.Identity, Vector3.One);
 
             Gizmos.Color = Color.Green;
-            Gizmos.Transform = so.WorldTransform * rotMatrix;
+            Gizmos.Transform = Matrix4.TRS(so.Position, so.Rotation, Vector3.One) * rotMatrix;
 
             Vector3 scale = so.Scale;
             float scaledHeight = collider.HalfHeight*2.0f*scale.y;
@@ -109,7 +109,7 @@ namespace BansheeEditor
                 Matrix4.TRS(-center, Quaternion.Identity, Vector3.One);
 
             Gizmos.Color = Color.Green;
-            Gizmos.Transform = so.WorldTransform * rotMatrix;
+            Gizmos.Transform = Matrix4.TRS(so.Position, so.Rotation, Vector3.One) * rotMatrix;
 
             Vector3 bottomLeft = new Vector3(0.0f, -0.5f, -0.5f);
             Vector3 topLeft = new Vector3(0.0f, 0.5f, -0.5f);

+ 5 - 0
Source/MBansheeEngine/Physics/CapsuleCollider.cs

@@ -101,6 +101,11 @@ namespace BansheeEngine
             }
         }
 
+        public CapsuleCollider()
+        {
+            serializableData.localRotation = Quaternion.FromToRotation(Vector3.XAxis, normal);
+        }
+
         /// <summary>
         /// Returns the native capsule collider wrapped by this component.
         /// </summary>

+ 80 - 75
Source/MBansheeEngine/Physics/PlaneCollider.cs

@@ -1,75 +1,80 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-namespace BansheeEngine
-{
-    /// <summary>
-    /// Collider with plane geometry.
-    /// </summary>
-    public sealed class PlaneCollider : Collider
-    {
-        [SerializeField]
-        private float distance;
-
-        [SerializeField]
-        private Vector3 normal = new Vector3(1.0f, 0.0f, 0.0f);
-
-        /// <summary>
-        /// Distance of the plane from the local origin, along its normal vector.
-        /// </summary>
-        public float Distance
-        {
-            get { return distance; }
-            set
-            {
-                if (distance == value)
-                    return;
-
-                distance = value;
-                serializableData.localPosition = normal * distance;
-
-                if (Native != null)
-                    UpdateTransform();
-            }
-        }
-
-        /// <summary>
-        /// Normal vector of the plane. It determines how is the plane oriented.
-        /// </summary>
-        public Vector3 Normal
-        {
-            get { return normal; }
-            set
-            {
-                if (normal == value)
-                    return;
-
-                normal = value.Normalized;
-                serializableData.localRotation = Quaternion.FromToRotation(Vector3.XAxis, normal);
-
-                if (Native != null)
-                    UpdateTransform();
-            }
-        }
-
-        /// <inheritdoc/>
-        protected internal override bool IsValidParent(Rigidbody parent)
-    	{
-		    // Planes cannot be added to non-kinematic rigidbodies
-		    return parent.Kinematic;
-        }
-
-        /// <summary>
-        /// Returns the native plane collider wrapped by this component.
-        /// </summary>
-        private NativePlaneCollider Native
-        {
-            get { return (NativePlaneCollider)native; }
-        }
-
-        /// <inheritdoc/>
-        internal override NativeCollider CreateCollider()
-        {
-            return new NativePlaneCollider();
-        }
-    }
-}
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+namespace BansheeEngine
+{
+    /// <summary>
+    /// Collider with plane geometry.
+    /// </summary>
+    public sealed class PlaneCollider : Collider
+    {
+        [SerializeField]
+        private float distance;
+
+        [SerializeField]
+        private Vector3 normal = new Vector3(1.0f, 0.0f, 0.0f);
+
+        /// <summary>
+        /// Distance of the plane from the local origin, along its normal vector.
+        /// </summary>
+        public float Distance
+        {
+            get { return distance; }
+            set
+            {
+                if (distance == value)
+                    return;
+
+                distance = value;
+                serializableData.localPosition = normal * distance;
+
+                if (Native != null)
+                    UpdateTransform();
+            }
+        }
+
+        /// <summary>
+        /// Normal vector of the plane. It determines how is the plane oriented.
+        /// </summary>
+        public Vector3 Normal
+        {
+            get { return normal; }
+            set
+            {
+                if (normal == value)
+                    return;
+
+                normal = value.Normalized;
+                serializableData.localRotation = Quaternion.FromToRotation(Vector3.XAxis, normal);
+
+                if (Native != null)
+                    UpdateTransform();
+            }
+        }
+
+        /// <inheritdoc/>
+        protected internal override bool IsValidParent(Rigidbody parent)
+    	{
+		    // Planes cannot be added to non-kinematic rigidbodies
+		    return parent.Kinematic;
+        }
+
+        /// <summary>
+        /// Returns the native plane collider wrapped by this component.
+        /// </summary>
+        private NativePlaneCollider Native
+        {
+            get { return (NativePlaneCollider)native; }
+        }
+
+        public PlaneCollider()
+        {
+            serializableData.localRotation = Quaternion.FromToRotation(Vector3.XAxis, normal);
+        }
+
+        /// <inheritdoc/>
+        internal override NativeCollider CreateCollider()
+        {
+            return new NativePlaneCollider();
+        }
+    }
+}