-1
我正在尋找一種在運行時將網格導出爲stl/obj/fbx格式並將其保存在Android手機的本地文件中的方法。在運行時將網格轉換爲stl/obj/fbx
我該怎麼做?如果存在,我願意使用插件(免費/付費)。
我正在尋找一種在運行時將網格導出爲stl/obj/fbx格式並將其保存在Android手機的本地文件中的方法。在運行時將網格轉換爲stl/obj/fbx
我該怎麼做?如果存在,我願意使用插件(免費/付費)。
這真的很複雜,因爲您必須閱讀每種格式(stl/obj/fbx)的規範並理解它們以便自己創建一個。幸運的是,已經有很多插件可以用來將Unity網格導出爲stl,obj和fbx。
FBX:
UnityFBXExporter用於導出團結網在運行時爲FBX。
public GameObject objMeshToExport;
void Start()
{
string path = Path.Combine(Application.persistentDataPath, "data");
path = Path.Combine(path, "carmodel"+ ".fbx");
//Create Directory if it does not exist
if (!Directory.Exists(Path.GetDirectoryName(path)))
{
Directory.CreateDirectory(Path.GetDirectoryName(path));
}
FBXExporter.ExportGameObjToFBX(objMeshToExport, path, true, true);
}
OBJ:
對於物鏡,使用ObjExporter
。
public GameObject objMeshToExport;
void Start()
{
string path = Path.Combine(Application.persistentDataPath, "data");
path = Path.Combine(path, "carmodel" + ".obj");
//Create Directory if it does not exist
if (!Directory.Exists(Path.GetDirectoryName(path)))
{
Directory.CreateDirectory(Path.GetDirectoryName(path));
}
MeshFilter meshFilter = objMeshToExport.GetComponent<MeshFilter>();
ObjExporter.MeshToFile(meshFilter, path);
}
STL:
可以使用pb_Stl插件STL格式。
public GameObject objMeshToExport;
void Start()
{
string path = Path.Combine(Application.persistentDataPath, "data");
path = Path.Combine(path, "carmodel" + ".stl");
Mesh mesh = objMeshToExport.GetComponent<MeshFilter>().mesh;
//Create Directory if it does not exist
if (!Directory.Exists(Path.GetDirectoryName(path)))
{
Directory.CreateDirectory(Path.GetDirectoryName(path));
}
pb_Stl.WriteFile(path, mesh, FileType.Ascii);
//OR
pb_Stl_Exporter.Export(path, new GameObject[] { objMeshToExport }, FileType.Ascii);
}
感謝您的建議。我從來沒有想過在Github上找到插件......我今天晚些時候會嘗試所有這些插件。 –
我想開發一個Android應用程序(用於學校項目),它允許用戶設計自己的手機外殼,然後生成STL/OBJ格式的3D幾何文件,這可以用於3D打印。 (對不起,我沒有弄清楚這個問題。) 這就是我需要一個插件在Android應用程序運行時將gameobjects/mesh導出爲stl/obj/fbx文件的主要原因。 我在void Start()中嘗試了pb_Stl和UnityFBXExporter(您建議的代碼)。但是,當我打開我的應用程序,然後打開內部存儲。我發現沒有創建任何東西。 –
我想知道這些導出代碼可以在其他函數中實現,而不是void Start()。因爲我想要實現的是僅在單擊特定按鈕而不是應用程序的開始時才生成stl文件。 –