Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,7 @@ private void findChildren(int nodeIndex) throws IOException {
// removing the spatial from the dummy node,
// it will be attached to the attachment node of the bone
s.removeFromParent();
jw.attachedSpatial = s;
jw.attachedSpatials.add(s);
}
}
}
Expand Down Expand Up @@ -1482,7 +1482,7 @@ private void setupControls() {

for (int i = 0; i < nodes.size(); i++) {
JointWrapper bw = fetchFromCache("nodes", i, JointWrapper.class);
if (bw == null || bw.attachedSpatial == null) {
if (bw == null || bw.attachedSpatials.isEmpty()) {
continue;
}
String jointName = bw.joint.getName();
Expand All @@ -1494,7 +1494,10 @@ private void setupControls() {
jointName);
rootNode.addControl(skinControl);
}
skinControl.getAttachmentsNode(jointName).attachChild(bw.attachedSpatial);
Node attachmentNode = skinControl.getAttachmentsNode(jointName);
for (Spatial attachedSpatial : bw.attachedSpatials) {
attachmentNode.attachChild(attachedSpatial);
}
}
}

Expand Down Expand Up @@ -1597,7 +1600,7 @@ private class JointWrapper {
int jointIndex;
int skinIndex;
boolean isRoot = false;
Spatial attachedSpatial;
List<Spatial> attachedSpatials = new ArrayList<>();
List<Integer> children = new ArrayList<>();

public JointWrapper(Joint joint, int jointIndex, int skinIndex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ public void init() {

}

@Test
public void keepsEverySpatialAttachedToTheSameJoint() {
Spatial scene = assetManager.loadModel("gltf/JointAttachments.gltf");
boolean[] found = new boolean[2];
scene.depthFirstTraversal(spatial -> {
if ("FirstAttachment".equals(spatial.getName())) found[0] = true;
if ("SecondAttachment".equals(spatial.getName())) found[1] = true;
});
Assertions.assertTrue(found[0], "First joint attachment was lost");
Assertions.assertTrue(found[1], "Second joint attachment was lost");
}

@Test
public void testLoad() {
Spatial scene = assetManager.loadModel("gltf/box/box.gltf");
Expand Down
25 changes: 25 additions & 0 deletions jme3-plugins/src/test/resources/gltf/JointAttachments.gltf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"asset": {"version": "2.0"},
"scene": 0,
"scenes": [{"nodes": [0]}],
"nodes": [
{"name": "Root", "children": [1, 2]},
{"name": "SkinnedMesh", "mesh": 0, "skin": 0},
{"name": "Joint", "children": [3, 4]},
{"name": "FirstAttachment"},
{"name": "SecondAttachment"}
],
"skins": [{"joints": [2]}],
"meshes": [{"primitives": [{"attributes": {"POSITION": 0, "JOINTS_0": 1, "WEIGHTS_0": 2}}]}],
"buffers": [{"byteLength": 96, "uri": "data:application/octet-stream;base64,AAAAAAAAAAAAAAAAAACAPwAAAAAAAAAAAAAAAAAAgD8AAAAAAAAAAAAAAAAAAAAAAACAPwAAAAAAAAAAAAAAAAAAgD8AAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAAAA"}],
"bufferViews": [
{"buffer": 0, "byteOffset": 0, "byteLength": 36},
{"buffer": 0, "byteOffset": 36, "byteLength": 12},
{"buffer": 0, "byteOffset": 48, "byteLength": 48}
],
"accessors": [
{"bufferView": 0, "componentType": 5126, "count": 3, "type": "VEC3", "min": [0, 0, 0], "max": [1, 1, 0]},
{"bufferView": 1, "componentType": 5121, "count": 3, "type": "VEC4"},
{"bufferView": 2, "componentType": 5126, "count": 3, "type": "VEC4"}
]
}
Loading