コード例 #1
0
        /// <summary>
        /// Load a .MTL file from the specified path.
        /// </summary>
        /// <param name="mtlPath">The path of the .MTL file.</param>
        private void LoadMtl(string mtlPath)
        {
            this.mtlPath   = mtlPath;
            this.mtlParser = null;

            this.materials = new Dictionary <string, ObjMtlMaterial>();

            this.currentLoadMaterial = null;

            using (mtlParser = new ObjMtlParser(mtlPath))
            {
                while (mtlParser.ReadNextLine())
                {
                    // Parse according to the keyword
                    string keyword = mtlParser.GetNextWord();

                    switch (keyword)
                    {
                    case "newmtl":
                        ParseMtlMaterialDeclaration();
                        break;

                    case "map_Kd":
                        ParseMtlDiffuseTextureMapDeclaration();
                        break;

                    case null:     // Empty line
                        break;

                    default:
                        warningLog.Add(string.Format(
                                           "{0}: Unrecognized keyword '{1}'.", mtlParser.GetFilePositionStr(), keyword));
                        break;
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Load the model from the .OBJ file
        /// </summary>
        /// <param name="objPath">The path of a file containing the .OBJ file.</param>
        /// <returns>A list of warnings while loading the file.</returns>
        public List <string> LoadObj(string objPath)
        {
            if (objPath == null)
            {
                throw new ArgumentNullException("objPath");
            }

            // Set up the parser status to load a new .OBJ file
            this.warningLog = new List <string>();

            this.objPath   = objPath;
            this.objParser = null;

            this.vertexPositions = new List <Vector4>();
            this.vertexNormals   = new List <Vector3>();
            this.vertexTexCoords = new List <Vector3>();

            this.currentObject       = null;
            this.currentMesh         = null;
            this.currentUsedMaterial = null;

            this.mtlPath   = null;
            this.mtlParser = null;

            this.materials = new Dictionary <string, ObjMtlMaterial>();

            this.currentLoadMaterial = null;

            using (objParser = new ObjMtlParser(objPath))
            {
                while (objParser.ReadNextLine())
                {
                    // Parse according to the keyword
                    string keyword = objParser.GetNextWord();

                    switch (keyword)
                    {
                    case "o":
                        ParseObjObjectDeclaration();
                        break;

                    case "mtllib":
                        ParseObjMtlLibDeclaration();
                        break;

                    case "usemtl":
                        ParseObjUseMtlDeclaration();
                        break;

                    case "v":
                        ParseObjVertexPositionDeclaration();
                        break;

                    case "vn":
                        ParseObjVertexNormalDeclaration();
                        break;

                    case "vt":
                        ParseObjVertexTexCoordDeclaration();
                        break;

                    case "f":
                        ParseObjFaceDeclaration();
                        break;

                    case null:     // Empty line
                        break;

                    default:
                        warningLog.Add(string.Format(
                                           "{0}: Unrecognized keyword '{1}'.", objParser.GetFilePositionStr(), keyword));
                        break;
                    }
                }
            }

            return(warningLog);
        }