From 9339733ff6bac9f8a40c28e1453eeff34c139308 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 2 Apr 2021 17:38:46 +0900 Subject: [PATCH] IAnimationImporter, MeshImporter, NodeImporter --- .../Runtime/UniGLTF/IO/IAnimationImporter.cs | 2 +- .../UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs | 8 ++++---- Assets/UniGLTF/Runtime/UniGLTF/IO/MeshImporter.cs | 12 ++++++------ Assets/UniGLTF/Runtime/UniGLTF/IO/NodeImporter.cs | 14 +++++++------- .../Runtime/UniGLTF/IO/RootAnimationImporter.cs | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/IAnimationImporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/IAnimationImporter.cs index 1d3057d66..09e77a7c0 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/IAnimationImporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/IAnimationImporter.cs @@ -5,6 +5,6 @@ namespace UniGLTF { public interface IAnimationImporter { - List Import(glTF gltf, GameObject root, Axises invertAxis); + List Import(glTF gltf, GameObject root, List nodes, List clips, Axises invertAxis); } } diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs index 50cff20c5..289ef7357 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs @@ -110,7 +110,7 @@ namespace UniGLTF using (MeasureTime("AnimationImporter")) { - AnimationClips.AddRange(AnimationImporter.Import(GLTF, Root, InvertAxis)); + AnimationClips.AddRange(AnimationImporter.Import(GLTF, Root, null, null, InvertAxis)); } await OnLoadHierarchy(awaitCaller, MeasureTime); @@ -149,12 +149,12 @@ namespace UniGLTF nodes.Add(NodeImporter.BuildHierarchy(GLTF, i, Nodes, Meshes)); } - NodeImporter.FixCoordinate(this, nodes, inverter); + NodeImporter.FixCoordinate(GLTF, nodes, inverter); // skinning for (int i = 0; i < nodes.Count; ++i) { - NodeImporter.SetupSkinning(this, nodes, i, inverter); + NodeImporter.SetupSkinning(GLTF, nodes, i, inverter); } if (Root == null) @@ -202,7 +202,7 @@ namespace UniGLTF { using (MeasureTime("BuildMesh")) { - var meshWithMaterials = await MeshImporter.BuildMeshAsync(awaitCaller, MaterialFactory, x); + var meshWithMaterials = await MeshImporter.BuildMeshAsync(awaitCaller, MaterialFactory.GetMaterial, x); var mesh = meshWithMaterials.Mesh; // mesh name diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MeshImporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MeshImporter.cs index cd6d73f85..469b46ad0 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MeshImporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MeshImporter.cs @@ -225,7 +225,7 @@ namespace UniGLTF for (int j = 0; j < jointsLength; ++j) { var bw = new BoneWeight(); - + var joints = joints0(j); var weights = weights0(j); @@ -240,7 +240,7 @@ namespace UniGLTF bw.boneIndex3 = joints.w; bw.weight3 = weights.w; - + bw = NormalizeBoneWeight(bw); m_boneWeights.Add(bw); @@ -389,7 +389,7 @@ namespace UniGLTF for (int j = 0; j < jointsLength; ++j) { var bw = new BoneWeight(); - + var joints = joints0(j); var weights = weights0(j); @@ -406,7 +406,7 @@ namespace UniGLTF bw.weight3 = weights.w; bw = NormalizeBoneWeight(bw); - + m_boneWeights.Add(bw); } } @@ -648,7 +648,7 @@ namespace UniGLTF } } - public static async Task BuildMeshAsync(IAwaitCaller awaitCaller, MaterialFactory ctx, MeshImporter.MeshContext meshContext) + public static async Task BuildMeshAsync(IAwaitCaller awaitCaller, Func ctx, MeshImporter.MeshContext meshContext) { var (mesh, recalculateTangents) = _BuildMesh(meshContext); @@ -663,7 +663,7 @@ namespace UniGLTF var result = new MeshWithMaterials { Mesh = mesh, - Materials = meshContext.MaterialIndices.Select(x => ctx.GetMaterial(x)).ToArray() + Materials = meshContext.MaterialIndices.Select(ctx).ToArray() }; await awaitCaller.NextFrame(); diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/NodeImporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/NodeImporter.cs index 8461da81c..41a143d38 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/NodeImporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/NodeImporter.cs @@ -131,9 +131,9 @@ namespace UniGLTF // // fix node's coordinate. z-back to z-forward // - public static void FixCoordinate(ImporterContext context, List nodes, IAxisInverter inverter) + public static void FixCoordinate(glTF gltf, List nodes, IAxisInverter inverter) { - if (context.GLTF.rootnodes == null) + if (gltf.rootnodes == null) { return; } @@ -142,7 +142,7 @@ namespace UniGLTF Position = x.Transform.position, Rotation = x.Transform.rotation, }); - foreach (var x in context.GLTF.rootnodes) + foreach (var x in gltf.rootnodes) { // fix nodes coordinate // reverse Z in global @@ -158,7 +158,7 @@ namespace UniGLTF } } - public static void SetupSkinning(ImporterContext context, List nodes, int i, IAxisInverter inverter) + public static void SetupSkinning(glTF gltf, List nodes, int i, IAxisInverter inverter) { var x = nodes[i]; var skinnedMeshRenderer = x.Transform.GetComponent(); @@ -170,12 +170,12 @@ namespace UniGLTF if (mesh == null) throw new Exception(); if (skinnedMeshRenderer == null) throw new Exception(); - if (x.SkinIndex.Value < context.GLTF.skins.Count) + if (x.SkinIndex.Value < gltf.skins.Count) { // calculate internal values(boundingBox etc...) when sharedMesh assigned ? skinnedMeshRenderer.sharedMesh = null; - var skin = context.GLTF.skins[x.SkinIndex.Value]; + var skin = gltf.skins[x.SkinIndex.Value]; var joints = skin.joints.Select(y => nodes[y].Transform).ToArray(); if (joints.Any()) { @@ -184,7 +184,7 @@ namespace UniGLTF if (skin.inverseBindMatrices != -1) { - var bindPoses = context.GLTF.GetArrayFromAccessor(skin.inverseBindMatrices) + var bindPoses = gltf.GetArrayFromAccessor(skin.inverseBindMatrices) .Select(inverter.InvertMat4) .ToArray() ; diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/RootAnimationImporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/RootAnimationImporter.cs index 7c062da4b..f58bf4f87 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/RootAnimationImporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/RootAnimationImporter.cs @@ -6,7 +6,7 @@ namespace UniGLTF { public sealed class RootAnimationImporter : IAnimationImporter { - public List Import(glTF gltf, GameObject root, Axises invertAxis) + public List Import(glTF gltf, GameObject root, List _nodes, List _clips, Axises invertAxis) { var animationClips = new List(); if (gltf.animations != null && gltf.animations.Any())