diff --git a/Editor/Scripts/GLTFImporter.cs b/Editor/Scripts/GLTFImporter.cs index c2f9bafd1..6076371ea 100644 --- a/Editor/Scripts/GLTFImporter.cs +++ b/Editor/Scripts/GLTFImporter.cs @@ -256,7 +256,7 @@ public override void OnImportAsset(AssetImportContext ctx) JsonUtility.FromJsonOverwrite(importPlugin.jsonSettings, existing); } } - var context = new GLTFImportContext(ctx, settings); + var context = new GLTFImportContext(ctx, settings) { ImportScaleFactor = _scaleFactor }; GameObject gltfScene = null; AnimationClip[] animations = null; @@ -840,7 +840,6 @@ private static void UpdateColorSpace() loader.LoadUnreferencedImagesAndMaterials = true; loader.MaximumLod = _maximumLod; loader.IsMultithreaded = true; - loader._importScaleFactor = _scaleFactor; // Need to call with RunSync, otherwise the draco loader will freeze the editor AsyncHelpers.RunSync(() => loader.LoadSceneAsync()); diff --git a/Runtime/Scripts/GLTFSceneImporter.cs b/Runtime/Scripts/GLTFSceneImporter.cs index 4756cd406..022754896 100644 --- a/Runtime/Scripts/GLTFSceneImporter.cs +++ b/Runtime/Scripts/GLTFSceneImporter.cs @@ -136,14 +136,6 @@ public struct ImportStatistics public partial class GLTFSceneImporter : IDisposable { - // public static event Action BeforeImport; - // public static event Action BeforeImportScene; - // public static event Action AfterImportedScene; - // public static event Action AfterImportedNode; - // public static event Action AfterImportedMaterial; - // public static event Action AfterImportedTexture; - // public static event Action AfterImported; - public enum ColliderType { None, @@ -274,10 +266,6 @@ public GameObject LastLoadedScene protected GLTFRoot _gltfRoot; protected AssetCache _assetCache; protected bool _isRunning = false; - -#if UNITY_EDITOR - internal float _importScaleFactor = 1f; -#endif protected ImportProgress progressStatus = default(ImportProgress); protected IProgress progress = null; diff --git a/Runtime/Scripts/Plugins/Core/ImportContext.cs b/Runtime/Scripts/Plugins/Core/ImportContext.cs index 7907b5c7b..a778fe8af 100644 --- a/Runtime/Scripts/Plugins/Core/ImportContext.cs +++ b/Runtime/Scripts/Plugins/Core/ImportContext.cs @@ -14,6 +14,7 @@ public class GLTFImportContext public readonly AssetImportContext AssetContext; public string FilePath => AssetContext.assetPath; public readonly AssetImporter SourceImporter; + public float ImportScaleFactor = 1.0f; #endif public readonly List Plugins; diff --git a/Runtime/Scripts/SceneImporter/ImporterAnimation.cs b/Runtime/Scripts/SceneImporter/ImporterAnimation.cs index f33e66a48..056bb5850 100644 --- a/Runtime/Scripts/SceneImporter/ImporterAnimation.cs +++ b/Runtime/Scripts/SceneImporter/ImporterAnimation.cs @@ -288,14 +288,18 @@ protected async Task ConstructClip(Transform root, int animationI { case GLTFAnimationChannelPath.translation: propertyNames = new string[] { "localPosition.x", "localPosition.y", "localPosition.z" }; - +#if UNITY_EDITOR + // TODO technically this should be postprocessing in the ScriptedImporter instead, + // but performance is much better if we do it when constructing the clips + var factor = Context?.ImportScaleFactor ?? 1f; +#endif SetAnimationCurve(clip, relativePath, propertyNames, input, output, samplerCache.Interpolation, typeof(Transform), (data, frame) => { var position = data.AsVec3s[frame].ToUnityVector3Convert(); #if UNITY_EDITOR - return new float[] { position.x * _importScaleFactor, position.y * _importScaleFactor, position.z * _importScaleFactor}; + return new float[] { position.x * factor, position.y * factor, position.z * factor}; #else return new float[] { position.x, position.y, position.z }; #endif