Skip to content

Commit

Permalink
Fixed ModelUtil rename of root animation track to "root"
Browse files Browse the repository at this point in the history
  • Loading branch information
JCash committed Sep 16, 2023
1 parent 70dbaba commit 67563df
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Expand Up @@ -412,8 +412,8 @@ public void testObjectAnimations() throws Exception {
@Test
public void testSkeleton() throws Exception {

String[] boneIds = {"Bone", "Bone_001", "Bone_002", "Bone_003", "Bone_004"};
String[] parentIds = {null, "Bone", "Bone", "Bone", "Bone"};
String[] boneIds = {"root", "Bone_001", "Bone_002", "Bone_003", "Bone_004"};
String[] parentIds = {null, "root", "root", "root", "root"};

Rig.Skeleton.Builder skeleton = Rig.Skeleton.newBuilder();
ColladaUtil.loadSkeleton(load("bone_influences.dae"), skeleton, new ArrayList<String>());
Expand Down
Expand Up @@ -332,8 +332,8 @@ public void testBoneInfluences() throws Exception {
@Test
public void testSkeleton() throws Exception {

String[] boneIds = {"Bottom", "Middle", "Top"};
String[] parentIds = {null, "Bottom", "Middle"};
String[] boneIds = {"root", "Middle", "Top"};
String[] parentIds = {null, "root", "Middle"};

Rig.Skeleton.Builder skeletonBuilder = Rig.Skeleton.newBuilder();
ModelImporter.Scene scene = loadBuiltScene("bend2bones.gltf", skeletonBuilder);
Expand Down
Expand Up @@ -286,6 +286,12 @@ public static void loadAnimations(Scene scene, Rig.AnimationSet.Builder animatio
System.out.printf("Scene contains more than one animation. Picking the the longest one ('%s')\n", scene.animations[0].name);
}

ArrayList<ModelImporter.Bone> bones = loadSkeleton(scene);
String prevRootName = null;
if (!bones.isEmpty()) {
prevRootName = bones.get(0).node.name;
}

for (ModelImporter.Animation animation : scene.animations) {

Rig.RigAnimation.Builder animBuilder = Rig.RigAnimation.newBuilder();
Expand Down Expand Up @@ -328,7 +334,12 @@ public static void loadAnimations(Scene scene, Rig.AnimationSet.Builder animatio
animBuilder.setDuration(animation.duration);

for (ModelImporter.NodeAnimation nodeAnimation : animation.nodeAnimations) {
createAnimationTracks(animBuilder, nodeAnimation, nodeAnimation.node.name, animation.duration, startTime, sampleRate);
String nodeName = nodeAnimation.node.name;
if (prevRootName != null && prevRootName.equals(nodeName)) {
nodeName = "root";
}

createAnimationTracks(animBuilder, nodeAnimation, nodeName, animation.duration, startTime, sampleRate);
}

animationSetBuilder.addAnimations(animBuilder.build());
Expand Down

0 comments on commit 67563df

Please sign in to comment.