Beispiel #1
0
 public NVRDrawIndexedPrimitive(NVRMesh mesh, List <NVRVertex> vertices, List <int> indices, bool complex)
 {
     this.Parent = mesh;
     this.Indices.AddRange(indices);
     if (complex)
     {
         this.Vertices.AddRange(vertices);
         if (vertices.Count > 0)
         {
             this.VertexType = vertices[0].GetVertexType();
             NVRVertexType expectedType = NVRVertex.GetVertexTypeFromMaterial(mesh.Material);
             if (expectedType != this.VertexType)
             {
                 throw new InvalidVertexTypeException(mesh.Material.Type, expectedType);
             }
         }
     }
     else
     {
         this.VertexType = NVRVertexType.NVRVERTEX;
         // Conversion to simple vertex
         foreach (NVRVertex vertex in vertices)
         {
             this.Vertices.Add(new NVRVertex(vertex.Position));
         }
     }
 }
Beispiel #2
0
        public NVRMesh AddMesh(NVRMeshQuality meshQualityLevel, NVRMaterial material, List <NVRVertex> vertices, List <int> indices)
        {
            NVRMesh newMesh = new NVRMesh(meshQualityLevel, 0, material, vertices, indices);

            this.Meshes.Add(newMesh);
            return(newMesh);
        }
Beispiel #3
0
        public NVRDrawIndexedPrimitive(BinaryReader br, NVRBuffers buffers, NVRMesh mesh, bool isComplex)
        {
            this.Parent = mesh;
            // Read vertices
            this.VertexBuffer = br.ReadInt32();
            this.FirstVertex  = br.ReadInt32();
            this.VertexCount  = br.ReadInt32();
            long currentOffset = br.BaseStream.Position;

            // Find vertex type
            int vertexSize = 12;

            if (isComplex)
            {
                this.VertexType = NVRVertex.GetVertexTypeFromMaterial(mesh.Material);
                switch (VertexType)
                {
                case NVRVertexType.NVRVERTEX_4:
                    vertexSize = NVRVertex4.Size;
                    break;

                case NVRVertexType.NVRVERTEX_8:
                    vertexSize = NVRVertex8.Size;
                    break;

                case NVRVertexType.NVRVERTEX_12:
                    vertexSize = NVRVertex12.Size;
                    break;
                }
            }

            //Parse vertices
            br.BaseStream.Seek(buffers.VertexBuffers[VertexBuffer].Offset + FirstVertex * vertexSize, SeekOrigin.Begin);
            for (int i = 0; i < VertexCount; i++)
            {
                NVRVertex newVertex;
                switch (VertexType)
                {
                case NVRVertexType.NVRVERTEX_4:
                    newVertex = new NVRVertex4(br);
                    break;

                case NVRVertexType.NVRVERTEX_8:
                    newVertex = new NVRVertex8(br);
                    break;

                case NVRVertexType.NVRVERTEX_12:
                    newVertex = new NVRVertex12(br);
                    break;

                default:
                    newVertex = new NVRVertex(br);
                    break;
                }
                this.Vertices.Add(newVertex);
            }

            // Store indices
            br.BaseStream.Seek(currentOffset, SeekOrigin.Begin);
            this.IndexBuffer = br.ReadInt32();
            this.FirstIndex  = br.ReadInt32();
            this.IndexCount  = br.ReadInt32();

            for (int i = FirstIndex; i < FirstIndex + IndexCount; i++)
            {
                this.Indices.Add(buffers.IndexBuffers[IndexBuffer].Indices[i]);
            }

            // Fix indices
            int indicesMin = FindMin(this.Indices);

            for (int i = 0; i < this.Indices.Count; i++)
            {
                this.Indices[i] -= indicesMin;
            }
        }