我正在嘗試構建一個房間編輯器。所以用戶已經放置了家具,旋轉它們等。所有物件都保存為 Room 父級的子級。我需要對功能進行編程,現在將房間及其子項保存為 FBX 或 OBJ,以便可以通過任何 3D 查看軟體發送和查看它,甚至可以在攪拌機之類的東西中打開它(紋理還不是問題)
我嘗試使用 Streamwriter,但似乎無法做到。我看過https://docs.unity3d.com/ScriptReference/PrefabUtility.html但這不會匯出預制件,而是將它們存盤在專案檔案中。
有沒有人對我可以用來解決這個問題有任何想法或建議
uj5u.com熱心網友回復:
該FBX SDK系結可以允許游戲在運行時匯入和匯出程序中被執行。
注意:默認情況下,FBX SDK 系結僅為編輯器,不會包含在構建中。為了將包包含在構建中,將 FBXSDK_RUNTIME 定義添加到 Edit > Project Settings... > Player > Other Settings > Scripting Define Symbols。
using UnityEngine;
using UnityEngine.UI;
using Autodesk.Fbx;
using System.IO;
public class WriteFBXonEvent : MonoBehaviour
{
//Make sure to attach these Buttons in the Inspector
public Button m_HitMeButton;
void Start()
{
Button btn = m_HitMeButton.GetComponent<Button>();
btn.onClick.AddListener(TaskOnClick);
}
void TaskOnClick()
{
// Build the fbx scene file path
// (player/player_data/emptySceneFromRuntime.fbx)
string fbxFilePath = Application.dataPath;
fbxFilePath = Path.Combine(fbxFilePath, "emptySceneFromRuntime.fbx");
fbxFilePath = Path.GetFullPath(fbxFilePath);
Debug.Log(string.Format("The file that will be written is {0}", fbxFilePath));
using (var fbxManager = FbxManager.Create())
{
FbxIOSettings fbxIOSettings = FbxIOSettings.Create(fbxManager, Globals.IOSROOT);
// Configure the IO settings.
fbxManager.SetIOSettings(fbxIOSettings);
// Create the exporter
var fbxExporter = FbxExporter.Create(fbxManager, "Exporter");
// Initialize the exporter.
int fileFormat = fbxManager.GetIOPluginRegistry().FindWriterIDByDescription("FBX ascii (*.fbx)");
bool status = fbxExporter.Initialize(fbxFilePath, fileFormat, fbxIOSettings);
// Check that initialization of the fbxExporter was successful
if (!status)
{
Debug.LogError(string.Format("failed to initialize exporter, reason: {0}",
fbxExporter.GetStatus().GetErrorString()));
return;
}
// Create a scene
var fbxScene = FbxScene.Create(fbxManager, "Scene");
// create scene info
FbxDocumentInfo fbxSceneInfo = FbxDocumentInfo.Create(fbxManager, "SceneInfo");
// set some scene info values
fbxSceneInfo.mTitle = "fromRuntime";
fbxSceneInfo.mSubject = "Exported from a Unity runtime";
fbxSceneInfo.mAuthor = "Unity Technologies";
fbxSceneInfo.mRevision = "1.0";
fbxSceneInfo.mKeywords = "export runtime";
fbxSceneInfo.mComment = "This is to demonstrate the capability of exporting from a Unity runtime, using the FBX SDK C# bindings";
fbxScene.SetSceneInfo(fbxSceneInfo);
// Export the scene to the file.
status = fbxExporter.Export(fbxScene);
// cleanup
fbxScene.Destroy();
fbxExporter.Destroy();
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/369351.html
上一篇:我怎樣才能只用一根手指轉向輸入
