public void Initialize(Device device, string sceneName) { m_ObjectLoader.Load(sceneName + ".obj"); m_ObjectLoader.LoadMaterials(sceneName + ".mtl"); m_MaterialsResources = new TexWrapper[m_ObjectLoader.m_MatTexMappingDiffuse.Count]; int counter = 0; foreach (var v in m_ObjectLoader.m_MatTexMappingDiffuse) { TexWrapper tex = new TexWrapper(); bool found = false; foreach (var t in m_MaterialsResources) { if (t.textureName == v.Value) { tex.name = v.Key; tex.textureName = v.Value; tex.textureObject = t.textureObject; tex.textureSrv = t.textureSrv; found = true; break; } } if (!found) { tex.name = v.Key; tex.textureName = v.Value; try { tex.textureObject = Texture2D.FromFile(device, v.Value); tex.textureSrv = new ShaderResourceView(device, tex.textureObject); } catch { tex.textureObject = null; tex.textureSrv = null; } } m_MaterialsResources[counter++] = tex; } int numVertices = m_ObjectLoader.m_Vertices.Count; int numIndices = m_ObjectLoader.m_Indices.Count; // create test vertex data, making sure to rewind the stream afterward var vertices = new DataStream(8 * sizeof(System.Single) * numVertices, true, true); foreach (var vertex in m_ObjectLoader.m_Vertices) { vertices.Write(new Vector3(vertex.x, vertex.y, vertex.z)); Vector3 normal = new Vector3(vertex.nx, vertex.ny, vertex.nz); vertices.Write(normal); Vector2 uv = new Vector2(vertex.u, vertex.v); vertices.Write(uv); } vertices.Position = 0; var indices = new DataStream(sizeof(System.Int32) * numIndices, true, true); foreach (var index in m_ObjectLoader.m_Indices) { indices.Write(index); } indices.Position = 0; // create the vertex layout and buffer var elements = new[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0), new InputElement("NORMAL", 0, Format.R32G32B32_Float, 0), new InputElement("TEXCOORD", 0, Format.R32G32_Float, 0) }; m_SceneInputLayout = new InputLayout(device, ShaderManager.GetVertexShaderSignature("VertexScene"), elements); m_VertexBuffer = new Buffer(device, vertices, 8 * sizeof(System.Single) * numVertices, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); m_IndexBuffer = new Buffer(device, indices, 4 * numIndices, ResourceUsage.Default, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); }