fixes some isues with the gltfLoader when there are several skins

shader-nodes-enhancement
Nehon 7 years ago committed by Rémy Bouquet
parent 8634509a95
commit 2e323eb7cf
  1. 6
      jme3-examples/src/main/java/jme3test/model/TestGltfLoading.java
  2. 22
      jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java

@ -109,6 +109,8 @@ public class TestGltfLoading extends SimpleApplication {
// rootNode.addLight(pl);
// PointLight pl1 = new PointLight(new Vector3f(-5.0f, -5.0f, -5.0f), ColorRGBA.White.mult(0.5f), 50);
// rootNode.addLight(pl1);
loadModel("Models/gltf/polly/project_polly.gltf", new Vector3f(0, 0, 0), 0.5f);
//loadModel("Models/gltf/nier/scene.gltf", new Vector3f(0, -1.5f, 0), 0.01f);
//loadModel("Models/gltf/izzy/scene.gltf", new Vector3f(0, -1, 0), 0.01f);
//loadModel("Models/gltf/darth/scene.gltf", new Vector3f(0, -1, 0), 0.01f);
@ -118,7 +120,7 @@ public class TestGltfLoading extends SimpleApplication {
//loadModel("Models/gltf/war/scene.gltf", new Vector3f(0, -1, 0), 0.1f);
//loadModel("Models/gltf/ganjaarl/scene.gltf", new Vector3f(0, -1, 0), 0.01f);
//loadModel("Models/gltf/hero/scene.gltf", new Vector3f(0, -1, 0), 0.1f);
loadModel("Models/gltf/mercy/scene.gltf", new Vector3f(0, -1, 0), 0.01f);
/// loadModel("Models/gltf/mercy/scene.gltf", new Vector3f(0, -1, 0), 0.01f);
//loadModel("Models/gltf/crab/scene.gltf", Vector3f.ZERO, 1);
//loadModel("Models/gltf/manta/scene.gltf", Vector3f.ZERO, 0.2f);
//loadModel("Models/gltf/bone/scene.gltf", Vector3f.ZERO, 0.1f);
@ -234,7 +236,7 @@ public class TestGltfLoading extends SimpleApplication {
}
//System.err.println(ctrl.getArmature().toString());
//ctrl.setHardwareSkinningPreferred(false);
getStateManager().getState(ArmatureDebugAppState.class).addArmatureFrom(ctrl);
// getStateManager().getState(ArmatureDebugAppState.class).addArmatureFrom(ctrl);
// AnimControl aCtrl = findControl(s, AnimControl.class);
// //ctrl.getSpatial().removeControl(ctrl);
// if (aCtrl == null) {

@ -245,9 +245,11 @@ public class GltfLoader implements AssetLoader {
Integer skinIndex = getAsInteger(nodeData, "skin");
if (skinIndex != null) {
SkinData skinData = fetchFromCache("skins", skinIndex, SkinData.class);
List<Spatial> spatials = skinnedSpatials.get(skinData);
spatials.add(spatial);
skinData.used = true;
if (skinData != null) {
List<Spatial> spatials = skinnedSpatials.get(skinData);
spatials.add(spatial);
skinData.used = true;
}
}
spatial.setLocalTransform(readTransforms(nodeData));
@ -1027,20 +1029,22 @@ public class GltfLoader implements AssetLoader {
private void setupControls() {
for (SkinData skinData : skinnedSpatials.keySet()) {
List<Spatial> spatials = skinnedSpatials.get(skinData);
Spatial spatial = skinData.parent;
if (spatials.isEmpty()) {
continue;
}
Spatial spatial = skinData.parent;
if (spatials.size() >= 1) {
spatial = findCommonAncestor(spatials);
}
if (skinData.parent != null && spatial != skinData.parent) {
skinData.rootBoneTransformOffset = spatial.getWorldTransform().invert();
skinData.rootBoneTransformOffset.combineWithParent(skinData.parent.getWorldTransform());
}
// if (spatial != skinData.parent) {
// skinData.rootBoneTransformOffset = spatial.getWorldTransform().invert();
// if (skinData.parent != null) {
// skinData.rootBoneTransformOffset.combineWithParent(skinData.parent.getWorldTransform());
// }
// }
if (skinData.animComposer != null && skinData.animComposer.getSpatial() == null) {
spatial.addControl(skinData.animComposer);
}

Loading…
Cancel
Save