1+ package org .jmonkeyengine .screenshottests .light .pbr ;
2+
3+ import com .jme3 .app .Application ;
4+ import com .jme3 .app .SimpleApplication ;
5+ import com .jme3 .app .state .BaseAppState ;
6+ import com .jme3 .asset .AssetManager ;
7+ import com .jme3 .environment .EnvironmentProbeControl ;
8+ import com .jme3 .material .Material ;
9+ import com .jme3 .math .FastMath ;
10+ import com .jme3 .math .Vector3f ;
11+ import com .jme3 .renderer .Camera ;
12+ import com .jme3 .scene .Geometry ;
13+ import com .jme3 .scene .Spatial ;
14+ import com .jme3 .util .SkyFactory ;
15+ import com .jme3 .util .mikktspace .MikktspaceTangentGenerator ;
16+ import org .jmonkeyengine .screenshottests .testframework .ScreenshotTestBase ;
17+ import org .junit .jupiter .api .TestInfo ;
18+ import org .junit .jupiter .params .ParameterizedTest ;
19+ import org .junit .jupiter .params .provider .Arguments ;
20+ import org .junit .jupiter .params .provider .MethodSource ;
21+
22+ import java .util .stream .Stream ;
23+
24+ /**
25+ * A simpler PBR example that uses EnvironmentProbeControl to bake the environment
26+ *
27+ * @author Richard Tingle (aka richtea) - screenshot test adaptation
28+ */
29+ public class TestPBRSimple extends ScreenshotTestBase {
30+
31+ private static Stream <Arguments > testParameters () {
32+ return Stream .of (
33+ Arguments .of ("WithRealtimeBaking" , true ),
34+ Arguments .of ("WithoutRealtimeBaking" , false )
35+ );
36+ }
37+
38+ /**
39+ * Test PBR simple with different parameters
40+ *
41+ * @param testName The name of the test (used for screenshot filename)
42+ * @param realtimeBaking Whether to use realtime baking
43+ */
44+ @ ParameterizedTest (name = "{0}" )
45+ @ MethodSource ("testParameters" )
46+ public void testPBRSimple (String testName , boolean realtimeBaking , TestInfo testInfo ) {
47+ if (!testInfo .getTestClass ().isPresent () || !testInfo .getTestMethod ().isPresent ()) {
48+ throw new RuntimeException ("Test preconditions not met" );
49+ }
50+
51+ String imageName = testInfo .getTestClass ().get ().getName () + "." + testInfo .getTestMethod ().get ().getName () + "_" + testName ;
52+
53+ screenshotTest (new BaseAppState () {
54+ private EnvironmentProbeControl envProbe ;
55+ private int frame = 0 ;
56+
57+ @ Override
58+ protected void initialize (Application app ) {
59+ Camera cam = app .getCamera ();
60+ cam .setLocation (new Vector3f (18 , 10 , 0 ));
61+ cam .lookAt (new Vector3f (0 , 0 , 0 ), Vector3f .UNIT_Y );
62+
63+ AssetManager assetManager = app .getAssetManager ();
64+ SimpleApplication simpleApp = (SimpleApplication ) app ;
65+
66+ // Create the tank model
67+ Geometry model = (Geometry ) assetManager .loadModel ("Models/Tank/tank.j3o" );
68+ MikktspaceTangentGenerator .generate (model );
69+
70+ Material pbrMat = assetManager .loadMaterial ("Models/Tank/tank.j3m" );
71+ model .setMaterial (pbrMat );
72+ simpleApp .getRootNode ().attachChild (model );
73+
74+ // Create sky
75+ Spatial sky = SkyFactory .createSky (assetManager , "Textures/Sky/Path.hdr" , SkyFactory .EnvMapType .EquirectMap );
76+ simpleApp .getRootNode ().attachChild (sky );
77+
78+ // Create baker control
79+ envProbe = new EnvironmentProbeControl (assetManager , 256 );
80+ simpleApp .getRootNode ().addControl (envProbe );
81+
82+ // Tag the sky, only the tagged spatials will be rendered in the env map
83+ envProbe .tag (sky );
84+ }
85+
86+ @ Override
87+ protected void cleanup (Application app ) {
88+ // Nothing to clean up
89+ }
90+
91+ @ Override
92+ protected void onEnable () {
93+ // Nothing to do
94+ }
95+
96+ @ Override
97+ protected void onDisable () {
98+ // Nothing to do
99+ }
100+
101+ @ Override
102+ public void update (float tpf ) {
103+ if (realtimeBaking ) {
104+ frame ++;
105+ if (frame == 2 ) {
106+ SimpleApplication simpleApp = (SimpleApplication ) getApplication ();
107+ simpleApp .getRootNode ().getControl (EnvironmentProbeControl .class ).rebake ();
108+ }
109+ }
110+ }
111+ }).setBaseImageFileName (imageName )
112+ .setFramesToTakeScreenshotsOn (10 )
113+ .run ();
114+ }
115+ }
0 commit comments