0

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

但不幸的是,我无法加载 .mtl 文件或任何纹理

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

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

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);


    }
4

1 回答 1

1

实际上 helix 在默认情况下至少对 .obj 文件执行此操作。在您的 .obj 文件中必须有一行

mtllib File02.mtl

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

于 2016-04-11T10:18:19.537 回答