本文介绍了如何使用Helix ToolKit加载纹理和材质?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试加载3d obj文件或3ds文件,它已加载

I am trying to load 3d obj files or 3ds file, it's loaded

但是很遗憾,我无法加载.mtl文件或任何纹理

任何想法/示例代码如何加载.mtl文件或纹理?

Any Idea/sample code how to load .mtl files or textures?

--->已加载3D模型,但颜色为灰色

---> The 3D models is loaded but in gray color

public void load3dModel()
    {
        ObjReader CurrentHelixObjReader = new ObjReader();
       // Model3DGroup MyModel = CurrentHelixObjReader.Read(@"D:\3DModel\dinosaur_FBX\dinosaur.fbx");
      // Model3DGroup MyModel = CurrentHelixObjReader.Read(@"C:\Users\aaa\Downloads\jlb4kmi4xssg-iphone6model\iphone_6_model.FBX");


        Model3DGroup model = null;
        string path = @"C:\Users\aaa\Downloads\jlb4kmi4xssg-iphone6model\note4.obj";
        string ext = System.IO.Path.GetExtension(path).ToLower();
        switch (ext)
        {
            case ".3ds":
                {
                    var r = new StudioReader();
                    model = r.Read(path);
                    break;
                }

            case ".fbx":
                {
                    var r = new HelixToolkit.Wpf.ObjReader();
                    model = r.Read(path);
                    break;
                }

            case ".lwo":
                {
                    var r = new HelixToolkit.Wpf.LwoReader();
                    model = r.Read(path);

                    break;
                }

            case ".obj":
                {
                    var r = new HelixToolkit.Wpf.ObjReader();
                    model = r.Read(path);

                    //Material matty = (MaterialGroup)((GeometryModel3D)model.Children[0]).Material;
                    //Material myMaterial = MaterialHelper.CreateImageMaterial(@"C:\Users\aaa\Downloads\jlb4kmi4xssg-iphone6model\sam-scrn.jpg", 1);
                   // Material anotherMaterial = ((GeometryModel3D)model.Children[0]).Material;
                   //  Newmodel.Children.Add(new GeometryModel3D { Geometry = anotherMaterial, Material = myMaterial });
                    break;
                }

            case ".objz":
                {
                    var r = new HelixToolkit.Wpf.ObjReader();
                    model = r.ReadZ(path);
                    break;
                }

            case ".stl":
                {
                    var r = new HelixToolkit.Wpf.StLReader();
                    model = r.Read(path);
                    break;
                }

            case ".off":
                {
                    var r = new HelixToolkit.Wpf.OffReader();
                    model = r.Read(path);
                    break;
                }

            default:
                throw new InvalidOperationException("File format not supported.");
        }

       Newmodel.Content = model;

        //MyModel.Children.Add(MyModel);


    }

推荐答案

实际上,至少对于.obj文件,默认情况下,螺旋实际上是这样做的.在您的.obj文件中,必须有一行

actually helix do it by default at least for .obj files.In your .obj file there must be a line like

mtllib File02.mtl

其中File02.mtl是您的材料文件名. helix然后调用LoadMaterialLib方法,该方法读取mtllib之后指定的.mtl文件.只要确保此.mtl文件存在并且其名称没有更改即可.也许您同时更改了.obj和.mtl文件名,但是在.obj文件中,mtllib参数保持不变.

where File02.mtl is your material file name. helix calls then LoadMaterialLib method, which reads the .mtl file specified after mtllib. Just be sure this .mtl file exists and his name was not changed. Perhaps you changed both .obj and .mtl filenames, but inside of the .obj file the mtllib parameter remained unchanged.

这篇关于如何使用Helix ToolKit加载纹理和材质?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 05:04