Exemple #1
0
        public void MtlLoad_Tests()
        {
            var mtlFile = Path.Combine(SampleRootPath, "model/model.mtl");

            var model = MtlParser.Parse(mtlFile);

            Assert.NotNull(model);
            Assert.Equal(4, model.Materials.Count);
        }
Exemple #2
0
 public Converter(string objFile, bool binary, bool withBatchTable = false)
     : this(objFile, new GltfOptions
 {
     Binary = binary,
     WithBatchTable = withBatchTable,
     ObjEncoding = MtlParser.InitEncoding(objFile)
 })
 {
 }
Exemple #3
0
        private void AddSponzaAtriumObjects()
        {
            ObjParser parser = new ObjParser();

            using (FileStream objStream = File.OpenRead(AssetHelper.GetPath("Models/SponzaAtrium/sponza.obj")))
            {
                ObjFile atriumFile = parser.Parse(objStream);
                MtlFile atriumMtls;
                using (FileStream mtlStream = File.OpenRead(AssetHelper.GetPath("Models/SponzaAtrium/sponza.mtl")))
                {
                    atriumMtls = new MtlParser().Parse(mtlStream);
                }

                foreach (ObjFile.MeshGroup group in atriumFile.MeshGroups)
                {
                    Vector3                scale               = new Vector3(0.1f);
                    ConstructedMeshInfo    mesh                = atriumFile.GetMesh(group);
                    MaterialDefinition     materialDef         = atriumMtls.Definitions[mesh.MaterialName];
                    ImageSharpTexture      overrideTextureData = null;
                    ImageSharpTexture      alphaTexture        = null;
                    MaterialPropsAndBuffer materialProps       = CommonMaterials.Brick;
                    if (materialDef.DiffuseTexture != null)
                    {
                        string texturePath = AssetHelper.GetPath("Models/SponzaAtrium/" + materialDef.DiffuseTexture);
                        overrideTextureData = LoadTexture(texturePath, true);
                    }
                    if (materialDef.AlphaMap != null)
                    {
                        string texturePath = AssetHelper.GetPath("Models/SponzaAtrium/" + materialDef.AlphaMap);
                        alphaTexture = LoadTexture(texturePath, false);
                    }
                    if (materialDef.Name.Contains("vase"))
                    {
                        materialProps = CommonMaterials.Vase;
                    }
                    if (group.Name == "sponza_117")
                    {
                        MirrorMesh.Plane = Plane.CreateFromVertices(
                            atriumFile.Positions[group.Faces[0].Vertex0.PositionIndex] * scale.X,
                            atriumFile.Positions[group.Faces[0].Vertex1.PositionIndex] * scale.Y,
                            atriumFile.Positions[group.Faces[0].Vertex2.PositionIndex] * scale.Z);
                        materialProps = CommonMaterials.Reflective;
                    }

                    AddTexturedMesh(
                        mesh,
                        overrideTextureData,
                        alphaTexture,
                        materialProps,
                        Vector3.Zero,
                        Quaternion.Identity,
                        scale,
                        group.Name);
                }
            }
        }
Exemple #4
0
        public void LoadMtl_Test()
        {
            var mtlFile = @"..\..\..\..\testassets\Office\model.mtl";

            Assert.True(System.IO.File.Exists(mtlFile), "mtl file does not exist!");
            using (var mtlParser = new MtlParser(mtlFile))
            {
                var mats = mtlParser.GetMats();
                Assert.True(mats.Count > 0);
            }
        }
Exemple #5
0
        private void DrawObj()
        {
            string texPath = ConfigurationManager.AppSettings["TexPath"];
            string path    = ConfigurationManager.AppSettings["ObjPath"];

            StringBuilder   builder   = new StringBuilder();
            Stopwatch       watch     = Stopwatch.StartNew();
            Mesh            mesh      = ObjParser.GetMeshFromFile(path);
            List <Material> materials = MtlParser.GetMaterialFromFile("Wood Texture.mtl");

            watch.Stop();
            builder.AppendLine($"Parsing: {watch.ElapsedMilliseconds} ms");
            watch        = Stopwatch.StartNew();
            mesh.Texture = Bitmap.FromFile(texPath) as Bitmap;
            watch.Stop();
            builder.AppendLine($"Loading texture: {watch.ElapsedMilliseconds} ms");
            watch = Stopwatch.StartNew();
            _canvas.DrawMesh(mesh, Line.LineType.Bresenham);
            watch.Stop();
            builder.AppendLine($"Drawing: {watch.ElapsedMilliseconds} ms");
            LogView.Text = builder.ToString();
        }
Exemple #6
0
        private void AddSponzaAtriumObjects(CommandList cl)
        {
            ObjParser parser = new ObjParser();

            using (FileStream objStream = File.OpenRead(AssetHelper.GetPath("Models/SponzaAtrium/sponza.obj")))
            {
                ObjFile atriumFile = parser.Parse(objStream);
                MtlFile atriumMtls;
                using (FileStream mtlStream = File.OpenRead(AssetHelper.GetPath("Models/SponzaAtrium/sponza.mtl")))
                {
                    atriumMtls = new MtlParser().Parse(mtlStream);
                }

                foreach (ObjFile.MeshGroup group in atriumFile.MeshGroups)
                {
                    ConstructedMeshInfo    mesh                = atriumFile.GetMesh(group);
                    MaterialDefinition     materialDef         = atriumMtls.Definitions[mesh.MaterialName];
                    ImageSharpTexture      overrideTextureData = null;
                    ImageSharpTexture      alphaTexture        = null;
                    MaterialPropsAndBuffer materialProps       = CommonMaterials.Brick;
                    if (materialDef.DiffuseTexture != null)
                    {
                        string texturePath = AssetHelper.GetPath("Models/SponzaAtrium/" + materialDef.DiffuseTexture);
                        overrideTextureData = LoadTexture(texturePath, true);
                    }
                    if (materialDef.AlphaMap != null)
                    {
                        string texturePath = AssetHelper.GetPath("Models/SponzaAtrium/" + materialDef.AlphaMap);
                        alphaTexture = LoadTexture(texturePath, false);
                    }
                    if (materialDef.Name.Contains("vase"))
                    {
                        materialProps = CommonMaterials.Vase;
                    }

                    AddTexturedMesh(cl, mesh, overrideTextureData, alphaTexture, materialProps, Vector3.Zero, Quaternion.Identity, new Vector3(0.1f));
                }
            }
        }
Exemple #7
0
        public MtlFile Deserialize(Stream stream)
        {
            var parser = new MtlParser();

            return(parser.Parse(stream));
        }
Exemple #8
0
 /// <summary>
 /// Store the data from the parsed .mtl file in the Mtl attribute
 /// </summary>
 public void UpdateMtlData()
 {
     Mtl = MtlParser.GetMtlData(this);
 }