From 50ae0be479a3dfc9aae43b694da45e46cbff2396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B7=A6=E5=8F=B3=E7=9C=8B?= <1918891542@qq.com> Date: Tue, 27 Jun 2023 20:53:11 +0800 Subject: [PATCH] Exporting models support --- Assets/Scenes/Version2.unity | 6 +-- Assets/Scripts/Exporter/ModelExporter.cs | 39 +++++++++++++++++++ Assets/Scripts/Exporter/ModelExporter.cs.meta | 11 ++++++ Assets/Scripts/Exporter/TextureExporter.cs | 2 +- Assets/Scripts/UmaViewerUI.cs | 4 +- Assets/Scripts/umamusume.asmdef | 3 +- 6 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 Assets/Scripts/Exporter/ModelExporter.cs create mode 100644 Assets/Scripts/Exporter/ModelExporter.cs.meta diff --git a/Assets/Scenes/Version2.unity b/Assets/Scenes/Version2.unity index 67861ca..43145a1 100644 --- a/Assets/Scenes/Version2.unity +++ b/Assets/Scenes/Version2.unity @@ -7301,7 +7301,7 @@ GameObject: - component: {fileID: 305581831} - component: {fileID: 305581830} m_Layer: 5 - m_Name: ExportTextures + m_Name: ExportModel m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -7373,7 +7373,7 @@ MonoBehaviour: m_Calls: - m_Target: {fileID: 1564959567} m_TargetAssemblyTypeName: UmaViewerUI, umamusume - m_MethodName: ExportTextures + m_MethodName: ExportModel m_Mode: 1 m_Arguments: m_ObjectArgument: {fileID: 0} @@ -13708,7 +13708,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_text: Export Textures + m_text: Export Model m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} diff --git a/Assets/Scripts/Exporter/ModelExporter.cs b/Assets/Scripts/Exporter/ModelExporter.cs new file mode 100644 index 0000000..fb9eac7 --- /dev/null +++ b/Assets/Scripts/Exporter/ModelExporter.cs @@ -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); + } +} diff --git a/Assets/Scripts/Exporter/ModelExporter.cs.meta b/Assets/Scripts/Exporter/ModelExporter.cs.meta new file mode 100644 index 0000000..2573d86 --- /dev/null +++ b/Assets/Scripts/Exporter/ModelExporter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bf3b5b616874ba1479b187dd881b2ebb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Exporter/TextureExporter.cs b/Assets/Scripts/Exporter/TextureExporter.cs index b595d42..40a9ed2 100644 --- a/Assets/Scripts/Exporter/TextureExporter.cs +++ b/Assets/Scripts/Exporter/TextureExporter.cs @@ -31,7 +31,7 @@ public class TextureExporter { string m_Path = Application.dataPath; - string savePath = m_Path + "/../Texture2D/" + gameobj.name + "/"; + string savePath = m_Path + "/../Exported/" + gameobj.name + "/Texture2D/"; if (!Directory.Exists(savePath)) { diff --git a/Assets/Scripts/UmaViewerUI.cs b/Assets/Scripts/UmaViewerUI.cs index f73b762..2bd8c49 100644 --- a/Assets/Scripts/UmaViewerUI.cs +++ b/Assets/Scripts/UmaViewerUI.cs @@ -1310,10 +1310,12 @@ public class UmaViewerUI : MonoBehaviour MessageScrollRect.verticalNormalizedPosition = 0; } - public void ExportTextures() + public void ExportModel() { if (Builder.CurrentUMAContainer) { + //TextureExporter.exportAllTexture(Builder.CurrentUMAContainer.gameObject); + ModelExporter.exportModel(Builder.CurrentUMAContainer.gameObject); TextureExporter.exportAllTexture(Builder.CurrentUMAContainer.gameObject); } } diff --git a/Assets/Scripts/umamusume.asmdef b/Assets/Scripts/umamusume.asmdef index 4ee991a..f0df044 100644 --- a/Assets/Scripts/umamusume.asmdef +++ b/Assets/Scripts/umamusume.asmdef @@ -6,7 +6,8 @@ "GUID:800597811bcc5d848b15e12807d6de45", "GUID:d60799ab2a985554ea1a39cd38695018", "GUID:fd1d627189c561043911a07470238b9c", - "GUID:145e2572884581c48a08acf566c1a1d6" + "GUID:145e2572884581c48a08acf566c1a1d6", + "GUID:18d18f811ba286c49814567a3cfba688" ], "includePlatforms": [], "excludePlatforms": [],