Exemple #1
0
 private void FinalizeCurrentMaterial()
 {
     if (_currentDefinition != null)
     {
         _definitions.Add(_currentDefinition);
         _currentDefinition = null;
     }
 }
Exemple #2
0
            public void Process(string line)
            {
                _currentLine++;
                _currentLineText = line;

                string[] pieces = line.Split(s_whitespaceChars, StringSplitOptions.RemoveEmptyEntries);
                if (pieces.Length == 0 || pieces[0].StartsWith("#"))
                {
                    return;
                }
                switch (pieces[0].ToLowerInvariant().Trim())
                {
                case "newmtl":
                    ExpectExactly(pieces, 1, "newmtl");
                    FinalizeCurrentMaterial();
                    _currentDefinition = new MaterialDefinition(pieces[1]);
                    break;

                case "ka":
                    ExpectExactly(pieces, 3, "Ka");
                    _currentDefinition.AmbientReflectivity = ParseVector3(pieces[1], pieces[2], pieces[3], "Ka");
                    break;

                case "kd":
                    ExpectExactly(pieces, 3, "Kd");
                    _currentDefinition.DiffuseReflectivity = ParseVector3(pieces[1], pieces[2], pieces[3], "Kd");
                    break;

                case "ks":
                    ExpectExactly(pieces, 3, "Ks");
                    _currentDefinition.SpecularReflectivity = ParseVector3(pieces[1], pieces[2], pieces[3], "Ks");
                    break;

                case "ke":     // Non-standard?
                    ExpectExactly(pieces, 3, "Ke");
                    _currentDefinition.EmissiveCoefficient = ParseVector3(pieces[1], pieces[2], pieces[3], "Ks");
                    break;

                case "tf":
                    ExpectExactly(pieces, 3, "Tf");
                    _currentDefinition.TransmissionFilter = ParseVector3(pieces[1], pieces[2], pieces[3], "Tf");
                    break;

                case "illum":
                    ExpectExactly(pieces, 1, "illum");
                    _currentDefinition.IlluminationModel = ParseInt(pieces[1], "illum");
                    break;

                case "d":     // "Dissolve", or opacity
                    ExpectExactly(pieces, 1, "d");
                    _currentDefinition.Opacity = ParseFloat(pieces[1], "d");
                    break;

                case "tr":     // Transparency
                    ExpectExactly(pieces, 1, "Tr");
                    _currentDefinition.Opacity = 1 - ParseFloat(pieces[1], "Tr");
                    break;

                case "ns":
                    ExpectExactly(pieces, 1, "Ns");
                    _currentDefinition.SpecularExponent = ParseFloat(pieces[1], "Ns");
                    break;

                case "sharpness":
                    ExpectExactly(pieces, 1, "sharpness");
                    _currentDefinition.Sharpness = ParseFloat(pieces[1], "sharpness");
                    break;

                case "ni":     // "Index of refraction"
                    ExpectExactly(pieces, 1, "Ni");
                    _currentDefinition.OpticalDensity = ParseFloat(pieces[1], "Ni");
                    break;

                case "map_ka":
                    ExpectExactly(pieces, 1, "map_ka");
                    _currentDefinition.AmbientTexture = pieces[1];
                    break;

                case "map_kd":
                    ExpectExactly(pieces, 1, "map_kd");
                    _currentDefinition.DiffuseTexture = pieces[1];
                    break;

                case "map_bump":
                case "bump":
                    ExpectExactly(pieces, 1, "map_bump");
                    _currentDefinition.BumpMap = pieces[1];
                    break;

                case "map_d":
                    ExpectExactly(pieces, 1, "map_d");
                    _currentDefinition.AlphaMap = pieces[1];
                    break;

                case "map_ns":
                    ExpectExactly(pieces, 1, "map_ns");
                    _currentDefinition.SpecularColorTexture = pieces[1];
                    break;


                default:
                    throw new ObjParseException(
                              string.Format("An unsupported line-type specifier, '{0}', was used on line {1}, \"{2}\"",
                                            pieces[0],
                                            _currentLine,
                                            _currentLineText));
                }
            }