Skip to content

Commit 39fef1b

Browse files
committed
fix nullref with asset info when there's actually no asset info
1 parent 5f94f2b commit 39fef1b

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

Editor/Scripts/GLTFImporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ private void CreateGLTFScene(GLTFImportContext context, out GameObject scene,
969969
scene = loader.LastLoadedScene;
970970
animationClips = loader.CreatedAnimationClips;
971971

972-
_gltfAsset = loader.Root.Asset.ToString(true);
972+
_gltfAsset = loader.Root.Asset?.ToString(true);
973973
importer = loader;
974974
}
975975
}

Runtime/Scripts/GLTFSceneImporter.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ public GameObject LastLoadedScene
203203
get { return _lastLoadedScene; }
204204
}
205205

206+
private bool AnyAnimationTimeNotIncreasing;
207+
206208
public TextureCacheData[] TextureCache => _assetCache.TextureCache;
207209
public Texture2D[] InvalidImageCache => _assetCache.InvalidImageCache;
208210
public MaterialCacheData[] MaterialCache => _assetCache.MaterialCache;
@@ -223,7 +225,7 @@ public GameObject LastLoadedScene
223225
/// Whether to keep a CPU-side copy of the texture after upload to GPU
224226
/// </summary>
225227
/// <remaks>
226-
/// This is is necessary when a texture is used with different sampler states, as Unity doesn't allow setting
228+
/// This is necessary when a texture is used with different sampler states, as Unity doesn't allow setting
227229
/// of filter and wrap modes separately form the texture object. Setting this to false will omit making a copy
228230
/// of a texture in that case and use the original texture's sampler state wherever it's referenced; this is
229231
/// appropriate in cases such as the filter and wrap modes being specified in the shader instead
@@ -1350,6 +1352,11 @@ protected virtual async Task ConstructScene(GLTFScene scene, bool showSceneObj,
13501352
#else
13511353
Debug.Log(LogType.Warning, "glTF scene contains animations but com.unity.modules.animation isn't installed. Install that module to import animations.");
13521354
#endif
1355+
if (AnyAnimationTimeNotIncreasing)
1356+
{
1357+
Debug.Log(LogType.Warning, $"Time of some subsequent animation keyframes is not increasing in {_gltfFileName} (glTF-Validator error ACCESSOR_ANIMATION_INPUT_NON_INCREASING)");
1358+
}
1359+
13531360
CreatedAnimationClips = constructedClips.ToArray();
13541361
}
13551362
}

Runtime/Scripts/SceneImporter/ImporterAnimation.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ private void SetTangentMode(Keyframe[] keyframes, int keyframeIndex, Interpolati
205205
key.outTangent = 0;
206206
break;
207207
case InterpolationType.LINEAR:
208-
key.inTangent = GetCurveKeyframeLeftLinearSlope(keyframes, keyframeIndex);
209-
key.outTangent = GetCurveKeyframeLeftLinearSlope(keyframes, keyframeIndex + 1);
208+
key.inTangent = GetCurveKeyframeLeftLinearSlope(keyframes, keyframeIndex, ref AnyAnimationTimeNotIncreasing);
209+
key.outTangent = GetCurveKeyframeLeftLinearSlope(keyframes, keyframeIndex + 1, ref AnyAnimationTimeNotIncreasing);
210210
break;
211211
case InterpolationType.STEP:
212212
key.inTangent = float.PositiveInfinity;
@@ -218,7 +218,7 @@ private void SetTangentMode(Keyframe[] keyframes, int keyframeIndex, Interpolati
218218
keyframes[keyframeIndex] = key;
219219
}
220220

221-
private static float GetCurveKeyframeLeftLinearSlope(Keyframe[] keyframes, int keyframeIndex)
221+
private static float GetCurveKeyframeLeftLinearSlope(Keyframe[] keyframes, int keyframeIndex, ref bool anyNonCreasing)
222222
{
223223
if (keyframeIndex <= 0 || keyframeIndex >= keyframes.Length)
224224
{
@@ -233,7 +233,7 @@ private static float GetCurveKeyframeLeftLinearSlope(Keyframe[] keyframes, int k
233233
var k = keyframes[keyframeIndex];
234234
k.time = keyframes[keyframeIndex - 1].time + Mathf.Epsilon + 1 / 100f;
235235
keyframes[keyframeIndex] = k;
236-
Debug.Log(LogType.Warning, "Time of subsequent animation keyframes is not increasing (glTF-Validator error ACCESSOR_ANIMATION_INPUT_NON_INCREASING)");
236+
anyNonCreasing = true;
237237
return float.PositiveInfinity;
238238
}
239239
return valueDelta / timeDelta;

0 commit comments

Comments
 (0)