دعم ملفات MTL عند تصدير OBJ

كيفية دعم ملفات MTL عند تصدير OBJ

المشكلة: كيفية دعم ملفات MTL عند تصدير OBJ.

نصائح: للقيام بذلك، يمكنك استخدام ملف المادة عند التصدير إلى تنسيق OBJ. أدناه مثال. المرفقات هي ملفات النتيجة (ColorImage.obj و ColorImage.mtl) وملف المصدر (ColorImage.dwf).

مثال:

string fileName = "ColorImage";
string file = string.Format("{0}.dwf", fileName);
string outFile = string.Format("{0}.obj", fileName);
string mtlFileName = string.Format("{0}.mtl", fileName);
using (FileStream inStream = new FileStream(file, FileMode.Open))
using (Image image = Image.Load(inStream))
using (FileStream stream = new FileStream(outFile, FileMode.Create))
using (var mtlStream = new FileStream(mtlFileName, FileMode.Create))
{
ObjOptions options = new ObjOptions();
options.MtlFileName = mtlFileName;
options.MtlFileStream = mtlStream;
options.VectorRasterizationOptions = new CadRasterizationOptions { DrawType = CadDrawTypeMode.UseObjectColor };
image.Save(stream, options);
}