From 38316c48b52672e5900739cbac3be7b6dd359bce Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 23 Jul 2018 11:34:55 +0900 Subject: [PATCH] Move export menu --- Core/Scripts/IO/gltfExporter.cs | 10 ++++- README.md | 75 +++++++++++++++++---------------- 2 files changed, 46 insertions(+), 39 deletions(-) diff --git a/Core/Scripts/IO/gltfExporter.cs b/Core/Scripts/IO/gltfExporter.cs index db608ec..ba58cc2 100644 --- a/Core/Scripts/IO/gltfExporter.cs +++ b/Core/Scripts/IO/gltfExporter.cs @@ -12,7 +12,7 @@ namespace UniGLTF { public class gltfExporter : IDisposable { - const string CONVERT_HUMANOID_KEY = "GameObject/gltf/export"; + const string CONVERT_HUMANOID_KEY = UniGLTFVersion.UNIGLTF_VERSION + "/Export"; #if UNITY_EDITOR [MenuItem(CONVERT_HUMANOID_KEY, true, 1)] @@ -43,6 +43,12 @@ private static void ExportFromMenu() } var bytes = gltf.ToGlbBytes(); File.WriteAllBytes(path, bytes); + + if (path.StartsWithUnityAssetPath()) + { + AssetDatabase.ImportAsset(path.ToUnityRelativePath()); + AssetDatabase.Refresh(); + } } #endif @@ -622,7 +628,7 @@ public static Exported FromGameObject(glTF gltf, GameObject go, bool useSparseAc if (go.transform.childCount == 0) { - throw new UniGLTFException("root node required"); + throw new UniGLTFException("empty root GameObject required"); } var unityNodes = go.transform.Traverse() diff --git a/README.md b/README.md index dafce40..ed5d23e 100644 --- a/README.md +++ b/README.md @@ -9,66 +9,67 @@ ![duck_prefab](doc/duck_prefab.png) ![animation](doc/animation.gif) -* [Samples](https://github.com/ousttrue/UniGLTF_Test) +* [Sample and Tests](https://github.com/ousttrue/UniGLTF_Test) +* [Humanoid Helper](https://github.com/ousttrue/UniHumanoid) +* [Json backend](https://github.com/ousttrue/UniJson) -## License +# License * [MIT license](LICENSE) -## Download +# Sample Models -* https://github.com/ousttrue/UniGLTF/releases - -## Install - -* import [unitypackage](https://github.com/ousttrue/UniGLTF/releases) - -## Usage - -* drop gltf folder or glb file into Assets folder - -or +* https://github.com/KhronosGroup/glTF-Sample-Models -* menu [Assets] - [gltf] - [import] +Exclude SciFiHelmet(70074vertices), all model can import. -## Importer +[Mesh.IndexFormat(from 2017.3)](https://docs.unity3d.com/ScriptReference/Mesh-indexFormat.html) allows a huge mesh, Otherwise mesh division required. -* [x] asset(ScriptedImporter) (Unity-2017 or new) -* [x] asset(AssetPostprocessor.OnPostprocessAllAssets) (Unity-5.6) +![SciFiHelmet](doc/SciFiHelmet.png) -* runtime [Assets] - [gltf] - [import] +# Download -### Sample Models +* https://github.com/ousttrue/UniGLTF/releases -* https://github.com/KhronosGroup/glTF-Sample-Models +## Install -Exclude SciFiHelmet(70074vertices), all model can import. +* import [unitypackage](https://github.com/ousttrue/UniGLTF/releases) -[Mesh.IndexFormat(from 2017.3)](https://docs.unity3d.com/ScriptReference/Mesh-indexFormat.html) allows a huge mesh, Otherwise mesh division required. +# Usage -![SciFiHelmet](doc/SciFiHelmet.png) +## Import as asset -### Can load gltf in zip archive +* drop gltf folder or glb file into Assets folder -* https://github.com/ousttrue/UniGLTF_Test/blob/master/Assets/UniGLTF.Samples/LoaderFromHttp/LoadFromHttp.cs +or -## Exporter +* menu [UniGLTF] - [Import] (select out of Asset folder gltf file(gltf, glb, zip) and (save into Asset folder) -* asset([right click] - [gltf] - [export] -* runtime -* [validation](http://github.khronos.org/glTF-Validator/) +## Import in runTime -## Experimental ScriptedImporter for Unity2017 +```cs +var path; // gltf, glb or zip(include gltf) -[ScriptedImporter](https://docs.unity3d.com/ScriptReference/Experimental.AssetImporters.ScriptedImporter.html) +var context = gltfImporter.Load(path); +context.ShowMeshes(); -* Unity2017.3.0f3 +GameObject root = context.Root; +``` -![duck_assets](doc/duck_assets.png) +## Export from scene -ScriptedImporter removed. +* menu [UniGLTF] - [Export] -## Humanoid Helper +## Import in runTime -* move to [UniHumanoid](https://github.com/ousttrue/UniHumanoid) +```cs +var gltf = new glTF(); +using (var exporter = new gltfExporter(gltf)) +{ + exporter.Prepare(go); + exporter.Export(); +} +var bytes = gltf.ToGlbBytes(); +File.WriteAllBytes(path, bytes); +```