public PhysxTriangleMesh(PhysxPhysicWorld PhysxPhysicWorld, IModelo model,Microsoft.Xna.Framework.Matrix localTransformation, Microsoft.Xna.Framework.Matrix worldTransformation, Microsoft.Xna.Framework.Vector3 scale, MaterialDescription MaterialDescription)
        {
            Microsoft.Xna.Framework.Vector3[] vertices = null;
            int[] indices = null;
            ExtractData(ref vertices, ref indices, model);                                    

            
            TriangleMeshDesc meshDesc = new TriangleMeshDesc();            
            Vector3[] points = new Vector3[vertices.Count()];
            for (int i = 0; i < vertices.Count(); i++)
			{
			    points[i] = vertices[i].AsPhysX();
			}            
            meshDesc.Points = points;            
            meshDesc.SetTriangles<int>(indices);
            //meshDesc.Triangles = indices;
            
            MemoryStream ms = new MemoryStream();
            if(PhysxPhysicWorld.Cooking.CookTriangleMesh(meshDesc,ms)==false)
            {
                PloobsEngine.Engine.Logger.ActiveLogger.LogMessage("Cant Cook Model",Engine.Logger.LogLevel.FatalError);
            }
            
            ms.Position = 0;
            TriangleMesh triangleMesh = PhysxPhysicWorld.Physix.CreateTriangleMesh(ms);
            
            staticActor = PhysxPhysicWorld.Physix.CreateRigidStatic(worldTransformation.AsPhysX());
            TriangleMeshGeometry TriangleMeshGeometry = new TriangleMeshGeometry(triangleMesh,new MeshScale(scale.AsPhysX(),Quaternion.Identity));

            material = PhysxPhysicWorld.Physix.CreateMaterial(MaterialDescription.StaticFriction, MaterialDescription.DynamicFriction, MaterialDescription.Bounciness);
            aTriMeshShape = staticActor.CreateShape(TriangleMeshGeometry, material, localTransformation.AsPhysX());

            this.Scale = scale;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PhysxTriangleMesh"/> class.
        /// Cooks the Model on the fly
        /// </summary>
        /// <param name="PhysxPhysicWorld">The physx physic world.</param>
        /// <param name="model">The model.</param>
        /// <param name="worldTransformation">The world transformation.</param>
        /// <param name="scale">The scale.</param>
        /// <param name="density">The density.</param>
        /// <param name="material">The material.</param>
        public PhysxTriangleMesh(PhysxPhysicWorld PhysxPhysicWorld, IModelo model, Microsoft.Xna.Framework.Matrix worldTransformation, Microsoft.Xna.Framework.Vector3 scale, float density = 1,StillDesign.PhysX.Material material = null)
        {
            Microsoft.Xna.Framework.Vector3[] vertices = null;
            int[] indices = null;
            ExtractData(ref vertices, ref indices, model);


            TriangleMeshDescription meshDesc = new TriangleMeshDescription();
            meshDesc.AllocateVertices<Microsoft.Xna.Framework.Vector3>(vertices.Count());            
            meshDesc.VerticesStream.SetData<Microsoft.Xna.Framework.Vector3>(vertices);
            meshDesc.AllocateTriangles<int>(indices.Count());
            meshDesc.TriangleStream.SetData<int>(indices);
            meshDesc.Flags = 0;
            meshDesc.VertexCount = vertices.Count();
            meshDesc.TriangleCount = indices.Count();

            MemoryStream ms = new MemoryStream();
            Cooking.InitializeCooking();            
            if (Cooking.CookTriangleMesh(meshDesc, ms) == false)
            {
                PloobsEngine.Engine.Logger.ActiveLogger.LogMessage("Cant Cook Model",Engine.Logger.LogLevel.FatalError);
            }
            Cooking.CloseCooking();

            ms.Position = 0;
            TriangleMesh triangleMesh = PhysxPhysicWorld.Core.CreateTriangleMesh(ms);
            TriangleMeshShapeDescription bunnyShapeDesc = new TriangleMeshShapeDescription();
            if (material != null)
                bunnyShapeDesc.Material = material;
            bunnyShapeDesc.TriangleMesh = triangleMesh;                
            ActorDesc = new ActorDescription();
            ActorDesc.Shapes.Add(bunnyShapeDesc);            
            ActorDesc.BodyDescription= null;
            ActorDesc.GlobalPose = worldTransformation.AsPhysX();            
            this.Scale = scale;
        }
        public PhysxTriangleMesh(PhysxPhysicWorld PhysxPhysicWorld, FileStream FileStream, Microsoft.Xna.Framework.Matrix localTransformation, Microsoft.Xna.Framework.Matrix worldTransformation, Microsoft.Xna.Framework.Vector3 scale, MaterialDescription MaterialDescription)
        {
            TriangleMesh triangleMesh = PhysxPhysicWorld.Physix.CreateTriangleMesh(FileStream);

            staticActor = PhysxPhysicWorld.Physix.CreateRigidStatic(worldTransformation.AsPhysX());
            TriangleMeshGeometry TriangleMeshGeometry = new TriangleMeshGeometry(triangleMesh, new MeshScale(scale.AsPhysX(), Quaternion.Identity));

            material = PhysxPhysicWorld.Physix.CreateMaterial(MaterialDescription.StaticFriction, MaterialDescription.DynamicFriction, MaterialDescription.Bounciness);
            aTriMeshShape = staticActor.CreateShape(TriangleMeshGeometry, material, localTransformation.AsPhysX());

            this.Scale = scale;
        }
 public PhysxStaticActor(PhysxPhysicWorld PhysxPhysicWorld ,Geometry geometry, Microsoft.Xna.Framework.Matrix localTransformation, Microsoft.Xna.Framework.Matrix worldTransformation, Microsoft.Xna.Framework.Vector3 scale, MaterialDescription MaterialDescription)
 {            
     staticActor = PhysxPhysicWorld.Physix.CreateRigidStatic(worldTransformation.AsPhysX());
     material = PhysxPhysicWorld.Physix.CreateMaterial(MaterialDescription.StaticFriction, MaterialDescription.DynamicFriction, MaterialDescription.Bounciness);
     Shape aTriMeshShape = staticActor.CreateShape(geometry, material, localTransformation.AsPhysX());
 }