Skip to content

Commit

Permalink
Merge pull request #1086 from ousttrue/feature10/zip_extract
Browse files Browse the repository at this point in the history
Feature10/zip extract
  • Loading branch information
PoChang007 authored Jul 1, 2021
2 parents d90520f + fc774d2 commit ed51975
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using UnityEngine;
using UnityEditor;
#if UNITY_2020_2_OR_NEWER
using UnityEditor.AssetImporters;
#else
Expand All @@ -10,14 +8,11 @@
namespace UniGLTF
{
[ScriptedImporter(1, "glb")]
public class GlbScriptedImporter : ScriptedImporter
public class GlbScriptedImporter : GltfScriptedImporterBase
{
[SerializeField]
public ScriptedImporterAxes m_reverseAxis;

public override void OnImportAsset(AssetImportContext ctx)
{
ScriptedImporterImpl.Import(this, ctx, m_reverseAxis.ToAxes());
Import(this, ctx, m_reverseAxis.ToAxes());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace UniGLTF
{
[CustomEditor(typeof(GlbScriptedImporter))]
public class GlbScriptedImporterEditorGUI : RemapScriptedImporterEditorBase
public class GlbScriptedImporterEditor : RemapScriptedImporterEditorBase
{
GlbScriptedImporter m_importer;
GltfData m_data;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using UnityEngine;
using UnityEditor;
#if UNITY_2020_2_OR_NEWER
using UnityEditor.AssetImporters;
#else
Expand All @@ -10,14 +8,11 @@
namespace UniGLTF
{
[ScriptedImporter(1, "gltf")]
public class GltfScriptedImporter : ScriptedImporter
public class GltfScriptedImporter : GltfScriptedImporterBase
{
[SerializeField]
public ScriptedImporterAxes m_reverseAxis = default;

public override void OnImportAsset(AssetImportContext ctx)
{
ScriptedImporterImpl.Import(this, ctx, m_reverseAxis.ToAxes());
Import(this, ctx, m_reverseAxis.ToAxes());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Linq;
using UnityEngine;
using UnityEditor;
using System.Linq;
using VRMShaders;
#if UNITY_2020_2_OR_NEWER
using UnityEditor.AssetImporters;
Expand All @@ -10,15 +11,21 @@

namespace UniGLTF
{
public static class ScriptedImporterImpl
/// <summary>
/// ScriptedImporterImpl から改め
/// </summary>
public abstract class GltfScriptedImporterBase : ScriptedImporter
{
[SerializeField]
public ScriptedImporterAxes m_reverseAxis = default;

/// <summary>
/// glb をパースして、UnityObject化、さらにAsset化する
/// </summary>
/// <param name="scriptedImporter"></param>
/// <param name="context"></param>
/// <param name="reverseAxis"></param>
public static void Import(ScriptedImporter scriptedImporter, AssetImportContext context, Axes reverseAxis)
protected static void Import(ScriptedImporter scriptedImporter, AssetImportContext context, Axes reverseAxis)
{
#if VRM_DEVELOP
Debug.Log("OnImportAsset to " + scriptedImporter.assetPath);
Expand All @@ -28,7 +35,7 @@ public static void Import(ScriptedImporter scriptedImporter, AssetImportContext
// Parse(parse glb, parser gltf json)
//
var data = new AmbiguousGltfFileParser(scriptedImporter.assetPath).Parse();


//
// Import(create unity objects)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace UniGLTF
{
[CustomEditor(typeof(GltfScriptedImporter))]
public class GltfScriptedImporterEditorGUI : RemapScriptedImporterEditorBase
public class GltfScriptedImporterEditor : RemapScriptedImporterEditorBase
{
GltfScriptedImporter m_importer;
GltfData m_data;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void ExtractMaterialsAndTextures(ScriptedImporter self, GltfData data, ITextureD
.ToDictionary(kv => kv.Item1, kv => kv.Item2)
;

var assetPath = UnityPath.FromFullpath(self.assetPath);
var assetPath = UnityPath.FromUnityPath(self.assetPath);
var dirName = textureDir(assetPath.Value); // $"{assetPath.FileNameWithoutExtension}.Textures";
TextureExtractor.ExtractTextures(
data,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using UnityEngine;
using UnityEditor;
#if UNITY_2020_2_OR_NEWER
using UnityEditor.AssetImporters;
#else
Expand All @@ -12,14 +10,11 @@ namespace UniGLTF
#if UNIGLTF_ENABLE_ZIPARCHVIE_IMPORTER
[ScriptedImporter(1, "zip")]
#endif
public class ZipArchivedGltfScriptedImporter : ScriptedImporter
public class ZipArchivedGltfScriptedImporter : GltfScriptedImporterBase
{
[SerializeField]
public ScriptedImporterAxes m_reverseAxis = default;

public override void OnImportAsset(AssetImportContext ctx)
{
ScriptedImporterImpl.Import(this, ctx, m_reverseAxis.ToAxes());
Import(this, ctx, m_reverseAxis.ToAxes());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using UnityEditor;
using UnityEngine;
using System.IO;
using System.Linq;
#if UNITY_2020_2_OR_NEWER
using UnityEditor.AssetImporters;
#else
using UnityEditor.Experimental.AssetImporters;
#endif


namespace UniGLTF
{
[CustomEditor(typeof(ZipArchivedGltfScriptedImporter))]
public class ZipArchivedGltfScriptedImporterEditor : RemapScriptedImporterEditorBase
{
ZipArchivedGltfScriptedImporter m_importer;
GltfData m_data;

RemapEditorMaterial m_materialEditor;
RemapEditorAnimation m_animationEditor;

public override void OnEnable()
{
base.OnEnable();

m_importer = target as ZipArchivedGltfScriptedImporter;
m_data = new AmbiguousGltfFileParser(m_importer.assetPath).Parse();

var materialGenerator = new GltfMaterialDescriptorGenerator();
var materialKeys = m_data.GLTF.materials.Select((_, i) => materialGenerator.Get(m_data, i).SubAssetKey);
var textureKeys = new GltfTextureDescriptorGenerator(m_data).Get().GetEnumerable().Select(x => x.SubAssetKey);
m_materialEditor = new RemapEditorMaterial(materialKeys.Concat(textureKeys), GetEditorMap, SetEditorMap);
m_animationEditor = new RemapEditorAnimation(AnimationImporterUtil.EnumerateSubAssetKeys(m_data.GLTF), GetEditorMap, SetEditorMap);
}

enum Tabs
{
Model,
Animation,
Materials,
}
static Tabs s_currentTab;

public override void OnInspectorGUI()
{
s_currentTab = MeshUtility.TabBar.OnGUI(s_currentTab);
GUILayout.Space(10);

switch (s_currentTab)
{
case Tabs.Model:
base.OnInspectorGUI();
break;

case Tabs.Animation:
m_animationEditor.OnGUI(m_importer, m_data);
RevertApplyRemapGUI(m_importer);
break;

case Tabs.Materials:
m_materialEditor.OnGUI(m_importer, m_data,
new GltfTextureDescriptorGenerator(m_data),
assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Textures",
assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Materials");
RevertApplyRemapGUI(m_importer);
break;
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ed51975

Please sign in to comment.