public void SetupSimData(PhysXRigidBody attachedRigidBody, IntPtr wheelSimData, int wheelNum, uint vehicleId) { if (autoCalculateSpringStrength) { float sprungMass = PhysXLib.GetSuspensionSprungMass(suspension); suspensionSpringStrength = (Physics.gravity.magnitude * sprungMass) / (suspensionDistance * (1 - suspensionSpringTargetPosition)); } this.wheelNum = wheelNum; this.attachedRigidBody = attachedRigidBody; Transform bodyParent = attachedRigidBody.transform; PhysXVec3 wheelCentrePos = new PhysXVec3(bodyParent.InverseTransformPoint(transform.TransformPoint(wheelCentre))); PhysXVec3 forceAppPos = new PhysXVec3(bodyParent.InverseTransformPoint(transform.TransformPoint(wheelCentre + forceAppPoint))); PhysXLib.SetWheelSimForceAppPoint(wheelSimData, wheelNum, forceAppPos); PhysXLib.SetWheelSimWheelCentre(wheelSimData, wheelNum, wheelCentrePos); PhysXLib.SetWheelSimWheelData(wheelSimData, wheelNum, wheel); PhysXLib.SetWheelSimTireData(wheelSimData, wheelNum, tire); PhysXLib.SetWheelSimSuspensionData(wheelSimData, wheelNum, suspension, new PhysXVec3(-transform.up)); PhysXLib.SetWheelSimWheelShape(wheelSimData, wheelNum, -1); PhysXLib.SetWheelSimQueryFilterData(wheelSimData, wheelNum, 0, 0, 0, vehicleId); }
// Start is called before the first frame update public virtual void Setup(PhysXBody attachedRigidBody, uint vehicleId) { this.attachedRigidBody = attachedRigidBody as PhysXRigidBody; Transform bodyParent = attachedRigidBody.transform; PhysXVec3 position = new PhysXVec3(bodyParent.InverseTransformPoint(transform.TransformPoint(offset))); PhysXQuat rotation = new PhysXQuat(transform.rotation * Quaternion.Inverse(bodyParent.rotation)); IntPtr localTransform = PhysXLib.CreateTransform(position, rotation); PhysXLib.SetShapeLocalTransform(shape, localTransform); PhysXLib.SetShapeSimulationFlag(shape, !trigger); PhysXLib.SetShapeSceneQueryFlag(shape, !trigger); PhysXLib.SetShapeTriggerFlag(shape, trigger); PhysXLib.CollisionEvent collisionEventFlags = attachedRigidBody.collisionEventFlags; PhysXLib.SetCollisionFilterData(shape, (UInt32)ownLayers, (UInt32)collisionLayers, (UInt32)collisionEventFlags, vehicleId); PhysXLib.SetQueryFilterData(shape, (UInt32)ownLayers, 0, 0, vehicleId); shapeNum = attachedRigidBody.AddCollider(this); }
// private Mesh meshMesh = null; // Start is called before the first frame update public override void Setup(PhysXBody attachedRigidBody, uint vehicleId) { if (mesh == null) { Debug.LogError("Collider mesh is null on " + gameObject.name); } else if (!mesh.isReadable) { Debug.LogError("Collider mesh: " + mesh.name + " is not readable"); } else { // meshMesh = Instantiate(mesh); // meshMesh.Clear(); // List<Vector3> meshMeshVertices = new List<Vector3>(); IntPtr vertexArray = PhysXLib.CreateVectorArray(); Vector3[] unscaledVertices = mesh.vertices; Vector3[] vertices = new Vector3[unscaledVertices.Length]; for (int i = 0; i < unscaledVertices.Length; i++) { vertices[i] = new Vector3(unscaledVertices[i].x * scale.x, unscaledVertices[i].y * scale.y, unscaledVertices[i].z * scale.z); // vertices[i] = unscaledVertices[i];//new Vector3(unscaledVertices[i].x * scale.x, unscaledVertices[i].y * scale.y, unscaledVertices[i].z * scale.z); } Vector3 centre = Vector3.zero; foreach (Vector3 vertex in vertices) { centre += vertex; } centre /= vertices.Length; // offset += new Vector3(centre.x * scale.x, centre.y * scale.y, centre.z * scale.z); offset += centre; PhysXVec3 physXVertex = new PhysXVec3(Vector3.zero); foreach (Vector3 vertex in vertices) { physXVertex.FromVector(vertex - centre); PhysXLib.AddVectorToArray(vertexArray, physXVertex); } IntPtr geom = IntPtr.Zero; if (convex) { geom = PhysXLib.CreateConvexMeshGeometry(vertexArray, new PhysXVec3(Vector3.one)); } else { geom = PhysXLib.CreateMeshGeometry(vertexArray, mesh.triangles, mesh.triangles.Length / 3, new PhysXVec3(Vector3.one)); } shape = PhysXLib.CreateShape(geom, physXMaterial, 0.02f); // if (!convex) { // int vertexCount = PhysXLib.GetMeshVertexCount(geom); // int triCount = PhysXLib.GetMeshTriangleCount(geom); // IntPtr usedVertices = PhysXLib.CreateVectorArray(); // int[] usedTris = new int[triCount * 3]; // PhysXLib.GetMeshGeometry(geom, usedVertices, usedTris); // for (int i = 0; i < vertexCount; i++) { // PhysXLib.GetVectorFromArray(usedVertices, physXVertex, i); // meshMeshVertices.Add(physXVertex.ToVector()); // } // meshMesh.SetVertices(meshMeshVertices); // meshMesh.triangles = usedTris; // meshMesh.RecalculateNormals(); // } base.Setup(attachedRigidBody, vehicleId); } }
public static bool FireRaycastFiltered(PhysXVec3 origin, PhysXVec3 direction, float distance, IntPtr raycastHit, uint w0, uint w1, uint w2, uint w3) { return(PhysXLib.FireRaycastFiltered(scene, origin, direction, distance, raycastHit, w0, w1, w2, w3)); }
public static bool FireRaycast(PhysXVec3 origin, PhysXVec3 direction, float distance, IntPtr raycastHit) { return(PhysXLib.FireRaycast(scene, origin, direction, distance, raycastHit)); }