mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-04-24 23:18:04 -05:00
Merge pull request #958 from ousttrue/fix/scripted_importer_acxes
Fix/scripted importer axes
This commit is contained in:
commit
0ca5f97639
|
|
@ -8,7 +8,7 @@ namespace UniGLTF
|
|||
{
|
||||
public GameObject Root { get; set; }
|
||||
|
||||
public Axises InverseAxis;
|
||||
public Axes InverseAxis;
|
||||
|
||||
[Header("MorphTarget(BlendShape)")]
|
||||
public bool Sparse;
|
||||
|
|
|
|||
|
|
@ -13,17 +13,11 @@ namespace UniGLTF
|
|||
public class GlbScriptedImporter : ScriptedImporter
|
||||
{
|
||||
[SerializeField]
|
||||
Axises m_reverseAxis;
|
||||
public ScriptedImporterAxes m_reverseAxis;
|
||||
|
||||
public override void OnImportAsset(AssetImportContext ctx)
|
||||
{
|
||||
var asset = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(ctx.assetPath);
|
||||
if (asset == null)
|
||||
{
|
||||
// first time. set default setting
|
||||
m_reverseAxis = UniGLTFPreference.GltfIOAxis;
|
||||
}
|
||||
ScriptedImporterImpl.Import(this, ctx, m_reverseAxis);
|
||||
ScriptedImporterImpl.Import(this, ctx, m_reverseAxis.ToAxes());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,17 +13,11 @@ namespace UniGLTF
|
|||
public class GltfScriptedImporter : ScriptedImporter
|
||||
{
|
||||
[SerializeField]
|
||||
Axises m_reverseAxis = default;
|
||||
public ScriptedImporterAxes m_reverseAxis = default;
|
||||
|
||||
public override void OnImportAsset(AssetImportContext ctx)
|
||||
{
|
||||
var asset = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(ctx.assetPath);
|
||||
if (asset == null)
|
||||
{
|
||||
// first time. set default setting
|
||||
m_reverseAxis = UniGLTFPreference.GltfIOAxis;
|
||||
}
|
||||
ScriptedImporterImpl.Import(this, ctx, m_reverseAxis);
|
||||
ScriptedImporterImpl.Import(this, ctx, m_reverseAxis.ToAxes());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
namespace UniGLTF
|
||||
{
|
||||
/// <summary>
|
||||
/// ScriptedImporter の Inspector 用の Axes 設定
|
||||
/// </summary>
|
||||
public enum ScriptedImporterAxes
|
||||
{
|
||||
Default,
|
||||
Z,
|
||||
X,
|
||||
}
|
||||
|
||||
public static class ScriptedImporterAxesExtensions
|
||||
{
|
||||
public static Axes ToAxes(this ScriptedImporterAxes axis)
|
||||
{
|
||||
switch (axis)
|
||||
{
|
||||
case ScriptedImporterAxes.Z: return Axes.Z;
|
||||
case ScriptedImporterAxes.X: return Axes.X;
|
||||
case ScriptedImporterAxes.Default:
|
||||
{
|
||||
return UniGLTFPreference.GltfIOAxis;
|
||||
}
|
||||
|
||||
default: throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5b3b7b9629a4da242bacf52f5ca0fd80
|
||||
guid: 6f9b903cff6f27c4dbee54a9b8e8d1af
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
|
@ -20,7 +20,7 @@ namespace UniGLTF
|
|||
/// <param name="scriptedImporter"></param>
|
||||
/// <param name="context"></param>
|
||||
/// <param name="reverseAxis"></param>
|
||||
public static void Import(ScriptedImporter scriptedImporter, AssetImportContext context, Axises reverseAxis)
|
||||
public static void Import(ScriptedImporter scriptedImporter, AssetImportContext context, Axes reverseAxis)
|
||||
{
|
||||
#if VRM_DEVELOP
|
||||
Debug.Log("OnImportAsset to " + scriptedImporter.assetPath);
|
||||
|
|
|
|||
|
|
@ -2,32 +2,65 @@ using UnityEngine;
|
|||
using UnityEditor;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
public static class UniGLTFPreference
|
||||
{
|
||||
static IEnumerable<string> GetReimportPaths()
|
||||
{
|
||||
String[] guids = AssetDatabase.FindAssets("t:GameObject", null);
|
||||
foreach (var guid in guids)
|
||||
{
|
||||
var assetPath = AssetDatabase.GUIDToAssetPath(guid);
|
||||
if (AssetImporter.GetAtPath(assetPath) is GlbScriptedImporter glb)
|
||||
{
|
||||
if (glb.m_reverseAxis == ScriptedImporterAxes.Default)
|
||||
{
|
||||
Debug.Log($"[reimport] {assetPath}");
|
||||
yield return assetPath;
|
||||
}
|
||||
}
|
||||
else if (AssetImporter.GetAtPath(assetPath) is GltfScriptedImporter gltf)
|
||||
{
|
||||
if (gltf.m_reverseAxis == ScriptedImporterAxes.Default)
|
||||
{
|
||||
Debug.Log($"[reimport] {assetPath}");
|
||||
yield return assetPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[PreferenceItem("UniGLTF")]
|
||||
private static void OnPreferenceGUI()
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
// language
|
||||
M17N.LanguageGetter.OnGuiSelectLang();
|
||||
EditorGUILayout.HelpBox($"Custom editor language setting", MessageType.Info, true);
|
||||
|
||||
// default axis
|
||||
GltfIOAxis = (Axises)EditorGUILayout.EnumPopup("Default Invert axis", GltfIOAxis);
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var gltfIOAxis = (Axes)EditorGUILayout.EnumPopup("Default Invert axis", GltfIOAxis);
|
||||
EditorGUILayout.HelpBox($"Default invert axis when glb/gltf import/export", MessageType.Info, true);
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
// global setting
|
||||
GltfIOAxis = gltfIOAxis;
|
||||
|
||||
// apply assets
|
||||
foreach (var path in GetReimportPaths().ToArray())
|
||||
{
|
||||
AssetDatabase.ImportAsset(path, default);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const string AXIS_KEY = "UNIGLTF_IO_AXIS";
|
||||
static Axises? s_axis;
|
||||
public static Axises GltfIOAxis
|
||||
static Axes? s_axis;
|
||||
public static Axes GltfIOAxis
|
||||
{
|
||||
set
|
||||
{
|
||||
|
|
@ -38,18 +71,62 @@ namespace UniGLTF
|
|||
{
|
||||
if (!s_axis.HasValue)
|
||||
{
|
||||
var value = EditorPrefs.GetString(AXIS_KEY, default(Axises).ToString());
|
||||
if (Enum.TryParse<Axises>(value, out Axises parsed))
|
||||
var value = EditorPrefs.GetString(AXIS_KEY, default(Axes).ToString());
|
||||
if (Enum.TryParse<Axes>(value, out Axes parsed))
|
||||
{
|
||||
s_axis = parsed;
|
||||
}
|
||||
else
|
||||
{
|
||||
s_axis = default(Axises);
|
||||
s_axis = default(Axes);
|
||||
}
|
||||
}
|
||||
return s_axis.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool HasSymbol(string symbol)
|
||||
{
|
||||
var target = EditorUserBuildSettings.selectedBuildTargetGroup;
|
||||
var current = PlayerSettings.GetScriptingDefineSymbolsForGroup(target).Split(';');
|
||||
return current.Contains(symbol);
|
||||
}
|
||||
|
||||
public static void AddSymbol(string symbol)
|
||||
{
|
||||
var target = EditorUserBuildSettings.selectedBuildTargetGroup;
|
||||
var current = PlayerSettings.GetScriptingDefineSymbolsForGroup(target).Split(';');
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(target,
|
||||
string.Join(";", current.Concat(new[] { symbol }))
|
||||
);
|
||||
}
|
||||
|
||||
public static void RemoveSymbol(string symbol)
|
||||
{
|
||||
var target = EditorUserBuildSettings.selectedBuildTargetGroup;
|
||||
var current = PlayerSettings.GetScriptingDefineSymbolsForGroup(target).Split(';');
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(target,
|
||||
string.Join(";", current.Where(x => x != symbol))
|
||||
);
|
||||
}
|
||||
|
||||
public static void ToggleSymbol(string title, string symbol)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var isStop = HasSymbol(symbol);
|
||||
var newValue = GUILayout.Toggle(isStop, title);
|
||||
EditorGUILayout.HelpBox($"define C# symbol '{symbol}'", MessageType.Info, true);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
if (newValue)
|
||||
{
|
||||
AddSymbol(symbol);
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveSymbol(symbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ using UnityEngine;
|
|||
|
||||
namespace UniGLTF
|
||||
{
|
||||
public enum Axises
|
||||
public enum Axes
|
||||
{
|
||||
Z,
|
||||
X,
|
||||
|
|
@ -65,12 +65,12 @@ namespace UniGLTF
|
|||
|
||||
public static class AxisesExtensions
|
||||
{
|
||||
public static IAxisInverter Create(this Axises axis)
|
||||
public static IAxisInverter Create(this Axes axis)
|
||||
{
|
||||
switch (axis)
|
||||
{
|
||||
case Axises.Z: return new ReverseZ();
|
||||
case Axises.X: return new ReverseX();
|
||||
case Axes.Z: return new ReverseZ();
|
||||
case Axes.X: return new ReverseX();
|
||||
default: throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
11
Assets/UniGLTF/Runtime/UniGLTF/IO/Axes.cs.meta
Normal file
11
Assets/UniGLTF/Runtime/UniGLTF/IO/Axes.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ec65074bc74907c4580348aa0b159411
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -5,6 +5,6 @@ namespace UniGLTF
|
|||
{
|
||||
public interface IAnimationImporter
|
||||
{
|
||||
List<AnimationClip> Import(glTF gltf, GameObject root, List<Transform> nodes, List<AnimationClip> clips, Axises invertAxis);
|
||||
List<AnimationClip> Import(glTF gltf, GameObject root, List<Transform> nodes, List<AnimationClip> clips, Axes invertAxis);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ namespace UniGLTF
|
|||
/// <summary>
|
||||
/// GLTF から Unity に変換するときに反転させる軸
|
||||
/// </summary>
|
||||
public Axises InvertAxis = Axises.Z;
|
||||
public Axes InvertAxis = Axes.Z;
|
||||
|
||||
public static List<string> UnsupportedExtensions = new List<string>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ namespace UniGLTF
|
|||
{
|
||||
public sealed class RootAnimationImporter : IAnimationImporter
|
||||
{
|
||||
public List<AnimationClip> Import(glTF gltf, GameObject root, List<Transform> _nodes, List<AnimationClip> _clips, Axises invertAxis)
|
||||
public List<AnimationClip> Import(glTF gltf, GameObject root, List<Transform> _nodes, List<AnimationClip> _clips, Axes invertAxis)
|
||||
{
|
||||
var animationClips = new List<AnimationClip>();
|
||||
if (gltf.animations != null && gltf.animations.Any())
|
||||
|
|
@ -26,7 +26,7 @@ namespace UniGLTF
|
|||
return animationClips;
|
||||
}
|
||||
|
||||
private IEnumerable<AnimationClip> ImportAnimationClips(glTF gltf, Axises invertAxis)
|
||||
private IEnumerable<AnimationClip> ImportAnimationClips(glTF gltf, Axes invertAxis)
|
||||
{
|
||||
for (var i = 0; i < gltf.animations.Count; ++i)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ namespace UniGLTF
|
|||
|
||||
IAxisInverter m_axisInverter;
|
||||
|
||||
public gltfExporter(glTF gltf, Axises invertAxis = Axises.Z)
|
||||
public gltfExporter(glTF gltf, Axes invertAxis = Axes.Z)
|
||||
{
|
||||
glTF = gltf;
|
||||
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ namespace UniGLTF
|
|||
{
|
||||
DivideVertexBuffer = false
|
||||
};
|
||||
var axisInverter = Axises.X.Create();
|
||||
var axisInverter = Axes.X.Create();
|
||||
|
||||
var (gltfMesh, blendShapeIndexMap) = MeshExporter.ExportMesh(glTF, bufferIndex, new MeshWithRenderer(go.transform), Materials, meshExportSettings, axisInverter);
|
||||
|
||||
|
|
@ -176,7 +176,7 @@ namespace UniGLTF
|
|||
{
|
||||
DivideVertexBuffer = true
|
||||
};
|
||||
var axisInverter = Axises.X.Create();
|
||||
var axisInverter = Axes.X.Create();
|
||||
|
||||
var (gltfMesh, blendShapeIndexMap) = MeshExporter.ExportMesh(glTF, bufferIndex, new MeshWithRenderer(go.transform), Materials, meshExportSettings, axisInverter);
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ using System.Linq;
|
|||
|
||||
namespace VRM
|
||||
{
|
||||
public static class VrmInfo
|
||||
public static class VrmPreference
|
||||
{
|
||||
const string KEY_STOP_VRMASSETPOSTPROCESSOR = "StopVrmAssetPostProcessor";
|
||||
const string ASSETPOSTPROCESSOR_STOP_SYMBOL = "VRM_STOP_ASSETPOSTPROCESSOR";
|
||||
|
|
@ -12,36 +12,7 @@ namespace VRM
|
|||
[PreferenceItem("VRM0")]
|
||||
private static void OnPreferenceGUI()
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
var target = EditorUserBuildSettings.selectedBuildTargetGroup;
|
||||
var current = PlayerSettings.GetScriptingDefineSymbolsForGroup(target).Split(';');
|
||||
|
||||
var stop = current.Any(x => x == ASSETPOSTPROCESSOR_STOP_SYMBOL);
|
||||
var newValue = GUILayout.Toggle(stop, KEY_STOP_VRMASSETPOSTPROCESSOR);
|
||||
EditorGUILayout.HelpBox($"define C# symbol '{ASSETPOSTPROCESSOR_STOP_SYMBOL}'", MessageType.Info, true);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
}
|
||||
|
||||
if (stop != newValue)
|
||||
{
|
||||
stop = newValue;
|
||||
if (stop)
|
||||
{
|
||||
// add symbol
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(target,
|
||||
string.Join(";", current.Concat(new[] { ASSETPOSTPROCESSOR_STOP_SYMBOL }))
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// remove symbol
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(target,
|
||||
string.Join(";", current.Where(x => x != ASSETPOSTPROCESSOR_STOP_SYMBOL))
|
||||
);
|
||||
}
|
||||
}
|
||||
UniGLTF.UniGLTFPreference.ToggleSymbol(KEY_STOP_VRMASSETPOSTPROCESSOR, ASSETPOSTPROCESSOR_STOP_SYMBOL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ namespace VRM
|
|||
|
||||
public readonly VRM.glTF_VRM_extensions VRM = new glTF_VRM_extensions();
|
||||
|
||||
public VRMExporter(glTF gltf) : base(gltf, Axises.Z)
|
||||
public VRMExporter(glTF gltf) : base(gltf, Axes.Z)
|
||||
{
|
||||
gltf.extensionsUsed.Add(glTF_VRM_extensions.ExtensionName);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user