/// <summary> /// Initializes a new instance of the <see cref="CustomModel"/> class. /// </summary> /// <param name="factory">The factory.</param> /// <param name="loader">The loader.</param> public CustomModel(GraphicFactory factory, ObjectInformation[] loader) : base(factory, loader[0].modelName, false) { System.Diagnostics.Debug.Assert(loader != null); System.Diagnostics.Debug.Assert(loader.Count() != 0); BatchInformations = new BatchInformation[1][]; BatchInformations[0] = new BatchInformation[loader.Count()]; TextureInformations = new TextureInformation[1][]; TextureInformations[0] = new TextureInformation[loader.Count()]; BoundingSphere bs = new BoundingSphere(); for (int i = 0; i < loader.Count(); i++) { BatchInformations[0][i] = loader[i].batchInformation; TextureInformations[0][i] = loader[i].textureInformation; float radius; Vector3 center; ModelBuilderHelper.ExtractModelRadiusAndCenter(BatchInformations[0][i], out radius, out center); bs = BoundingSphere.CreateMerged(bs, new BoundingSphere(center, radius)); } modelRadius = bs.Radius; }
protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformations) { VertexPositionTexture[] billboardVertices = new VertexPositionTexture[positions.Count * 6]; int i = 0; foreach (var position in positions) { billboardVertices[i++] = new VertexPositionTexture(position, new Vector2(0, 0)); billboardVertices[i++] = new VertexPositionTexture(position, new Vector2(1, 0)); billboardVertices[i++] = new VertexPositionTexture(position, new Vector2(1, 1)); billboardVertices[i++] = new VertexPositionTexture(position, new Vector2(0, 0)); billboardVertices[i++] = new VertexPositionTexture(position, new Vector2(1, 1)); billboardVertices[i++] = new VertexPositionTexture(position, new Vector2(0, 1)); } VertexBuffer vertexBufferS = factory.CreateVertexBuffer(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(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 void BuildModel() { added = true; int vertCount = vertices.Count(); int indexCount = 0; if (useIndices) { indexCount = indices.Count(); } int noVertices = vertCount; int noTriangles = 0; if (useIndices) { noTriangles = indexCount / 3; } else { noTriangles = vertCount / 3; } VertexBuffer vertexBufferS; IndexBuffer IndexBufferS = null; vertexBufferS = factory.CreateVertexBuffer(vertices[0].VertexDeclaration, vertCount, BufferUsage); vertexBufferS.SetData <T>(vertices.ToArray()); if (useIndices) { IndexBufferS = factory.CreateIndexBuffer(IndexElementSize.ThirtyTwoBits, indexCount, BufferUsage); IndexBufferS.SetData <int>(indices.ToArray()); } 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, useIndices == true ? BatchType.INDEXED : BatchType.NORMAL); b[0].ModelLocalTransformation = transformation; b[0].VertexBuffer = vertexBufferS; if (useIndices) { 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(); TextureInformations = TextureInformations; vertices = null; indices = null; }
protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformation) { BatchInformations = new BatchInformation[1][]; BatchInformations[0] = new BatchInformation[1]; BatchInformations[0][0] = BatchInformation; TextureInformation = new TextureInformation[1][]; TextureInformation[0] = new TextureInformation[1]; TextureInformation[0][0] = new TextureInformation(false, factory, _diffuseName); TextureInformation[0][0].LoadTexture(); }
protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformations) { List <VertexPositionNormalTexture> vertexList = new List <VertexPositionNormalTexture>(); #if WINDOWS_PHONE || REACH ////gambi shortcut List <int> indexList2 = new List <int>(); GetVertexData(vertexList, indexList2, terrainObject); List <short> indexList = new List <short>(); foreach (var item in indexList2) { indexList.Add((short)item); } indexList2.Clear(); #else List <int> indexList = new List <int>(); GetVertexData(vertexList, indexList, terrainObject); #endif modelRadius = (terrainObject.BoundingBox.Value.Max - terrainObject.BoundingBox.Value.Max).Length() / 2; var newVertices = new VertexPositionNormalTexture[vertexList.Count]; vertexList.CopyTo(newVertices); #if WINDOWS_PHONE || REACH var newIndices = new short[indexList.Count]; #else var newIndices = new int[indexList.Count]; #endif indexList.CopyTo(newIndices); VertexBuffer vertexBufferS = factory.CreateVertexBuffer(VertexPositionNormalTexture.VertexDeclaration, newVertices.Count(), BufferUsage.WriteOnly); vertexBufferS.SetData(newVertices); #if WINDOWS_PHONE || REACH IndexBuffer indexBufferS = factory.CreateIndexBuffer(IndexElementSize.SixteenBits, newIndices.Count(), BufferUsage.WriteOnly); #else IndexBuffer indexBufferS = factory.CreateIndexBuffer(IndexElementSize.ThirtyTwoBits, newIndices.Count(), BufferUsage.WriteOnly); #endif indexBufferS.SetData(newIndices); BatchInformations = new BatchInformation[1][]; BatchInformation[] b = new BatchInformation[1]; b[0] = new BatchInformation(0, newVertices.Count(), newIndices.Count() / 3, 0, 0, VertexPositionNormalTexture.VertexDeclaration, VertexPositionNormalTexture.VertexDeclaration.VertexStride); b[0].VertexBuffer = vertexBufferS; b[0].IndexBuffer = indexBufferS; b[0].ModelLocalTransformation = Matrix.Identity; BatchInformations[0] = b; TextureInformations = new TextureInformation[1][]; TextureInformations[0] = new TextureInformation[1]; TextureInformations[0][0] = new TextureInformation(isInternal, factory, null, 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) { 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> /// Initializes a new instance of the <see cref="CustomModel"/> class. /// </summary> /// <param name="factory">The factory.</param> /// <param name="modelName">Name of the model.</param> /// <param name="meshindex">The meshindex.</param> /// <param name="binfo">The binfo.</param> /// <param name="diffuse">The diffuse.</param> public CustomModel(GraphicFactory factory, String modelName, int meshindex, BatchInformation[] binfo, Texture2D diffuse = null) : base(factory, modelName, false) { System.Diagnostics.Debug.Assert(binfo != null); System.Diagnostics.Debug.Assert(binfo.Count() != 0); BatchInformations = new BatchInformation[1][]; BatchInformations[0] = binfo; BoundingSphere bs = new BoundingSphere(); for (int i = 0; i < binfo.Count(); i++) { float radius; Vector3 center; ModelBuilderHelper.ExtractModelRadiusAndCenter(binfo[i], out radius, out center); bs = BoundingSphere.CreateMerged(bs, new BoundingSphere(center, radius)); } modelRadius = bs.Radius; TextureInformations = new TextureInformation[1][]; TextureInformations[0] = new TextureInformation[binfo.Count()]; for (int j = 0; j < TextureInformations[0].Count(); j++) { TextureInformations[0][j] = new TextureInformation(isInternal, factory); TextureInformations[0][j].LoadTexture(); if (diffuse == null) { if (model != null) { BasicEffect effect = model.Meshes[meshindex].MeshParts[j].Effect as BasicEffect; if (effect != null) { TextureInformations[0][j].SetTexture(effect.Texture, TextureType.DIFFUSE); } } } else { SetTexture(diffuse, TextureType.DIFFUSE, meshindex, j); } } }
/// <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) { //code not called !!! //Here for future usage. model = factory.GetModel(this.Name, isInternal); ModelBuilderHelper.Extract(model, out BatchInformations); BoundingSphere sphere = new BoundingSphere(); foreach (var item in model.Meshes) { BoundingSphere.CreateMerged(sphere, item.BoundingSphere); } modelRadius = sphere.Radius; TextureInformations = new TextureInformation[1][]; TextureInformations[0] = new TextureInformation[1]; TextureInformations[0][0] = new TextureInformation(isInternal, factory); 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) { TreeProfile t = factory.GetAsset <TreeProfile>(profileName); if (!String.IsNullOrEmpty(LeaftextureName)) { t.LeafTexture = factory.GetAsset <Texture2D>(LeaftextureName); } if (!String.IsNullOrEmpty(trunktextureName)) { t.TrunkTexture = factory.GetAsset <Texture2D>(trunktextureName); } tree = t.GenerateSimpleTree(StaticRandom.RandomInstance); BatchInformations = new BatchInformation[2][]; vertexBufferS = new VertexBuffer[2]; indexBufferS = new IndexBuffer[2]; indexBufferS[0] = tree.TrunkMesh.IndexBuffer; vertexBufferS[0] = tree.TrunkMesh.VertexBuffer; BatchInformation bi0 = new BatchInformation(0, tree.TrunkMesh.NumberOfVertices, tree.TrunkMesh.NumberOfTriangles, 0, 0, tree.TrunkMesh.Vdeclaration, TreeVertex.SizeInBytes); BatchInformations[0] = new BatchInformation[1]; BatchInformations[0][0] = bi0; indexBufferS[1] = tree.LeafCloud.Ibuffer; vertexBufferS[1] = tree.LeafCloud.Vbuffer; BatchInformation bi1 = new BatchInformation(0, tree.LeafCloud.Numleaves * 4, tree.LeafCloud.Numleaves * 2, 0, 0, tree.LeafCloud.Vdeclaration, LeafVertex.SizeInBytes); BatchInformations[1] = new BatchInformation[1]; BatchInformations[1][0] = bi1; TextureInformations = new TextureInformation[1][]; TextureInformations[0] = new TextureInformation[2]; TextureInformations[0][0] = new TextureInformation(isInternal, factory, null, null, null, null); TextureInformations[0][1] = new TextureInformation(isInternal, factory, null, null, null, null); TextureInformations[0][0].LoadTexture(); TextureInformations[0][1].LoadTexture(); TextureInformations[0][0].SetTexture(tree.TrunkTexture, TextureType.DIFFUSE); TextureInformations[0][1].SetTexture(tree.LeafTexture, TextureType.DIFFUSE); }
public static void Extract(GraphicFactory factory, out BatchInformation[][] batchInformationS, out TextureInformation[][] textureInformationS, Model model, String diffuseName = null, String bumpName = null, string specularName = null, String glowName = null, bool isinternal = false) { batchInformationS = new BatchInformation[model.Meshes.Count][]; textureInformationS = new TextureInformation[model.Meshes.Count][]; Matrix[] boneabsolute = new Matrix[model.Bones.Count]; model.CopyAbsoluteBoneTransformsTo(boneabsolute); for (int j = 0; j < model.Meshes.Count; j++) { ModelMesh mesh = model.Meshes[j]; BatchInformation[] b = new BatchInformation[mesh.MeshParts.Count]; TextureInformation[] t = new TextureInformation[mesh.MeshParts.Count]; for (int i = 0; i < mesh.MeshParts.Count; i++) { b[i] = new BatchInformation(mesh.MeshParts[i].VertexOffset, mesh.MeshParts[i].NumVertices, mesh.MeshParts[i].PrimitiveCount, mesh.MeshParts[i].StartIndex, mesh.MeshParts[i].VertexOffset, mesh.MeshParts[i].VertexBuffer.VertexDeclaration, mesh.MeshParts[i].VertexBuffer.VertexDeclaration.VertexStride); b[i].IndexBuffer = mesh.MeshParts[i].IndexBuffer; b[i].VertexBuffer = mesh.MeshParts[i].VertexBuffer; b[i].ModelLocalTransformation = boneabsolute[mesh.ParentBone.Index]; t[i] = new TextureInformation(isinternal, factory, diffuseName, bumpName, specularName, glowName); t[i].LoadTexture(); if (diffuseName == null) { BasicEffect BasicEffect = mesh.MeshParts[i].Effect as BasicEffect; if (BasicEffect != null) { t[i].SetTexture(BasicEffect.Texture, TextureType.DIFFUSE); } else if (mesh.MeshParts[i].Effect is SkinnedEffect) { t[i].SetTexture((mesh.MeshParts[i].Effect as SkinnedEffect).Texture, TextureType.DIFFUSE); } } } batchInformationS[j] = b; textureInformationS[j] = t; } }
/// <summary> /// Initializes a new instance of the <see cref="CustomModel"/> class. /// </summary> /// <param name="factory">The factory.</param> /// <param name="modelName">Name of the model.</param> /// <param name="BatchInformation">The batch information.</param> /// <param name="TextureInformation">The texture information.</param> /// <param name="meshindex">The meshindex.</param> /// <param name="meshpartIndex">Index of the meshpart.</param> public CustomModel(GraphicFactory factory, String modelName, BatchInformation BatchInformation, TextureInformation TextureInformation, int meshindex = 0, int meshpartIndex = 0) : base(factory, modelName, false) { System.Diagnostics.Debug.Assert(BatchInformation != null); System.Diagnostics.Debug.Assert(TextureInformation != null); BatchInformations = new BatchInformation[1][]; BatchInformations[0] = new BatchInformation[1]; BatchInformations[0][0] = BatchInformation; BoundingSphere bs = new BoundingSphere(); { float radius; Vector3 center; ModelBuilderHelper.ExtractModelRadiusAndCenter(BatchInformation, out radius, out center); bs = BoundingSphere.CreateMerged(bs, new BoundingSphere(center, radius)); } modelRadius = bs.Radius; TextureInformations = new TextureInformation[1][]; TextureInformations[0] = new TextureInformation[1]; TextureInformations[0][0] = TextureInformation; if (TextureInformation.getTexture(TextureType.DIFFUSE) == null) { if (model != null) { BasicEffect effect = model.Meshes[meshindex].MeshParts[meshpartIndex].Effect as BasicEffect; if (effect != null) { TextureInformations[0][0].SetTexture(effect.Texture, 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(); }
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; } }
/// <summary> /// Get texture cube /// (Only Environment and AmbientCubeMap) /// </summary> /// <param name="TextureType"></param> /// <param name="meshIndex"></param> /// <param name="meshPartIndex"></param> /// <returns></returns> public TextureCube GetCubeTexture(TextureType TextureType = TextureType.ENVIRONMENT, int meshIndex = 0, int meshPartIndex = 0) { TextureInformation ti = TextureInformations[meshIndex][meshPartIndex]; return(ti.getCubeTexture(TextureType)); }
/// <summary> /// Set Cube Texture of a mesh /// </summary> /// <param name="textureCube"></param> /// <param name="meshIndex"></param> /// <param name="meshPartIndex"></param> public void SetCubeTexture(TextureCube textureCube, TextureType TextureType = TextureType.ENVIRONMENT, int meshIndex = 0, int meshPartIndex = 0) { TextureInformation ti = TextureInformations[meshIndex][meshPartIndex]; ti.SetCubeTexture(textureCube, TextureType); }
/// <summary> /// Sets the texture. /// </summary> /// <param name="textureName">Name of the texture.</param> /// <param name="type">The type.</param> /// <param name="meshIndex">Index of the mesh.</param> /// <param name="meshPartIndex">Index of the mesh part.</param> public void SetTexture(String textureName, TextureType type = TextureType.DIFFUSE, int meshIndex = 0, int meshPartIndex = 0) { TextureInformation ti = TextureInformations[meshIndex][meshPartIndex]; ti.SetTexture(textureName, type); }
protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformations) { Vector3 myPosition = new Vector3(basePosition.X - (myWidth / 2), basePosition.Y, basePosition.Z - (myHeight / 2)); Vector3[] pos = new Vector3[myWidth * myHeight]; // Vertices VertexMultitextured[] myVertices = new VertexMultitextured[myWidth * myHeight]; for (int x = 0; x < myWidth; x++) { for (int y = 0; y < myHeight; y++) { myVertices[x + y * myWidth].Position = new Vector3(y, 0, x); pos[x + y * myWidth] = new Vector3(y, 0, x); myVertices[x + y * myWidth].Normal = new Vector3(0, -1, 0); myVertices[x + y * myWidth].TextureCoordinate.X = (float)x / 30.0f; myVertices[x + y * myWidth].TextureCoordinate.Y = (float)y / 30.0f; } } modelRadius = BoundingSphere.CreateFromPoints(pos).Radius; // Calc Tangent and Bi Normals. for (int x = 0; x < myWidth; x++) { for (int y = 0; y < myHeight; y++) { // Tangent Data. if (x != 0 && x < myWidth - 1) { myVertices[x + y * myWidth].Tangent = myVertices[x - 1 + y * myWidth].Position - myVertices[x + 1 + y * myWidth].Position; } else if (x == 0) { myVertices[x + y * myWidth].Tangent = myVertices[x + y * myWidth].Position - myVertices[x + 1 + y * myWidth].Position; } else { myVertices[x + y * myWidth].Tangent = myVertices[x - 1 + y * myWidth].Position - myVertices[x + y * myWidth].Position; } // Bi Normal Data. if (y != 0 && y < myHeight - 1) { myVertices[x + y * myWidth].BiNormal = myVertices[x + (y - 1) * myWidth].Position - myVertices[x + (y + 1) * myWidth].Position; } else if (y == 0) { myVertices[x + y * myWidth].BiNormal = myVertices[x + y * myWidth].Position - myVertices[x + (y + 1) * myWidth].Position; } else { myVertices[x + y * myWidth].BiNormal = myVertices[x + (y - 1) * myWidth].Position - myVertices[x + y * myWidth].Position; } } } VertexDeclaration vd = new VertexDeclaration(VertexMultitextured.SizeInBytes, VertexMultitextured.VertexElements); VertexBuffer vb = factory.CreateVertexBuffer(vd, myWidth * myHeight, BufferUsage.WriteOnly); vb.SetData(myVertices); short[] terrainIndices = new short[(myWidth - 1) * (myHeight - 1) * 6]; for (short x = 0; x < myWidth - 1; x++) { for (short y = 0; y < myHeight - 1; y++) { terrainIndices[(x + y * (myWidth - 1)) * 6] = (short)((x + 1) + (y + 1) * myWidth); terrainIndices[(x + y * (myWidth - 1)) * 6 + 1] = (short)((x + 1) + y * myWidth); terrainIndices[(x + y * (myWidth - 1)) * 6 + 2] = (short)(x + y * myWidth); terrainIndices[(x + y * (myWidth - 1)) * 6 + 3] = (short)((x + 1) + (y + 1) * myWidth); terrainIndices[(x + y * (myWidth - 1)) * 6 + 4] = (short)(x + y * myWidth); terrainIndices[(x + y * (myWidth - 1)) * 6 + 5] = (short)(x + (y + 1) * myWidth); } } IndexBuffer ib = factory.CreateIndexBuffer(IndexElementSize.SixteenBits, (myWidth - 1) * (myHeight - 1) * 6, BufferUsage.WriteOnly); ib.SetData(terrainIndices); BatchInformations = new BatchInformation[1][]; BatchInformation[] b = new BatchInformation[1]; b[0] = new BatchInformation(0, myVertices.Count(), terrainIndices.Count() / 3, 0, 0, vd, VertexMultitextured.SizeInBytes); b[0].VertexBuffer = vb; b[0].IndexBuffer = ib; BatchInformations[0] = b; TextureInformations = new TextureInformation[1][]; TextureInformations[0] = new TextureInformation[1]; TextureInformations[0][0] = new TextureInformation(isInternal, factory, null, null, null, null); TextureInformations[0][0].LoadTexture(); }