public override void Run() { var conf = new DefaultCollisionConfiguration(); var dispatcher = new CollisionDispatcher(conf); var broadphase = new AxisSweep3(new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000)); world = new DiscreteDynamicsWorld(dispatcher, broadphase, null, conf); var indexVertexArray = new TriangleIndexVertexArray(TorusMesh.Indices, TorusMesh.Vertices); foreach (var indexedMesh in indexVertexArray.IndexedMeshArray) { indexedMesh.ToString(); } AddToDisposeQueue(indexVertexArray); var gImpactMesh = new GImpactMeshShape(indexVertexArray); Vector3 aabbMin, aabbMax; gImpactMesh.GetAabb(Matrix.Identity, out aabbMin, out aabbMax); CreateBody(1.0f, gImpactMesh, Vector3.Zero); AddToDisposeQueue(gImpactMesh); gImpactMesh = null; var triangleMesh = new BvhTriangleMeshShape(indexVertexArray, true); triangleMesh.CalculateLocalInertia(1.0f); triangleMesh.GetAabb(Matrix.Identity, out aabbMin, out aabbMax); CreateBody(1.0f, triangleMesh, Vector3.Zero); AddToDisposeQueue(triangleMesh); triangleMesh = null; indexVertexArray = null; AddToDisposeQueue(conf); AddToDisposeQueue(dispatcher); AddToDisposeQueue(broadphase); AddToDisposeQueue(world); //conf.Dispose(); conf = null; //dispatcher.Dispose(); dispatcher = null; //broadphase.Dispose(); broadphase = null; for (int i = 0; i < 600; i++) { world.StepSimulation(1.0f / 60.0f); } world.Dispose(); world = null; ForceGC(); TestWeakRefs(); ClearRefs(); }
public void TriangleMeshTest1() { TestTriangleArray(indexVertexArray); TestTriangleArray(indexVertexArray2); Vector3 aabbMin, aabbMax; gImpactMeshShape.GetAabb(Matrix.Identity, out aabbMin, out aabbMax); triangleMeshShape.GetAabb(Matrix.Identity, out aabbMin, out aabbMax); for (int i = 0; i < 600; i++) { world.StepSimulation(1.0f / 60.0f); } }
public MeshCollider(GameObject obj) { gameObject = obj; MeshIndices.AddRange(gameObject.GetMeshRender()._mesh._indices); for (int i = 0; i < gameObject.GetMeshRender()._mesh._vertices.Length; i += 3) { Vector3 pos = new Vector3(gameObject.GetMeshRender()._mesh._vertices[i], gameObject.GetMeshRender()._mesh._vertices[i + 1], gameObject.GetMeshRender()._mesh._vertices[i + 2]); MeshVertices.Add(pos); } //ANTIGO ANTIGO ANTIGO // Initialize TriangleIndexVertexArray with float array /*indexVertexArray = new TriangleIndexVertexArray(MeshIndices.ToArray(), MeshVertices.ToArray()); * gImpactMeshShape = new GImpactMeshShape(indexVertexArray); * gImpactMeshShape.CalculateLocalInertia(1.0f); * gImpactMesh = CreateBody(1.0f, gImpactMeshShape, Vector3.Zero);*/ indexVertexArray2 = new TriangleIndexVertexArray(MeshIndices.ToArray(), MeshVertices.ToArray()); triangleMeshShape = new BvhTriangleMeshShape(indexVertexArray2, true); _collisionObject = new CollisionObject(); _collisionObject.WorldTransform = gameObject._transform.RotationMatrix * gameObject._transform.PositionMatrix * Matrix4.CreateScale(gameObject._transform.Size); _collisionObject.CollisionShape = triangleMeshShape; //TestTriangleArray(indexVertexArray); //TestTriangleArray(indexVertexArray2); Vector3 aabbMin, aabbMax; //gImpactMeshShape.GetAabb(Matrix4.Identity, out aabbMin, out aabbMax); triangleMeshShape.GetAabb(Matrix4.Identity, out aabbMin, out aabbMax); Physics.AddCollisionObject(_collisionObject); }