fixes some isues with the gltfLoader when there are several skins

monkanim
Nehon 7 years ago
parent 9dc87b71e9
commit 6ccacd257e
  1. 6
      jme3-examples/src/main/java/jme3test/model/TestGltfLoading.java
  2. 14
      jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java

@ -109,6 +109,8 @@ public class TestGltfLoading extends SimpleApplication {
// rootNode.addLight(pl); // rootNode.addLight(pl);
// PointLight pl1 = new PointLight(new Vector3f(-5.0f, -5.0f, -5.0f), ColorRGBA.White.mult(0.5f), 50); // PointLight pl1 = new PointLight(new Vector3f(-5.0f, -5.0f, -5.0f), ColorRGBA.White.mult(0.5f), 50);
// rootNode.addLight(pl1); // 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/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/izzy/scene.gltf", new Vector3f(0, -1, 0), 0.01f);
//loadModel("Models/gltf/darth/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/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/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/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/crab/scene.gltf", Vector3f.ZERO, 1);
//loadModel("Models/gltf/manta/scene.gltf", Vector3f.ZERO, 0.2f); //loadModel("Models/gltf/manta/scene.gltf", Vector3f.ZERO, 0.2f);
//loadModel("Models/gltf/bone/scene.gltf", Vector3f.ZERO, 0.1f); //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()); //System.err.println(ctrl.getArmature().toString());
//ctrl.setHardwareSkinningPreferred(false); //ctrl.setHardwareSkinningPreferred(false);
getStateManager().getState(ArmatureDebugAppState.class).addArmatureFrom(ctrl); // getStateManager().getState(ArmatureDebugAppState.class).addArmatureFrom(ctrl);
// AnimControl aCtrl = findControl(s, AnimControl.class); // AnimControl aCtrl = findControl(s, AnimControl.class);
// //ctrl.getSpatial().removeControl(ctrl); // //ctrl.getSpatial().removeControl(ctrl);
// if (aCtrl == null) { // if (aCtrl == null) {

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

Loading…
Cancel
Save