Example #1
0
        /// <summary>
        /// Parse a material declaration in a .MTL file (a line of the kind "newmtl testmtl").
        /// </summary>
        private void ParseMtlMaterialDeclaration()
        {
            // Check that the line contains a material name
            if (mtlParser.IsEndOfLine)
            {
                throw new InvalidObjMtlFileException(string.Format(
                                                         "{0}: Material declaration without a corresponding material name.", mtlParser.GetFilePositionStr()));
            }

            // Create the new material instance
            string materialName = mtlParser.ReadRestOfLine().Trim();

            currentLoadMaterial = new ObjMtlMaterial();

            if (materials.ContainsKey(materialName))
            {
                throw new InvalidObjMtlFileException(string.Format(
                                                         "{0}: Duplicate material name '{1}'.", mtlParser.GetFilePositionStr(), materialName));
            }
            materials.Add(materialName, currentLoadMaterial);
        }
Example #2
0
        /// <summary>
        /// Parses a object name declaration in a .OBJ file (a line of the kind "o [object name]").
        /// </summary>
        private void ParseObjObjectDeclaration()
        {
            // Check that the line contains an object name
            if (objParser.IsEndOfLine)
            {
                throw new InvalidObjMtlFileException(string.Format(
                                                         "{0}: Object declaration without a corresponding object name.", objParser.GetFilePositionStr()));
            }

            // Create the new object instance
            string newObjectName = objParser.ReadRestOfLine().Trim();

            currentObject = new ObjMtlObject();
            currentMesh   = null;

            // Add the object to the object list
            if (model.Objects.ContainsKey(newObjectName))
            {
                throw new InvalidObjMtlFileException(string.Format(
                                                         "{0}: Duplicate object name '{1}'.", objParser.GetFilePositionStr(), newObjectName));
            }
            model.Objects.Add(newObjectName, currentObject);
        }