/// <summary> /// Loads the model. /// </summary> /// <param name="factory">The factory.</param> /// <param name="BatchInformations">The batch informations.</param> /// <param name="TextureInformations">The texture informations.</param> protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformations) { VertexPositionTexture[] billboardVertices = new VertexPositionTexture[4]; int i = 0; billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(0, 0)); billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(1, 0)); billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(0, 1)); billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(1, 1)); VertexElement v0 = new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.TextureCoordinate, 1); VertexElement v1 = new VertexElement(sizeof(float) * 3, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 2); vd = new VertexDeclaration(v0, v1); VertexBuffer InstancedvertexBufferS; if (dynamicBufferSize != -1) { InstancedvertexBufferS = factory.CreateDynamicVertexBuffer(vd, dynamicBufferSize, BufferUsage.WriteOnly); } else { InstancedvertexBufferS = factory.CreateDynamicVertexBuffer(vd, instances.Count(), BufferUsage.WriteOnly); } InstancedvertexBufferS.SetData(instances); VertexBuffer vertexBufferS = factory.CreateVertexBuffer(VertexPositionTexture.VertexDeclaration, billboardVertices.Count(), BufferUsage.WriteOnly); vertexBufferS.SetData(billboardVertices); short[] indices = new short[] { 0, 2, 1, 1, 2, 3 }; IndexBuffer indexBufferS = factory.CreateIndexBuffer(IndexElementSize.SixteenBits, 6, BufferUsage.WriteOnly); indexBufferS.SetData <short>(indices); BatchInformations = new BatchInformation[1][]; BatchInformation[] b = new BatchInformation[1]; b[0] = new BatchInformation(0, 4, 2, 0, 0, VertexPositionTexture.VertexDeclaration, VertexPositionTexture.VertexDeclaration.VertexStride, instances.Count()); b[0].VertexBuffer = vertexBufferS; b[0].IndexBuffer = indexBufferS; b[0].InstancedVertexBuffer = InstancedvertexBufferS; BatchInformations[0] = b; TextureInformations = new TextureInformation[1][]; TextureInformations[0] = new TextureInformation[1]; TextureInformations[0][0] = new TextureInformation(isInternal, factory, diffuseTextureName, null, null, null); TextureInformations[0][0].LoadTexture(); }
protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformations) { billboardVertices = new VertexPositionTexture[maximumaParticles * 6]; for (int i = 0; i < maximumaParticles * 6;) { billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(0, 0)); billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(1, 0)); billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(1, 1)); billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(0, 0)); billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(1, 1)); billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(0, 1)); } VertexBuffer vertexBufferS = factory.CreateDynamicVertexBuffer(VertexPositionTexture.VertexDeclaration, billboardVertices.Count(), BufferUsage.WriteOnly); vertexBufferS.SetData(billboardVertices); int noVertices = billboardVertices.Count(); int noTriangles = noVertices / 3; BatchInformations = new BatchInformation[1][]; BatchInformation[] b = new BatchInformation[1]; b[0] = new BatchInformation(0, 0, noTriangles, 0, 0, VertexPositionTexture.VertexDeclaration, VertexPositionTexture.VertexDeclaration.VertexStride, BatchType.NORMAL); b[0].VertexBuffer = vertexBufferS; b[0].IndexBuffer = null; BatchInformations[0] = b; TextureInformations = new TextureInformation[1][]; TextureInformations[0] = new TextureInformation[1]; TextureInformations[0][0] = new TextureInformation(false, factory, diffuseTextureName, null, null, null); TextureInformations[0][0].LoadTexture(); }
public ClothModel(GraphicFactory factory, PhysxPhysicWorld PhysxPhysicWorld, ClothMeshDescription clothMeshDesc, XNA.Vector3[] Points, XNA.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); for (int i = 0; i < BatchInformation.NumVertices; i++) { vertexPositionNormalTexture[i].TextureCoordinate = TextCoords[i]; vertexPositionNormalTexture[i].Position = Points[i]; } // 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); } modelRadius = Microsoft.Xna.Framework.BoundingSphere.CreateFromPoints(Points).Radius; LoadModel(factory, out BatchInformations, out TextureInformations); }
protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformation) { vertexBufferS = factory.CreateDynamicVertexBuffer(VertexPositionTexture.VertexDeclaration, vertices.Count(), BufferUsage.None); vertexBufferS.SetData(vertices); int noVertices = vertices.Count(); int noTriangles = indices.Count() / 3; indexBufferS = factory.CreateDynamicIndexBuffer(IndexElementSize.ThirtyTwoBits, indices.Count(), BufferUsage.None); indexBufferS.SetData(indices); BatchInformations = new BatchInformation[1][]; BatchInformation[] b = new BatchInformation[1]; b[0] = new BatchInformation(0, noVertices, noTriangles, 0, 0, VertexPositionTexture.VertexDeclaration, VertexPositionTexture.VertexDeclaration.VertexStride, BatchType.INDEXED); b[0].VertexBuffer = vertexBufferS; b[0].IndexBuffer = indexBufferS; BatchInformations[0] = b; TextureInformation = new TextureInformation[1][]; TextureInformation[0] = new TextureInformation[1]; TextureInformation[0][0] = new TextureInformation(false, factory); TextureInformation[0][0].SetTexture(diffuseName, TextureType.DIFFUSE); }
/// <summary> /// Loads the model. /// </summary> /// <param name="factory">The factory.</param> /// <param name="BatchInformations">The batch informations.</param> /// <param name="TextureInformations">The texture informations.</param> protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformations) { int vertCount = bilboards.Count() * 4; int indexCount = bilboards.Count() * 6; int noVertices = vertCount; int noTriangles = indexCount / 3; VertexBuffer vertexBufferS = factory.CreateDynamicVertexBuffer(VertexPositionTexture.VertexDeclaration, vertCount, BufferUsage.WriteOnly); IndexBuffer IndexBufferS = factory.CreateDynamicIndexBuffer(IndexElementSize.SixteenBits, indexCount, BufferUsage.WriteOnly); BatchInformations = new BatchInformation[1][]; BatchInformation[] b = new BatchInformation[1]; b[0] = new BatchInformation(0, vertCount, noTriangles, 0, 0, VertexPositionTexture.VertexDeclaration, VertexPositionTexture.VertexDeclaration.VertexStride, BatchType.INDEXED); b[0].ModelLocalTransformation = Matrix.Identity; b[0].VertexBuffer = vertexBufferS; b[0].IndexBuffer = IndexBufferS; BatchInformations[0] = b; TextureInformations = new TextureInformation[1][]; TextureInformations[0] = new TextureInformation[1]; TextureInformations[0][0] = new TextureInformation(isInternal, factory, diffuseTextureName, null, null, null); TextureInformations[0][0].LoadTexture(); }
/// <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); }
/// <summary> /// Loads the model. /// </summary> /// <param name="factory">The factory.</param> /// <param name="BatchInformations">The batch informations.</param> /// <param name="TextureInformations">The texture informations.</param> protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformations) { VertexPositionTexture[] billboardVertices = new VertexPositionTexture[4]; int i = 0; billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(0, 0)); billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(1, 0)); billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(0, 1)); billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(1, 1)); VertexElement v0 = new VertexElement(0,VertexElementFormat.Vector3,VertexElementUsage.TextureCoordinate,1); VertexElement v1 = new VertexElement(sizeof(float) * 3,VertexElementFormat.Vector2,VertexElementUsage.TextureCoordinate,2); vd = new VertexDeclaration(v0, v1); VertexBuffer InstancedvertexBufferS; if (dynamicBufferSize != -1) { InstancedvertexBufferS = factory.CreateDynamicVertexBuffer(vd, dynamicBufferSize, BufferUsage.WriteOnly); } else { InstancedvertexBufferS = factory.CreateDynamicVertexBuffer(vd, instances.Count(), BufferUsage.WriteOnly); } InstancedvertexBufferS.SetData(instances); VertexBuffer vertexBufferS = factory.CreateVertexBuffer(VertexPositionTexture.VertexDeclaration, billboardVertices.Count(), BufferUsage.WriteOnly); vertexBufferS.SetData(billboardVertices); short[] indices = new short[] { 0,2,1,1,2,3}; IndexBuffer indexBufferS = factory.CreateIndexBuffer(IndexElementSize.SixteenBits, 6, BufferUsage.WriteOnly); indexBufferS.SetData<short>(indices); BatchInformations = new BatchInformation[1][]; BatchInformation[] b = new BatchInformation[1]; b[0] = new BatchInformation(0, 4, 2, 0, 0, VertexPositionTexture.VertexDeclaration, VertexPositionTexture.VertexDeclaration.VertexStride,instances.Count()); b[0].VertexBuffer = vertexBufferS; b[0].IndexBuffer = indexBufferS; b[0].InstancedVertexBuffer = InstancedvertexBufferS; BatchInformations[0] = b; TextureInformations = new TextureInformation[1][]; TextureInformations[0] = new TextureInformation[1]; TextureInformations[0][0] = new TextureInformation(isInternal, factory, diffuseTextureName, null, null, null); TextureInformations[0][0].LoadTexture(); }
/// <summary> /// Loads the model. /// </summary> /// <param name="factory">The factory.</param> /// <param name="BatchInformations">The batch informations.</param> /// <param name="TextureInformations">The texture informations.</param> protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformations) { int vertCount = bilboards.Count() * 4; int indexCount = bilboards.Count() * 6; int noVertices = vertCount; int noTriangles = indexCount / 3; VertexBuffer vertexBufferS = factory.CreateDynamicVertexBuffer(VertexPositionTexture.VertexDeclaration, vertCount, BufferUsage.WriteOnly); IndexBuffer IndexBufferS = factory.CreateDynamicIndexBuffer(IndexElementSize.SixteenBits, indexCount, BufferUsage.WriteOnly); BatchInformations = new BatchInformation[1][]; BatchInformation[] b = new BatchInformation[1]; b[0] = new BatchInformation(0, vertCount, noTriangles, 0, 0, VertexPositionTexture.VertexDeclaration, VertexPositionTexture.VertexDeclaration.VertexStride, BatchType.INDEXED); b[0].ModelLocalTransformation = Matrix.Identity; b[0].VertexBuffer = vertexBufferS; b[0].IndexBuffer = IndexBufferS; BatchInformations[0] = b; TextureInformations = new TextureInformation[1][]; TextureInformations[0] = new TextureInformation[1]; TextureInformations[0][0] = new TextureInformation(isInternal, factory, diffuseTextureName, null, null, null); TextureInformations[0][0].LoadTexture(); }
protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformation) { int vertCount = vertices.Count(); int indexCount = 0; if (indices != null) { indexCount = indices.Count(); } int noVertices = vertCount; int noTriangles = 0; if (indices != null) { noTriangles = indexCount / 3; } else { noTriangles = vertCount / 3; } VertexBuffer vertexBufferS; IndexBuffer IndexBufferS = null; if (isDynamic) { vertexBufferS = factory.CreateDynamicVertexBuffer(vertices[0].VertexDeclaration, (int)(vertCount * dynamicMultiplier), BufferUsage); if (indices != null) { IndexBufferS = factory.CreateDynamicIndexBuffer(IndexElementSize.ThirtyTwoBits, (int)(indexCount * dynamicMultiplier), BufferUsage); } } else { vertexBufferS = factory.CreateVertexBuffer(vertices[0].VertexDeclaration, vertCount, BufferUsage); if (indices != null) { IndexBufferS = factory.CreateIndexBuffer(IndexElementSize.ThirtyTwoBits, indexCount, BufferUsage); } } vertexBufferS.SetData <T>(vertices); if (indices != null) { IndexBufferS.SetData <int>(indices); } BatchInformations = new BatchInformation[1][]; BatchInformation[] b = new BatchInformation[1]; b[0] = new BatchInformation(0, vertCount, noTriangles, 0, 0, vertices[0].VertexDeclaration, vertices[0].VertexDeclaration.VertexStride, indices != null ? BatchType.INDEXED : BatchType.NORMAL); b[0].ModelLocalTransformation = transformation; b[0].VertexBuffer = vertexBufferS; if (indices != null) { b[0].IndexBuffer = IndexBufferS; } BatchInformations[0] = b; TextureInformations = new TextureInformation[1][]; TextureInformations[0] = new TextureInformation[1]; TextureInformations[0][0] = new TextureInformation(isInternal, factory, diffuseTextureName, null, null, null); TextureInformations[0][0].LoadTexture(); TextureInformation = TextureInformations; if (!isDynamic) { vertices = null; indices = null; } }