导出OBJ时支持MTL文件
Contents
[
Hide
]如何在导出OBJ时支持MTL文件
问题: 如何在导出OBJ时支持MTL文件。
提示: 要做到这一点,您可以在导出到OBJ格式时使用材质文件。以下是一个示例。附带了结果文件(ColorImage.obj和ColorImage.mtl)和源文件(ColorImage.dwf)。
示例:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |