From 26f393d09cd74b386f881d389977da4eab83eda4 Mon Sep 17 00:00:00 2001 From: rvandoosselaer Date: Sun, 12 Apr 2020 11:38:05 +0200 Subject: [PATCH] Clean up the test case and add some more context. #1340 --- .../jme3test/light/pbr/TestIssue1340.java | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/jme3-examples/src/main/java/jme3test/light/pbr/TestIssue1340.java b/jme3-examples/src/main/java/jme3test/light/pbr/TestIssue1340.java index 9c4cfda7b..82cd024ed 100644 --- a/jme3-examples/src/main/java/jme3test/light/pbr/TestIssue1340.java +++ b/jme3-examples/src/main/java/jme3test/light/pbr/TestIssue1340.java @@ -1,5 +1,6 @@ package jme3test.light.pbr; +import com.jme3.anim.SkinningControl; import com.jme3.app.SimpleApplication; import com.jme3.asset.plugins.UrlLocator; import com.jme3.environment.EnvironmentCamera; @@ -9,15 +10,20 @@ import com.jme3.light.DirectionalLight; import com.jme3.light.LightProbe; import com.jme3.math.ColorRGBA; import com.jme3.math.Vector3f; +import com.jme3.scene.Node; import com.jme3.scene.Spatial; import com.jme3.system.AppSettings; /** - * @author: rvandoosselaer + * This test case validates a shader compilation fix with a model using a PBR material in combination with a + * SkinningControl. When you run this application and you don't see a RenderException, the test is successful. + * For a detailed explanation consult the github issue: https://github.com/jMonkeyEngine/jmonkeyengine/issues/1340 + * -rvandoosselaer */ public class TestIssue1340 extends SimpleApplication { - int frame; + private Spatial model; + private int frame; public static void main(String[] args) { TestIssue1340 testIssue1340 = new TestIssue1340(); @@ -40,8 +46,11 @@ public class TestIssue1340 extends SimpleApplication { assetManager.registerLocator("https://github.com/KhronosGroup/glTF-Sample-Models/raw/master/2.0/RiggedFigure/", UrlLocator.class); - Spatial model = assetManager.loadModel("/glTF-Embedded/RiggedFigure.gltf"); - rootNode.attachChild(model); + model = assetManager.loadModel("/glTF-Embedded/RiggedFigure.gltf"); + SkinningControl skinningControl = getSkinningControl(model); + if (skinningControl == null || !skinningControl.isHardwareSkinningPreferred()) { + throw new IllegalArgumentException("This test case requires a model with a SkinningControl and with Hardware skinning preferred!"); + } viewPort.setBackgroundColor(ColorRGBA.LightGray); } @@ -53,9 +62,31 @@ public class TestIssue1340 extends SimpleApplication { LightProbeFactory.makeProbe(stateManager.getState(EnvironmentCamera.class), rootNode, new JobProgressAdapter() { @Override public void done(LightProbe result) { - enqueue(() -> rootNode.addLight(result)); + enqueue(() -> { + rootNode.attachChild(model); + rootNode.addLight(result); + }); } }); } } + + private SkinningControl getSkinningControl(Spatial model) { + SkinningControl control = model.getControl(SkinningControl.class); + if (control != null) { + return control; + } + + if (model instanceof Node) { + for (Spatial child : ((Node) model).getChildren()) { + SkinningControl skinningControl = getSkinningControl(child); + if (skinningControl != null) { + return skinningControl; + } + } + } + + return null; + } + }