我正在尝试加载 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);
}