void CreateSoftBody() { CreateBody(); m_trussID = TxNative.CreateTruss(m_truss); m_trussInstanceID = TxNative.WorldObjectAttachTruss(worldID, objectID, m_trussID); TxNative.TrussInstanceSetMassScale(worldID, m_trussInstanceID, m_massScale); if (m_collision) { m_matterIDs = new int[m_matters.Length]; for (int i = 0; i < m_matterIDs.Length; ++i) { m_matterIDs[i] = TxNative.CreateMatter(m_matters[i]); } m_shapeID = TxNative.CreateShape(); TxNative.ShapeSetTruss(m_shapeID, m_trussID); if (m_matterIDs.Length > 0) { TxNative.ShapeSetMatterCount(m_shapeID, m_matterIDs.Length); TxNative.ShapeSetMatters(m_shapeID, m_matterIDs, 0, m_matterIDs.Length); } TxNative.ShapeSetMargin(m_shapeID, m_margin); TxNative.WorldObjectAttachShape(worldID, objectID, m_shapeID); } if (m_skinning) { m_meshFilter = GetComponent <MeshFilter>(); if (m_meshFilter) { m_sharedMesh = m_meshFilter.sharedMesh; m_meshID = TxNative.CreateMesh(m_meshFilter.sharedMesh); m_skinID = TxNative.CreateSkin(); TxNative.SkinSetup(m_skinID, m_trussID, m_meshID, true); TxNative.WorldObjectAttachSkin(worldID, objectID, m_skinID); m_positions = m_sharedMesh.vertices; //new Vector3[m_meshFilter.sharedMesh.vertexCount]; m_normals = m_sharedMesh.normals; //new Vector3[m_meshFilter.sharedMesh.vertexCount]; m_tangents = m_sharedMesh.tangents; } } if (m_filling) { TxNative.TrussInstanceSetInternalPressure(worldID, m_trussInstanceID, m_internalPressure); TxNative.TrussInstanceSetAdiabaticIndex(worldID, m_trussInstanceID, m_adiabaticIndex); } else { TxNative.TrussInstanceSetInternalPressure(worldID, m_trussInstanceID, 0); TxNative.TrussInstanceSetAdiabaticIndex(worldID, m_trussInstanceID, 0); } if (m_spawnActive) { TxNative.WorldObjectSetActive(worldID, objectID, true); } if (m_deactivation) { TxNative.TrussInstanceSetDeactivationSpeed(worldID, m_trussInstanceID, m_deactivationSpeed); TxNative.TrussInstanceSetDeactivationTime(worldID, m_trussInstanceID, m_deactivationTime); } else { TxNative.TrussInstanceSetDeactivationSpeed(worldID, m_trussInstanceID, 0); TxNative.TrussInstanceSetDeactivationTime(worldID, m_trussInstanceID, float.MaxValue); } if (m_fastRotation) { TxNative.TrussInstanceSetFastRotation(worldID, m_trussInstanceID, true); } }
void CreateRigidBody() { m_rigidBody = GetComponent <Rigidbody>(); Rigidbody rb = m_rigidBody; m_rigidID = TxNative.CreateRigid(); TxNative.RigidSetType(m_rigidID, (int)m_interaction); TxNative.RigidSetMass(m_rigidID, rb.mass * m_massScale, rb.centerOfMass, rb.inertiaTensor * m_massScale, rb.inertiaTensorRotation); // Unity 4 crash on object duplicate CreateBody(); m_rigidInstanceID = TxNative.WorldObjectAttachRigid(worldID, objectID, m_rigidID); if (m_collision != CollisionType.None) { m_matterIDs = new int[m_matters.Length]; for (int i = 0; i < m_matterIDs.Length; ++i) { m_matterIDs[i] = TxNative.CreateMatter(m_matters[i]); } m_shapeID = TxNative.CreateShape(); Mesh shapeMesh; Vector3 shapeCenter, shapeSize; int capsuleDirection; switch (DetectCollisionType(out shapeMesh, out shapeCenter, out shapeSize, out capsuleDirection)) { case CollisionType.Mesh: { if (shapeMesh != null) { m_colliderID = TxNative.CreateMesh(shapeMesh); TxNative.ShapeSetMesh(m_shapeID, m_colliderID); } break; } case CollisionType.Convex: { if (shapeMesh != null) { m_colliderID = TxNative.CreateConvex(shapeMesh); TxNative.ShapeSetConvex(m_shapeID, m_colliderID); } break; } case CollisionType.Box: { m_colliderID = TxNative.CreateConvex(shapeCenter, shapeSize); TxNative.ShapeSetConvex(m_shapeID, m_colliderID); break; } case CollisionType.Capsule: { m_colliderID = TxNative.CreateConvex(shapeCenter, shapeSize.x, shapeSize.y, capsuleDirection); TxNative.ShapeSetConvex(m_shapeID, m_colliderID); break; } case CollisionType.Sphere: { m_colliderID = TxNative.CreateConvex(shapeCenter, shapeSize.x); TxNative.ShapeSetConvex(m_shapeID, m_colliderID); break; } } TxNative.ShapeSetMatterCount(m_shapeID, m_matterIDs.Length); TxNative.ShapeSetMatters(m_shapeID, m_matterIDs, 0, m_matterIDs.Length); TxNative.ShapeSetMargin(m_shapeID, m_margin); TxNative.WorldObjectAttachShape(worldID, objectID, m_shapeID); } TxPhysics.onBeforePhysX += OnBeforePhysX; }
void CreateStaticBody() { CreateBody(); if (m_collision != CollisionType.None) { m_matterIDs = new int[m_matters.Length]; for (int i = 0; i < m_matterIDs.Length; ++i) { m_matterIDs[i] = TxNative.CreateMatter(m_matters[i]); } m_shapeID = TxNative.CreateShape(); Mesh shapeMesh; TerrainData shapeTerrain; Vector3 shapeCenter, shapeSize; int capsuleDirection; switch (DetectCollisionType(out shapeMesh, out shapeTerrain, out shapeCenter, out shapeSize, out capsuleDirection)) { case CollisionType.Mesh: { if (shapeMesh != null) { m_colliderID = TxNative.CreateMesh(shapeMesh); TxNative.ShapeSetMesh(m_shapeID, m_colliderID); } break; } case CollisionType.Terrain: { if (shapeTerrain != null) { m_colliderID = TxNative.CreateTerrain(shapeTerrain); TxNative.ShapeSetTerrain(m_shapeID, m_colliderID); } break; } case CollisionType.Convex: { if (shapeMesh != null) { m_colliderID = TxNative.CreateConvex(shapeMesh); TxNative.ShapeSetConvex(m_shapeID, m_colliderID); } break; } case CollisionType.Box: { m_colliderID = TxNative.CreateConvex(shapeCenter, shapeSize); TxNative.ShapeSetConvex(m_shapeID, m_colliderID); break; } case CollisionType.Capsule: { m_colliderID = TxNative.CreateConvex(shapeCenter, shapeSize.x, shapeSize.y, capsuleDirection); TxNative.ShapeSetConvex(m_shapeID, m_colliderID); break; } case CollisionType.Sphere: { m_colliderID = TxNative.CreateConvex(shapeCenter, shapeSize.x); TxNative.ShapeSetConvex(m_shapeID, m_colliderID); break; } } TxNative.ShapeSetMatterCount(m_shapeID, m_matterIDs.Length); TxNative.ShapeSetMatters(m_shapeID, m_matterIDs, 0, m_matterIDs.Length); TxNative.ShapeSetMargin(m_shapeID, m_margin); TxNative.WorldObjectAttachShape(worldID, objectID, m_shapeID); } }