mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-27 21:34:38 -05:00
IAnimationImporter, MeshImporter, NodeImporter
This commit is contained in:
@@ -5,6 +5,6 @@ namespace UniGLTF
|
||||
{
|
||||
public interface IAnimationImporter
|
||||
{
|
||||
List<AnimationClip> Import(glTF gltf, GameObject root, Axises invertAxis);
|
||||
List<AnimationClip> Import(glTF gltf, GameObject root, List<Transform> nodes, List<AnimationClip> clips, Axises invertAxis);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<MeshWithMaterials> BuildMeshAsync(IAwaitCaller awaitCaller, MaterialFactory ctx, MeshImporter.MeshContext meshContext)
|
||||
public static async Task<MeshWithMaterials> BuildMeshAsync(IAwaitCaller awaitCaller, Func<int, Material> 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();
|
||||
|
||||
@@ -131,9 +131,9 @@ namespace UniGLTF
|
||||
//
|
||||
// fix node's coordinate. z-back to z-forward
|
||||
//
|
||||
public static void FixCoordinate(ImporterContext context, List<TransformWithSkin> nodes, IAxisInverter inverter)
|
||||
public static void FixCoordinate(glTF gltf, List<TransformWithSkin> 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<TransformWithSkin> nodes, int i, IAxisInverter inverter)
|
||||
public static void SetupSkinning(glTF gltf, List<TransformWithSkin> nodes, int i, IAxisInverter inverter)
|
||||
{
|
||||
var x = nodes[i];
|
||||
var skinnedMeshRenderer = x.Transform.GetComponent<SkinnedMeshRenderer>();
|
||||
@@ -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<Matrix4x4>(skin.inverseBindMatrices)
|
||||
var bindPoses = gltf.GetArrayFromAccessor<Matrix4x4>(skin.inverseBindMatrices)
|
||||
.Select(inverter.InvertMat4)
|
||||
.ToArray()
|
||||
;
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace UniGLTF
|
||||
{
|
||||
public sealed class RootAnimationImporter : IAnimationImporter
|
||||
{
|
||||
public List<AnimationClip> Import(glTF gltf, GameObject root, Axises invertAxis)
|
||||
public List<AnimationClip> Import(glTF gltf, GameObject root, List<Transform> _nodes, List<AnimationClip> _clips, Axises invertAxis)
|
||||
{
|
||||
var animationClips = new List<AnimationClip>();
|
||||
if (gltf.animations != null && gltf.animations.Any())
|
||||
|
||||
Reference in New Issue
Block a user