protected override void SetWorldAndRenderTechnich(out IRenderTechnic renderTech, out IWorld world) { PhysxPhysicWorld PhysxPhysicWorld = new PhysxPhysicWorld(new Vector3(0,-10,0)); world = new IWorld(PhysxPhysicWorld, new SimpleCuller()); ForwardRenderTecnichDescription desc = ForwardRenderTecnichDescription.Default(); desc.BackGroundColor = Color.CornflowerBlue; renderTech = new ForwardRenderTecnich(desc); }
/// <summary> /// Initializes a new instance of the <see cref="PhysxTriangleMesh"/> class. /// For cooked Models /// </summary> /// <param name="PhysxPhysicWorld">The physx physic world.</param> /// <param name="FileStream">The file stream.</param> /// <param name="localTransformation">The local transformation.</param> /// <param name="worldTransformation">The world transformation.</param> /// <param name="scale">The scale.</param> /// <param name="MaterialDescription">The material description.</param> 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.Core.CreateTriangleMesh(FileStream); TriangleMeshShapeDescription bunnyShapeDesc = new TriangleMeshShapeDescription(); bunnyShapeDesc.TriangleMesh = triangleMesh; BodyDescription bodyDesc = new BodyDescription(); ActorDesc.Shapes.Add(bunnyShapeDesc); ActorDesc.BodyDescription = bodyDesc; 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; }
/// <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; }
/// <summary> /// Initializes a new instance of the <see cref="SimpleModel"/> class. /// </summary> /// <param name="factory">The graphic factory.</param> /// <param name="PhysxPhysicWorld">The physx physic world.</param> /// <param name="clothMeshDesc">The cloth mesh desc.</param> /// <param name="Points">The points.</param> /// <param name="TextCoords">The text coords.</param> /// <param name="Indices">The indices.</param> /// <param name="diffuseTextureName">Name of the diffuse texture.</param> public ClothModel(GraphicFactory factory, PhysxPhysicWorld PhysxPhysicWorld, ClothMeshDescription clothMeshDesc, Vector3[] Points , Vector2[] TextCoords , int[] Indices , String diffuseTextureName = null) : base(factory, "Cloth", false) { this._diffuseName = diffuseTextureName; VerticesNum = Points.Length; IndicesNum = Indices.Length; clothMeshDesc.AllocateVertices<Vector3>(VerticesNum); clothMeshDesc.AllocateTriangles<int>(IndicesNum / 3); clothMeshDesc.VertexCount = VerticesNum; clothMeshDesc.TriangleCount = IndicesNum / 3; BatchInformation = new PloobsEngine.Modelo.BatchInformation(0, VerticesNum, IndicesNum / 3, 0, 0, VertexPositionNormalTexture.VertexDeclaration, VertexPositionNormalTexture.VertexDeclaration.VertexStride, PrimitiveType.TriangleList); BatchInformation.ModelLocalTransformation = XNA.Matrix.Identity; vertexPositionNormalTexture = new VertexPositionNormalTexture[VerticesNum]; BatchInformation.VertexBuffer = factory.CreateDynamicVertexBuffer(VertexPositionNormalTexture.VertexDeclaration, VerticesNum + (int)(1.2 * VerticesNum), BufferUsage.WriteOnly); BatchInformation.IndexBuffer = factory.CreateDynamicIndexBuffer(IndexElementSize.ThirtyTwoBits, IndicesNum + (int)(1.2 * IndicesNum), BufferUsage.WriteOnly); BatchInformation.IndexBuffer.SetData<int>(Indices); clothMeshDesc.VerticesStream.SetData(Points); clothMeshDesc.TriangleStream.SetData(Indices); XNA.Vector3[] pts = new XNA.Vector3[BatchInformation.NumVertices]; for (int i = 0; i < BatchInformation.NumVertices; i++) { vertexPositionNormalTexture[i].TextureCoordinate = TextCoords[i].AsXNA(); vertexPositionNormalTexture[i].Position = Points[i].AsXNA(); pts[i] = vertexPositionNormalTexture[i].Position; } modelRadius = Microsoft.Xna.Framework.BoundingSphere.CreateFromPoints(pts).Radius; pts = null; // We are using 32 bit integers for our indices, so make sure the 16 bit flag is removed. // 32 bits are the default, so this isn't technically needed, but it's good to show in a sample clothMeshDesc.Flags &= ~MeshFlag.Indices16Bit; //clothMeshDesc.Flags |= (MeshFlag)((int)clothMeshDesc.Flags | (int)ClothMeshFlag.Tearable); // Write the cooked data to memory using (var memoryStream = new MemoryStream()) { Cooking.InitializeCooking(); Cooking.CookClothMesh(clothMeshDesc, memoryStream); Cooking.CloseCooking(); // Need to reset the position of the stream to the beginning memoryStream.Position = 0; ClothMesh = PhysxPhysicWorld.Core.CreateClothMesh(memoryStream); } LoadModel(factory, out BatchInformations, out TextureInformations); }