public void TestDefaultRendererRenderModel() { //TODO: maybe detach this from the defaultrenderer? DefaultRenderer renderer = new DefaultRenderer(); TangentVertex[] vertices; short[] indices; var mat = new DefaultModelMaterialTextured(); BoxMesh.CreateUnitBoxVerticesAndIndices(out vertices, out indices); var renderable = renderer.CreateModelRenderable(vertices, indices, mat); var el = renderer.CreateRenderElement(renderable); XNAGame game = new XNAGame(); game.InitializeEvent += delegate { //TODO: make the renderer manage textures!!! using (var fs = new FileStream(TestFiles.WoodPlanksBareJPG, FileMode.Open, FileAccess.Read, FileShare.Read)) { mat.DiffuseTexture = Texture2D.FromFile(game.GraphicsDevice, fs); } }; game.AddXNAObject(renderer); game.Run(); }
private void initMeshRenderData(MeshRenderData data) { var materials = new List <MeshRenderMaterial>(); var parts = new Dictionary <MeshRenderMaterial, List <MeshCoreData.Part> >(); var coreData = data.Mesh.GetCoreData(); for (int i = 0; i < coreData.Parts.Count; i++) { var part = coreData.Parts[i]; var mat = materials.Find(o => o.Material.Equals(part.MeshMaterial)); if (mat == null) { mat = new MeshRenderMaterial(); mat.Material = part.MeshMaterial; materials.Add(mat); parts[mat] = new List <MeshCoreData.Part>(); } parts[mat].Add(part); } data.Materials = new MeshRenderMaterial[materials.Count]; for (int i = 0; i < materials.Count; i++) { var renderMat = materials[i]; data.Materials[i] = renderMat; var partList = parts[renderMat]; renderMat.Parts = new MeshRenderPart[partList.Count]; for (int j = 0; j < partList.Count; j++) { var part = partList[j]; var renderPart = new MeshRenderPart(); renderMat.Parts[j] = renderPart; renderPart.IndexBuffer = meshPartPool.GetIndexBuffer(part.MeshPart); renderPart.VertexBuffer = meshPartPool.GetVertexBuffer(part.MeshPart); renderPart.ObjectMatrix = part.ObjectMatrix; var geomData = part.MeshPart.GetGeometryData(); int vertCount = geomData.GetSourceVector3(MeshPartGeometryData.Semantic.Position).Length; renderPart.VertexCount = vertCount; renderPart.PrimitiveCount = vertCount / 3; } renderMat.Shader = baseShader.Clone(); if (renderMat.Material.DiffuseMap != null) { var material = new DefaultModelMaterialTextured(); material.DiffuseTexture = texturePool.LoadTexture(renderMat.Material.DiffuseMap); material.SetMaterialToShader(renderMat.Shader); } else { renderMat.Shader.DiffuseTexture = checkerTexture; renderMat.Shader.Technique = DefaultModelShader.TechniqueType.Textured; } } }