Ejemplo n.º 1
0
        public static void readMaterialFile(string mttlibLine, ref MaterialManager.Material material)
        {
            // mtllib voxelColor.mtl
            char[]   space        = { ' ' };
            string[] matFileLines = mttlibLine.Split(space);
            string   filename     = matFileLines[1];

            material = MaterialManager.loadMaterial(filename);
        }
Ejemplo n.º 2
0
        public Mesh(List <PosNorTexVertex> vertices, MaterialManager.Material meshMaterial)
        {
            BufferHandle      = GL.GenBuffer();
            VAOHandle         = GL.GenVertexArray();
            IndexBufferHandle = GL.GenBuffer();

            VertexAmount = vertices.Count;

            Error.checkGLError("Mesh constructor");

            rawVertices = vertices;

            MeshMaterial = meshMaterial;

            // Transformcomponent
            worldMatrix        = new Matrix4Uniform("modelMatrix");
            worldMatrix.Matrix = Matrix4.Identity;

            // RenderingComponent
            Scale        = 1.0f;
            DiffuseColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f);
            rotationY    = 0.0f;
        }
Ejemplo n.º 3
0
        // Reads on .obs file
        static public Mesh CreateFromFile(string filename)
        {
            List <OBJFileReader.OBJFace> faces = new List <OBJFileReader.OBJFace>();

            List <Vector3> positions = new List <Vector3>();
            List <Vector3> normals   = new List <Vector3>();
            List <Vector2> texCoords = new List <Vector2>();

            MaterialManager.Material meshMaterial = null;

            OBJFileReader.readOBJ(filename, ref faces, ref positions, ref normals, ref texCoords, ref meshMaterial);

            // Create positions
            List <PosNorTexVertex> vertices = new List <PosNorTexVertex>(positions.Count);

            Console.WriteLine("Mesh read from " + filename);

            foreach (OBJFileReader.OBJFace face in faces)
            {
                vertices.Add(new PosNorTexVertex(positions[(int)face.positionIndex - 1], normals[(int)face.normalIndex - 1], texCoords[(int)face.texCoordIndex - 1]));
            }

            return(new Mesh(vertices, meshMaterial));
        }
Ejemplo n.º 4
0
        public static void readOBJ(string filename, ref List <OBJFileReader.OBJFace> faces, ref List <Vector3> positions, ref List <Vector3> normals, ref List <Vector2> texCoords, ref MaterialManager.Material material)
        {
            // Sections
            // . normals
            // . texcoords
            // . verts
            // . faces


            StreamReader sourceFile = new StreamReader(filename);

            string line;

            do
            {
                line = sourceFile.ReadLine();
                if (line == null)
                {
                    break;
                }

                if (line.Contains("#"))
                {
                    // comment
                }
                else if (line.Contains("mtllib"))
                {
                    // material
                    // Read material properties from file
                    OBJFileReader.readMaterialFile(line, ref material);
                }
                else if (line.Contains("usemtl"))
                {
                    // material, what material to use.
                }
                else if (line.Contains("vn"))
                {
                    normals.Add(readNormal(line));
                }
                else if (line.Contains("vt"))
                {
                    texCoords.Add(readVector2(line));
                }
                else if (line.Contains("v"))
                {
                    positions.Add(readPos(line));
                }
                else if (line.Contains("f"))
                {
                    OBJFileReader.readFaces(line, ref faces);
                }
            } while (line != null);


            sourceFile.Close();
        }