Exporting models support

This commit is contained in:
左右看
2023-06-27 20:53:11 +08:00
parent ce6ae8f45c
commit 50ae0be479
6 changed files with 59 additions and 6 deletions
+39
View File
@@ -0,0 +1,39 @@
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using UnityEngine;
using UnityGLTF;
public class ModelExporter
{
public static string RetrieveTexturePath(UnityEngine.Texture texture)
{
string m_Path = Application.dataPath;
var path = m_Path + "/../unknown/" + texture.name; ;
return path;
}
public static void Export(Transform[] transforms, string sceneName)
{
var exportOptions = new UnityGLTF.ExportOptions { TexturePathRetriever = RetrieveTexturePath };
var exporter = new GLTFSceneExporter(transforms, exportOptions);
string m_Path = Application.dataPath;
string path = m_Path + "/../Exported/" + sceneName;
var resultFile = GLTFSceneExporter.GetFileName(path, sceneName, ".gltf");
exporter.SaveGLTFandBin(path, sceneName);
}
public static void exportModel(GameObject gameobj)
{
string sceneName = gameobj.name;
Transform[] rootTransforms = new Transform[] { gameobj.transform };
Export(rootTransforms, sceneName);
}
}