Skip to content

Commit

Permalink
move import scale factor into the import context
Browse files Browse the repository at this point in the history
  • Loading branch information
hybridherbst committed Jan 3, 2024
1 parent abc8762 commit 71bc548
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
3 changes: 1 addition & 2 deletions Editor/Scripts/GLTFImporter.cs
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
12 changes: 0 additions & 12 deletions Runtime/Scripts/GLTFSceneImporter.cs
Expand Up @@ -136,14 +136,6 @@ public struct ImportStatistics

public partial class GLTFSceneImporter : IDisposable
{
// public static event Action<GLTFSceneImporter, GLTFRoot> BeforeImport;
// public static event Action<GLTFSceneImporter, GLTFScene> BeforeImportScene;
// public static event Action<GLTFSceneImporter, GLTFScene, int, GameObject> AfterImportedScene;
// public static event Action<GLTFSceneImporter, Node, int, GameObject> AfterImportedNode;
// public static event Action<GLTFSceneImporter, GLTFMaterial, int, Material> AfterImportedMaterial;
// public static event Action<GLTFSceneImporter, GLTFTexture, int, Texture> AfterImportedTexture;
// public static event Action<GLTFSceneImporter, GLTFRoot, GameObject> AfterImported;

public enum ColliderType
{
None,
Expand Down Expand Up @@ -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<ImportProgress> progress = null;
Expand Down
1 change: 1 addition & 0 deletions Runtime/Scripts/Plugins/Core/ImportContext.cs
Expand Up @@ -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<GLTFImportPluginContext> Plugins;
Expand Down
8 changes: 6 additions & 2 deletions Runtime/Scripts/SceneImporter/ImporterAnimation.cs
Expand Up @@ -288,14 +288,18 @@ protected async Task<AnimationClip> 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
Expand Down

0 comments on commit 71bc548

Please sign in to comment.