private void ParseTriangles( XElement mesh, MeshSkinAndMaterials skinAndMaterials, SeparateStreamsMesh dstMesh, XElement element) { var meshInputs = this.ParseInputs(element); int[] p = new int[meshInputs.Count * meshInputs.Stride * 3]; this.ParseIntArray(element.ElementValue(this.schema.pName), p); var subMesh = dstMesh.CreateSubmesh(); subMesh.Material = skinAndMaterials.GetAnyMaterialFor(element.AttributeValue(this.schema.materialAttributeName)); subMesh.VertexSourceType = VertexSourceType.TriangleList; var streamList = StreamListOrderedByOffset(meshInputs, subMesh); for (int polygonIndex = 0; polygonIndex < meshInputs.Count; ++polygonIndex) { AddVertex(p, polygonIndex*3, streamList, meshInputs.Stride); AddVertex(p, polygonIndex * 3+1, streamList, meshInputs.Stride); AddVertex(p, polygonIndex * 3+2, streamList, meshInputs.Stride); } }
private void ParsePolylist( XElement mesh, MeshSkinAndMaterials skinAndMaterials, SeparateStreamsMesh dstMesh, XElement element) { var meshInputs = this.ParseInputs(element); int[] vcount = new int[meshInputs.Count]; this.ParseIntArray(element.ElementValue(this.schema.vcountName), vcount); var points = vcount.Sum(a => a); var firstSize = vcount[0]; bool isAllTheSame = vcount.All(i => i == firstSize); int[] p = new int[points * meshInputs.Stride]; this.ParseIntArray(element.ElementValue(this.schema.pName), p); var subMesh = dstMesh.CreateSubmesh(); subMesh.Material = skinAndMaterials.GetAnyMaterialFor(element.AttributeValue(this.schema.materialAttributeName)); var streamList = StreamListOrderedByOffset(meshInputs, subMesh); //if (isAllTheSame) //{ // if (firstSize == 3) // { // subMesh.VertexSourceType = VertexSourceType.TrianleList; // this.ParseElements(p, subMesh, meshInputs, points); // return; // } // if (firstSize == 4) // { // subMesh.VertexSourceType = VertexSourceType.QuadList; // this.ParseElements(p, subMesh, meshInputs, points); // return; // } //} subMesh.VertexSourceType = VertexSourceType.TriangleList; int startIndex = 0; for (int polygonIndex = 0; polygonIndex < vcount.Length; ++polygonIndex) { for (int i = 2; i < vcount[polygonIndex]; i++) { AddVertex(p, 0, streamList, meshInputs.Stride); AddVertex(p, i-1, streamList, meshInputs.Stride); AddVertex(p, i , streamList, meshInputs.Stride); } startIndex += vcount[polygonIndex]; } }
private void ParsePolygons( MeshSkinAndMaterials skinAndMaterials, SeparateStreamsMesh dstMesh, XElement element) { var meshInputs = this.ParseInputs(element); var subMesh = dstMesh.CreateSubmesh(); subMesh.Material = skinAndMaterials.GetAnyMaterialFor(element.AttributeValue(this.schema.materialAttributeName)); subMesh.VertexSourceType = VertexSourceType.TriangleList; var streamList = StreamListOrderedByOffset(meshInputs, subMesh); foreach (var polygon in element.Elements(this.schema.pName)) { var list = this.ParseIntList(polygon.Value); int numElements = list.Count / meshInputs.Stride; for (int i=1; i<numElements-1; ++i) { AddVertex(list, 0, streamList, meshInputs.Stride); AddVertex(list, i, streamList, meshInputs.Stride); AddVertex(list, i+1, streamList, meshInputs.Stride); } } }
public static IMesh BuildSoftEdgedBox(float x, float y, float z, IStreamConverterFactory converterFactory) { Float3[] p = new[] { new Float3(-x / 2.0f, -y / 2.0f, z / 2.0f), new Float3(x / 2.0f, -y / 2.0f, z / 2.0f), new Float3(-x / 2.0f, y / 2.0f, z / 2.0f), new Float3(x / 2.0f, y / 2.0f, z / 2.0f), new Float3(-x / 2.0f, y / 2.0f, -z / 2.0f), new Float3(x / 2.0f, y / 2.0f, -z / 2.0f), new Float3(-x / 2.0f, -y / 2.0f, -z / 2.0f), new Float3(x / 2.0f, -y / 2.0f, -z / 2.0f), }; Float3[] n = new[] { new Float3(-0.57735f, -0.57735f, -0.57735f), new Float3(-0.57735f, 0.57735f, -0.57735f), new Float3(0.57735f, -0.57735f, -0.57735f), new Float3(0.57735f, 0.57735f, -0.57735f), new Float3(-0.57735f, -0.57735f, 0.57735f), new Float3(-0.57735f, 0.57735f, 0.57735f), new Float3(0.57735f, -0.57735f, 0.57735f), new Float3(0.57735f, 0.57735f, 0.57735f), }; Float3[] uv = new[] { new Float3(0.0f, 0.0f, 0.0f), new Float3(1.0f, 0.0f, 0.0f), new Float3(1.0f, 1.0f, 0.0f), new Float3(0.0f, 1.0f, 0.0f), }; var res = new SeparateStreamsMesh(); res.SetStream(Streams.Position, 0, new ArrayMeshStream<Float3>(p, converterFactory)); res.SetStream(Streams.Normal, 0, new ArrayMeshStream<Float3>(n, converterFactory)); res.SetStream(Streams.TexCoord, 0, new ArrayMeshStream<Float3>(uv, converterFactory)); res.SetStream(Streams.TexCoord, 1, new ArrayMeshStream<Float3>(uv, converterFactory)); res.SetStream(Streams.Color, 0, new ArrayMeshStream<Color>(new Color[] { Color.FromArgb(255, 255, 255, 255) }, converterFactory)); var t2 = Float3.Normalize(p[7] - p[6]); var b2 = Float3.Cross(Float3.Normalize(n[0] + n[2] + n[3] + n[1]), t2); var t3 = Float3.Normalize(p[1] - p[0]); var b3 = Float3.Cross(Float3.Normalize(n[4] + n[6] + n[2] + n[0]), t3); var t4 = Float3.Normalize(p[5] - p[3]); var b4 = Float3.Cross(Float3.Normalize(n[7] + n[3] + n[2] + n[6]), t4); var t5 = Float3.Normalize(p[2] - p[4]); var b5 = Float3.Cross(Float3.Normalize(n[1] + n[5] + n[4] + n[0]), t5); res.SetStream(Streams.Tangent, 0, new ArrayMeshStream<Float3>(new Float3[] { new Float3(1, 0, 0), new Float3(1, 0, 0), t2, t3, t4, t5 }, converterFactory)); res.SetStream(Streams.Binormal, 0, new ArrayMeshStream<Float3>(new Float3[] { new Float3(0, 1, 0), new Float3(0, 0, -1), b2, b3, b4, b5 }, converterFactory)); var s = res.CreateSubmesh(); s.VertexSourceType = VertexSourceType.QuadList; var positionIndices = s.SetIndexStream(Streams.Position, 0, new ListMeshStream<int>(24, converterFactory)); var normalIndices = s.SetIndexStream(Streams.Normal, 0, new ListMeshStream<int>(24, converterFactory)); var uv0Indices = s.SetIndexStream(Streams.TexCoord, 0, new ListMeshStream<int>(24, converterFactory)); var uv1Indices = s.SetIndexStream(Streams.TexCoord, 1, new ListMeshStream<int>(24, converterFactory)); var colorIndices = s.SetIndexStream(Streams.Color, 0, new ListMeshStream<int>(24, converterFactory)); var tangentIndices = s.SetIndexStream(Streams.Tangent, 0, new ListMeshStream<int>(24, converterFactory)); var binormalIndices = s.SetIndexStream(Streams.Binormal, 0, new ListMeshStream<int>(24, converterFactory)); Vertex vertex; Float3 t; Float3 b; // Quad 0 TOP //t = new Float3(1, 0, 0); //b = new Float3(0, 1, 0); //Float3.Cross(new Float3(0,0,1),t) positionIndices.Add(0); normalIndices.Add(4); colorIndices.Add(0); uv0Indices.Add(3); uv1Indices.Add(3); tangentIndices.Add(0); binormalIndices.Add(0); positionIndices.Add(1); normalIndices.Add(6); colorIndices.Add(0); uv0Indices.Add(2); uv1Indices.Add(2); tangentIndices.Add(0); binormalIndices.Add(0); positionIndices.Add(3); normalIndices.Add(7); colorIndices.Add(0); uv0Indices.Add(1); uv1Indices.Add(1); tangentIndices.Add(0); binormalIndices.Add(0); positionIndices.Add(2); normalIndices.Add(5); colorIndices.Add(0); uv0Indices.Add(0); uv1Indices.Add(0); tangentIndices.Add(0); binormalIndices.Add(0); //vertex = new Vertex // { Position = p[0], Color = color, Normal = n[4], UV0 = uv[3], UV1 = uv[3], Tangent = t, Binormal = b }; //s.Add(ref vertex); //vertex = new Vertex // { Position = p[1], Color = color, Normal = n[6], UV0 = uv[2], UV1 = uv[2], Tangent = t, Binormal = b }; //s.Add(ref vertex); //vertex = new Vertex // { Position = p[3], Color = color, Normal = n[7], UV0 = uv[1], UV1 = uv[1], Tangent = t, Binormal = b }; //s.Add(ref vertex); //vertex = new Vertex // { Position = p[2], Color = color, Normal = n[5], UV0 = uv[0], UV1 = uv[0], Tangent = t, Binormal = b }; //s.Add(ref vertex); positionIndices.Add(2); normalIndices.Add(5); colorIndices.Add(0); uv0Indices.Add(3); uv1Indices.Add(3); tangentIndices.Add(1); binormalIndices.Add(1); positionIndices.Add(3); normalIndices.Add(7); colorIndices.Add(0); uv0Indices.Add(2); uv1Indices.Add(2); tangentIndices.Add(1); binormalIndices.Add(1); positionIndices.Add(5); normalIndices.Add(3); colorIndices.Add(0); uv0Indices.Add(1); uv1Indices.Add(1); tangentIndices.Add(1); binormalIndices.Add(1); positionIndices.Add(4); normalIndices.Add(1); colorIndices.Add(0); uv0Indices.Add(0); uv1Indices.Add(0); tangentIndices.Add(1); binormalIndices.Add(1); //// Quad 1 //t = new Float3(1, 0, 0); //b = new Float3(0, 0, -1); //vertex = new Vertex // { Position = p[2], Color = color, Normal = n[5], UV0 = uv[3], UV1 = uv[3], Tangent = t, Binormal = b }; //s.Add(ref vertex); //vertex = new Vertex // { Position = p[3], Color = color, Normal = n[7], UV0 = uv[2], UV1 = uv[2], Tangent = t, Binormal = b }; //s.Add(ref vertex); //vertex = new Vertex // { Position = p[5], Color = color, Normal = n[3], UV0 = uv[1], UV1 = uv[1], Tangent = t, Binormal = b }; //s.Add(ref vertex); //vertex = new Vertex // { Position = p[4], Color = color, Normal = n[1], UV0 = uv[0], UV1 = uv[0], Tangent = t, Binormal = b }; //s.Add(ref vertex); positionIndices.Add(4); normalIndices.Add(1); colorIndices.Add(0); uv0Indices.Add(3); uv1Indices.Add(3); tangentIndices.Add(2); binormalIndices.Add(2); positionIndices.Add(5); normalIndices.Add(3); colorIndices.Add(0); uv0Indices.Add(2); uv1Indices.Add(2); tangentIndices.Add(2); binormalIndices.Add(2); positionIndices.Add(7); normalIndices.Add(2); colorIndices.Add(0); uv0Indices.Add(1); uv1Indices.Add(1); tangentIndices.Add(2); binormalIndices.Add(2); positionIndices.Add(6); normalIndices.Add(0); colorIndices.Add(0); uv0Indices.Add(0); uv1Indices.Add(0); tangentIndices.Add(2); binormalIndices.Add(2); //// Quad 2 //t = Float3.Normalize(p[7] - p[6]); //b = Float3.Cross(Float3.Normalize(n[0] + n[2] + n[3] + n[1]), t); //vertex = new Vertex // { Position = p[4], Color = color, Normal = n[1], UV0 = uv[3], UV1 = uv[3], Tangent = t, Binormal = b }; //s.Add(ref vertex); //vertex = new Vertex // { Position = p[5], Color = color, Normal = n[3], UV0 = uv[2], UV1 = uv[2], Tangent = t, Binormal = b }; //s.Add(ref vertex); //vertex = new Vertex // { Position = p[7], Color = color, Normal = n[2], UV0 = uv[1], UV1 = uv[1], Tangent = t, Binormal = b }; //s.Add(ref vertex); //vertex = new Vertex // { Position = p[6], Color = color, Normal = n[0], UV0 = uv[0], UV1 = uv[0], Tangent = t, Binormal = b }; //s.Add(ref vertex); positionIndices.Add(6); normalIndices.Add(0); colorIndices.Add(0); uv0Indices.Add(3); uv1Indices.Add(3); tangentIndices.Add(3); binormalIndices.Add(3); positionIndices.Add(7); normalIndices.Add(2); colorIndices.Add(0); uv0Indices.Add(2); uv1Indices.Add(2); tangentIndices.Add(3); binormalIndices.Add(3); positionIndices.Add(1); normalIndices.Add(6); colorIndices.Add(0); uv0Indices.Add(1); uv1Indices.Add(1); tangentIndices.Add(3); binormalIndices.Add(3); positionIndices.Add(0); normalIndices.Add(4); colorIndices.Add(0); uv0Indices.Add(0); uv1Indices.Add(0); tangentIndices.Add(3); binormalIndices.Add(3); //// Quad 3 //t = Float3.Normalize(p[1] - p[0]); //b = Float3.Cross(Float3.Normalize(n[4] + n[6] + n[2] + n[0]), t); //vertex = new Vertex // { Position = p[6], Color = color, Normal = n[0], UV0 = uv[3], UV1 = uv[3], Tangent = t, Binormal = b }; //s.Add(ref vertex); //vertex = new Vertex // { Position = p[7], Color = color, Normal = n[2], UV0 = uv[2], UV1 = uv[2], Tangent = t, Binormal = b }; //s.Add(ref vertex); //vertex = new Vertex // { Position = p[1], Color = color, Normal = n[6], UV0 = uv[1], UV1 = uv[1], Tangent = t, Binormal = b }; //s.Add(ref vertex); //vertex = new Vertex // { Position = p[0], Color = color, Normal = n[4], UV0 = uv[0], UV1 = uv[0], Tangent = t, Binormal = b }; //s.Add(ref vertex); positionIndices.Add(1); normalIndices.Add(6); colorIndices.Add(0); uv0Indices.Add(3); uv1Indices.Add(3); tangentIndices.Add(4); binormalIndices.Add(4); positionIndices.Add(7); normalIndices.Add(2); colorIndices.Add(0); uv0Indices.Add(2); uv1Indices.Add(2); tangentIndices.Add(4); binormalIndices.Add(4); positionIndices.Add(5); normalIndices.Add(3); colorIndices.Add(0); uv0Indices.Add(1); uv1Indices.Add(1); tangentIndices.Add(4); binormalIndices.Add(4); positionIndices.Add(3); normalIndices.Add(7); colorIndices.Add(0); uv0Indices.Add(0); uv1Indices.Add(0); tangentIndices.Add(4); binormalIndices.Add(4); //// Quad 4 //t = Float3.Normalize(p[5] - p[3]); //b = Float3.Cross(Float3.Normalize(n[7] + n[3] + n[2] + n[6]), t); //vertex = new Vertex // { Position = p[1], Color = color, Normal = n[6], UV0 = uv[3], UV1 = uv[3], Tangent = t, Binormal = b }; //s.Add(ref vertex); //vertex = new Vertex // { Position = p[7], Color = color, Normal = n[2], UV0 = uv[2], UV1 = uv[2], Tangent = t, Binormal = b }; //s.Add(ref vertex); //vertex = new Vertex // { Position = p[5], Color = color, Normal = n[3], UV0 = uv[1], UV1 = uv[1], Tangent = t, Binormal = b }; //s.Add(ref vertex); //vertex = new Vertex // { Position = p[3], Color = color, Normal = n[7], UV0 = uv[0], UV1 = uv[0], Tangent = t, Binormal = b }; //s.Add(ref vertex); positionIndices.Add(6); normalIndices.Add(0); colorIndices.Add(0); uv0Indices.Add(3); uv1Indices.Add(3); tangentIndices.Add(5); binormalIndices.Add(5); positionIndices.Add(0); normalIndices.Add(4); colorIndices.Add(0); uv0Indices.Add(2); uv1Indices.Add(2); tangentIndices.Add(5); binormalIndices.Add(5); positionIndices.Add(2); normalIndices.Add(5); colorIndices.Add(0); uv0Indices.Add(1); uv1Indices.Add(1); tangentIndices.Add(5); binormalIndices.Add(5); positionIndices.Add(4); normalIndices.Add(1); colorIndices.Add(0); uv0Indices.Add(0); uv1Indices.Add(0); tangentIndices.Add(5); binormalIndices.Add(5); //// Quad 5 //t = Float3.Normalize(p[2] - p[4]); //b = Float3.Cross(Float3.Normalize(n[1] + n[5] + n[4] + n[0]), t); //vertex = new Vertex // { Position = p[6], Color = color, Normal = n[0], UV0 = uv[3], UV1 = uv[3], Tangent = t, Binormal = b }; //s.Add(ref vertex); //vertex = new Vertex // { Position = p[0], Color = color, Normal = n[4], UV0 = uv[2], UV1 = uv[2], Tangent = t, Binormal = b }; //s.Add(ref vertex); //vertex = new Vertex // { Position = p[2], Color = color, Normal = n[5], UV0 = uv[1], UV1 = uv[1], Tangent = t, Binormal = b }; //s.Add(ref vertex); //vertex = new Vertex // { Position = p[4], Color = color, Normal = n[1], UV0 = uv[0], UV1 = uv[0], Tangent = t, Binormal = b }; //s.Add(ref vertex); return res; }
private void ParsSubMesh(AseParser parser, Scene scene, Node node) { var mesh = new SeparateStreamsMesh(); var submesh = mesh.CreateSubmesh(); node.Mesh = mesh; scene.Geometries.Add(mesh); ArrayMeshStream<Float3> vertices = null; ListMeshStream<Float3> normalStream = null; FaceNormal[] normals = null; ArrayMeshStream<Float3> tvertices = null; ArrayMeshStream<Color> cols = null; AseFace[] faces = null; AseTFace[] tfaces = null; Tuple<int, int, int>[] colFaces = null; //TODO: submesh can have it's own vertex streams parser.Consume("{"); for (;;) { var attr = parser.Consume(); if (attr == null || attr == "}") { break; } if (0 == string.Compare(attr, "*TIMEVALUE", StringComparison.InvariantCultureIgnoreCase)) { parser.ConsumeFloat(); continue; } if (0 == string.Compare(attr, "*MESH_NUMVERTEX", StringComparison.InvariantCultureIgnoreCase)) { vertices = new ArrayMeshStream<Float3>(parser.ConsumeInt(), converterFactory); mesh.SetStream(Streams.Position, 0, vertices); continue; } if (0 == string.Compare(attr, "*MESH_VERTEX_LIST", StringComparison.InvariantCultureIgnoreCase)) { this.ParseVertexList(parser, vertices); continue; } if (0 == string.Compare(attr, "*MESH_NUMTVERTEX", StringComparison.InvariantCultureIgnoreCase)) { tvertices = new ArrayMeshStream<Float3>(parser.ConsumeInt(), converterFactory); mesh.SetStream(Streams.TexCoord, 0, tvertices); continue; } if (0 == string.Compare(attr, "*MESH_TVERTLIST", StringComparison.InvariantCultureIgnoreCase)) { this.ParseTVertList(parser, tvertices); continue; } if (0 == string.Compare(attr, "*MESH_NUMTVFACES", StringComparison.InvariantCultureIgnoreCase)) { tfaces = new AseTFace[parser.ConsumeInt()]; continue; } if (0 == string.Compare(attr, "*MESH_TFACELIST", StringComparison.InvariantCultureIgnoreCase)) { this.ParseTFaceList(parser, tfaces); continue; } if (0 == string.Compare(attr, "*MESH_NUMCVERTEX", StringComparison.InvariantCultureIgnoreCase)) { cols = new ArrayMeshStream<Color>(parser.ConsumeInt(), converterFactory); mesh.SetStream(Streams.Color, 0, cols); continue; } if (0 == string.Compare(attr, "*MESH_CVERTLIST", StringComparison.InvariantCultureIgnoreCase)) { this.ParseColList(parser, cols); continue; } if (0 == string.Compare(attr, "*MESH_NUMCVFACES", StringComparison.InvariantCultureIgnoreCase)) { colFaces = new Tuple<int, int, int>[parser.ConsumeInt()]; continue; } if (0 == string.Compare(attr, "*MESH_CFACELIST", StringComparison.InvariantCultureIgnoreCase)) { this.ParseColFaceList(parser, colFaces); continue; } if (0 == string.Compare(attr, "*MESH_NORMALS", StringComparison.InvariantCultureIgnoreCase)) { normals = new FaceNormal[faces.Length]; this.ParsNormalList(parser, normals); continue; } if (0 == string.Compare(attr, "*MESH_NUMFACES", StringComparison.InvariantCultureIgnoreCase)) { faces = new AseFace[parser.ConsumeInt()]; continue; } if (0 == string.Compare(attr, "*MESH_FACE_LIST", StringComparison.InvariantCultureIgnoreCase)) { this.ParseFaceList(parser, faces); continue; } parser.UnknownLexemError(); } ListMeshStream<int> positionIndices = null; if (vertices != null) { positionIndices = new ListMeshStream<int>(faces.Length * 3,converterFactory); submesh.SetIndexStream(Streams.Position, 0, positionIndices); } ListMeshStream<int> normalIndices = null; if (normals != null) { normalStream = new ListMeshStream<Float3>(faces.Length * 3, converterFactory); mesh.SetStream(Streams.Normal, 0, normalStream); normalIndices = new ListMeshStream<int>(faces.Length * 3, converterFactory); submesh.SetIndexStream(Streams.Normal, 0, normalIndices); } ListMeshStream<int> colorIndices = null; if (cols != null) { colorIndices = new ListMeshStream<int>(faces.Length * 3, converterFactory); submesh.SetIndexStream(Streams.Color, 0, colorIndices); } ListMeshStream<int> texCoordIndices = null; if (tvertices != null) { texCoordIndices = new ListMeshStream<int>(faces.Length * 3, converterFactory); submesh.SetIndexStream(Streams.TexCoord, 0, texCoordIndices); } for (int i = 0; i < faces.Length; ++i) { // -------------------------------------------------- // if (positionIndices != null) { positionIndices.Add(faces[i].A); } if (normalIndices != null) { normalIndices.Add(normalStream.Count); normalStream.Add(normals[i].A.Normal); } if (colorIndices != null) { colorIndices.Add(colFaces[i].Item1); } if (texCoordIndices != null) { texCoordIndices.Add(tfaces[i].A); } // -------------------------------------------------- // if (positionIndices != null) { positionIndices.Add(faces[i].C); } if (normalIndices != null) { normalIndices.Add(normalStream.Count); normalStream.Add(normals[i].C.Normal); } if (colorIndices != null) { colorIndices.Add(colFaces[i].Item3); } if (texCoordIndices != null) { texCoordIndices.Add(tfaces[i].C); } // -------------------------------------------------- // if (positionIndices != null) { positionIndices.Add(faces[i].B); } if (normalIndices != null) { normalIndices.Add(normalStream.Count); normalStream.Add(normals[i].B.Normal); } if (colorIndices != null) { colorIndices.Add(colFaces[i].Item2); } if (texCoordIndices != null) { texCoordIndices.Add(tfaces[i].B); } // -------------------------------------------------- // } }
private void BuildSubmeshes(int maxTextures, SeparateStreamsSubmesh[] submeshes, SeparateStreamsMesh streamMesh, BspMeshStreams meshStreams) { int[] textureToMaterial = new int[maxTextures]; foreach (var quake3Face in this.faces) { ++textureToMaterial[quake3Face.texinfo_id]; } for (int i = 0; i < maxTextures; ++i) { if (textureToMaterial[i] > 0) { submeshes[i] = streamMesh.CreateSubmesh(); int index = this.Scene.Materials.Count; var baseFileName = Path.Combine(this.GameRootPath, this.textures[i].name); var imagePath = baseFileName; if (!File.Exists(imagePath)) { imagePath = baseFileName + ".jpg"; if (!File.Exists(imagePath)) { imagePath = baseFileName + ".png"; if (!File.Exists(imagePath)) { imagePath = baseFileName + ".tga"; if (!File.Exists(imagePath)) { imagePath = this.textures[i].name; } } } } var texture = new FileReferenceImage { Path = imagePath }; this.Scene.Images.Add(texture); var effect = new SceneEffect { Diffuse = new ImageColorSource { Image = texture }, CullMode = CullMode.Front}; this.Scene.Effects.Add(effect); var sceneMaterial = new SceneMaterial { Effect = effect }; this.Scene.Materials.Add(sceneMaterial); submeshes[i].Material = sceneMaterial; textureToMaterial[i] = index; } } }