11package jme3test .light .pbr ;
22
3+ import com .jme3 .anim .SkinningControl ;
34import com .jme3 .app .SimpleApplication ;
45import com .jme3 .asset .plugins .UrlLocator ;
56import com .jme3 .environment .EnvironmentCamera ;
910import com .jme3 .light .LightProbe ;
1011import com .jme3 .math .ColorRGBA ;
1112import com .jme3 .math .Vector3f ;
13+ import com .jme3 .scene .Node ;
1214import com .jme3 .scene .Spatial ;
1315import com .jme3 .system .AppSettings ;
1416
1517/**
16- * @author: rvandoosselaer
18+ * This test case validates a shader compilation fix with a model using a PBR material in combination with a
19+ * SkinningControl. When you run this application and you don't see a RenderException, the test is successful.
20+ * For a detailed explanation consult the github issue: https://github.com/jMonkeyEngine/jmonkeyengine/issues/1340
21+ * -rvandoosselaer
1722 */
1823public class TestIssue1340 extends SimpleApplication {
1924
20- int frame ;
25+ private Spatial model ;
26+ private int frame ;
2127
2228 public static void main (String [] args ) {
2329 TestIssue1340 testIssue1340 = new TestIssue1340 ();
@@ -40,8 +46,11 @@ public void simpleInitApp() {
4046
4147 assetManager .registerLocator ("https://github.com/KhronosGroup/glTF-Sample-Models/raw/master/2.0/RiggedFigure/" , UrlLocator .class );
4248
43- Spatial model = assetManager .loadModel ("/glTF-Embedded/RiggedFigure.gltf" );
44- rootNode .attachChild (model );
49+ model = assetManager .loadModel ("/glTF-Embedded/RiggedFigure.gltf" );
50+ SkinningControl skinningControl = getSkinningControl (model );
51+ if (skinningControl == null || !skinningControl .isHardwareSkinningPreferred ()) {
52+ throw new IllegalArgumentException ("This test case requires a model with a SkinningControl and with Hardware skinning preferred!" );
53+ }
4554
4655 viewPort .setBackgroundColor (ColorRGBA .LightGray );
4756 }
@@ -53,9 +62,31 @@ public void simpleUpdate(float tpf) {
5362 LightProbeFactory .makeProbe (stateManager .getState (EnvironmentCamera .class ), rootNode , new JobProgressAdapter <LightProbe >() {
5463 @ Override
5564 public void done (LightProbe result ) {
56- enqueue (() -> rootNode .addLight (result ));
65+ enqueue (() -> {
66+ rootNode .attachChild (model );
67+ rootNode .addLight (result );
68+ });
5769 }
5870 });
5971 }
6072 }
73+
74+ private SkinningControl getSkinningControl (Spatial model ) {
75+ SkinningControl control = model .getControl (SkinningControl .class );
76+ if (control != null ) {
77+ return control ;
78+ }
79+
80+ if (model instanceof Node ) {
81+ for (Spatial child : ((Node ) model ).getChildren ()) {
82+ SkinningControl skinningControl = getSkinningControl (child );
83+ if (skinningControl != null ) {
84+ return skinningControl ;
85+ }
86+ }
87+ }
88+
89+ return null ;
90+ }
91+
6192}
0 commit comments