Note that there are some explanatory texts on larger screens.

plurals
  1. POIncorrect render of mesh in DirectX
    primarykey
    data
    text
    <p>I'm still pretty new to DirectX however I'm coming close to reaching my goal of rendering a special file format inside C#. I have one final hurdle. I have written some code to parse the file into a mesh object. I have done this to allow multiple textures to be rendered. As I said before I'm relative new to DirectX and have never created a mesh object from scratch. I have looked on the internet a lot to try and better understand how to create one from scratch. However many tutorials on the subject are not dealing with sub meshes and even Microsoft's own documentation is lacking. The problem I have is that the model is not rendering properly (See below). I'm really unsure if I have the properties of the AttributeRanges correct. Or my indices are incorrect as a whole (when rendering all models). <a href="http://s11.postimage.org/56dms3hlf/incorrectrender.png" rel="nofollow noreferrer">Image of rendering issues http://s11.postimage.org/56dms3hlf/incorrectrender.png</a></p> <p>One thing I can rule out is the validity of my data. I am 100% certain that my data is correct. My vertex position, texture mapping and my indices (correct for the vertex data for each separate model). If I adjust my loops and render only the first model. Heres my result. <a href="http://s12.postimage.org/de89qlw8t/correctrenderof0.png" rel="nofollow noreferrer">First model render http://s12.postimage.org/de89qlw8t/correctrenderof0.png</a></p> <p>Heres my code. I know it is messy :|</p> <pre><code>public void RenderModel(Model[] models,bool isTextured = false,bool wireFrame = false) { //Model object contains all vertex data and indices for that model //The indices do not hold any relation to other models. this.modelss = models; int vertexCount = 0; for (int currentModelID = 0; currentModelID &lt; models.Length; currentModelID++) { Model model = models[currentModelID]; vertexCount += model.renderDataSource.vertices.Length; AttributeRange range = new AttributeRange(); range.AttributeId = currentModelID; range.FaceCount = model.getIndices().Length / 3; range.FaceStart = Indices.Count /3; range.VertexCount = model.getTexturedVertices().Length; range.VertexStart = vertices.Count; this.vertices.AddRange(model.getTexturedVertices()); this.Indices.AddRange(model.getIndices()); Console.WriteLine("ID: " + range.AttributeId + " FaceCount: " + range.FaceCount + " FaceStart: " + range.FaceStart + " vercount " + range.VertexCount + " verstart: " + range.VertexStart ); attributeRanges.Add(range); } this.vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionNormalTextured),vertices.Count, device, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionNormalTextured.Format, Pool.Default); vertexBuffer.SetData(vertices.ToArray(), 0, LockFlags.None); getTextures(); this.indexBuffer = new IndexBuffer(typeof(ushort), Indices.Count, device, Usage.WriteOnly, Pool.Default); indexBuffer.SetData(Indices.ToArray(), 0, LockFlags.None); int faces = Indices.Count /3; int verCount = vertices.Count; model3d = new Mesh(Indices.Count /3 , vertices.Count, MeshFlags.SystemMemory,CustomVertex.PositionNormalTextured.Format, device); model3d.IndexBuffer.SetData(Indices.ToArray(), 0, LockFlags.None); model3d.VertexBuffer.SetData(vertices.ToArray(), 0, LockFlags.None); model3d.SetAttributeTable(attributeRanges.ToArray()); Render(isTextured); } private void Render(bool isTextured) { float x = (float)Math.Cos(rot); float z = (float)Math.Sin(rot); device.BeginScene(); setupLightingAndCamera(); device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, this.Width / this.Height, 1f, 50f); device.Transform.View = Matrix.LookAtLH(new Vector3(x, 8, z), new Vector3(0, 0, 0), new Vector3(0, 1, 0)); DrawMesh(); device.EndScene(); } private void DrawMesh() { for (int i = 0; i &lt; modelss.Length; i++) { Model model = modelss[i]; material = new Material(); material.Diffuse = Color.White; material.Specular = Color.LightGray; material.SpecularSharpness = 15.0F; device.Material = material; //Just obtains correct file from info in dictionaries device.SetTexture(0, textures[textureName[model.renderDataSource.shader]]); model3d.DrawSubset(i); } } </code></pre> <p>Finally heres the output of my debug, might help.</p> <pre><code> ID: 0 FaceCount: 22 FaceStart: 0 vercount 34 verstart: 0 ID: 1 FaceCount: 16 FaceStart: 22 vercount 24 verstart: 34 ID: 2 FaceCount: 16 FaceStart: 38 vercount 24 verstart: 58 ID: 3 FaceCount: 16 FaceStart: 54 vercount 24 verstart: 82 ID: 4 FaceCount: 446 FaceStart: 70 vercount 562 verstart: 106 ID: 5 FaceCount: 1176 FaceStart: 516 vercount 900 verstart: 668 ID: 6 FaceCount: 28 FaceStart: 1692 vercount 32 verstart: 1568 ID: 7 FaceCount: 47 FaceStart: 1720 vercount 76 verstart: 1600 ID: 8 FaceCount: 28 FaceStart: 1767 vercount 32 verstart: 1676 ID: 9 FaceCount: 47 FaceStart: 1795 vercount 76 verstart: 1708 ID: 10 FaceCount: 94 FaceStart: 1842 vercount 90 verstart: 1784 </code></pre> <p>Any help of any kind, would greatly be appreciated. Thank You</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload