Skip to content

Commit 4dfeeb1

Browse files
committed
Merge branch 'MeFisto94-wip/issue1290'
2 parents 2610e8d + 23c3ac1 commit 4dfeeb1

File tree

15 files changed

+442
-820
lines changed

15 files changed

+442
-820
lines changed

jme3-core/build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@ sourceSets {
1010
java {
1111
srcDir 'src/test/java'
1212
}
13+
14+
System.setProperty "java.awt.headless", "true"
1315
}
1416
}
1517

1618
dependencies {
1719
testImplementation project(':jme3-testdata')
20+
testImplementation project(':jme3-testdata')
21+
testImplementation project(':jme3-desktop')
22+
testRuntime project(':jme3-plugins')
1823
}
1924

2025
task updateVersionPropertiesFile {
@@ -40,4 +45,4 @@ task updateVersionPropertiesFile {
4045
}
4146
}
4247

43-
processResources.dependsOn updateVersionPropertiesFile
48+
processResources.dependsOn updateVersionPropertiesFile
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.jme3.asset;
2+
3+
import com.jme3.asset.plugins.ClasspathLocator;
4+
import com.jme3.asset.plugins.HttpZipLocator;
5+
import com.jme3.asset.plugins.UrlLocator;
6+
import com.jme3.asset.plugins.ZipLocator;
7+
import com.jme3.audio.plugins.WAVLoader;
8+
import com.jme3.system.JmeSystem;
9+
import com.jme3.texture.plugins.AWTLoader;
10+
import org.junit.Assert;
11+
import org.junit.Test;
12+
13+
public class TestLocators {
14+
15+
@Test
16+
public void testAbsoluteLocators() {
17+
AssetManager am = JmeSystem.newAssetManager(TestLocators.class.getResource("/com/jme3/asset/Desktop.cfg"));
18+
am.registerLocator("/", ClasspathLocator.class);
19+
am.registerLoader(WAVLoader.class, "wav");
20+
am.registerLoader(AWTLoader.class, "jpg");
21+
22+
Assert.assertNotNull(am.loadAudio("Sound/Effects/Gun.wav"));
23+
Assert.assertNotNull(am.loadTexture("Textures/Terrain/Pond/Pond.jpg"));
24+
}
25+
26+
/**
27+
* Demonstrates loading a file from a custom {@link AssetLoader}
28+
*/
29+
@Test
30+
public void testCustomLoader() {
31+
AssetManager am = new DesktopAssetManager(true);
32+
am.registerLocator("/", ClasspathLocator.class);
33+
am.registerLoader(TextLoader.class, "fnt");
34+
String result = (String)am.loadAsset("Interface/Fonts/Console.fnt");
35+
Assert.assertTrue(result.startsWith("info face=\"Lucida Console\" size=11 bold=0 italic=0 charset=\"\" unicode=1" +
36+
" stretchH=100 smooth=1 aa=1 padding=0,0,0,0 spacing=1,1 outline=0"));
37+
}
38+
39+
@Test
40+
public void testManyLocators() {
41+
AssetManager am = new DesktopAssetManager(true);
42+
am.registerLocator(
43+
"https://github.com/jMonkeyEngine/wiki/raw/master/docs/modules/tutorials/assets/images/beginner/",
44+
UrlLocator.class);
45+
46+
am.registerLocator("../jme3-examples/town.zip", ZipLocator.class);
47+
am.registerLocator(
48+
"https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/jmonkeyengine/wildhouse.zip",
49+
HttpZipLocator.class);
50+
am.registerLocator("/", ClasspathLocator.class);
51+
52+
// Try loading from jme3-core resources using the ClasspathLocator.
53+
Assert.assertNotNull("Failed to load from classpath",
54+
am.locateAsset(new AssetKey<>("Interface/Fonts/Default.fnt")));
55+
56+
// Try loading from the "town.zip" file using the ZipLocator.
57+
Assert.assertNotNull("Failed to load from town.zip file",
58+
am.locateAsset(new ModelKey("casaamarela.jpg")));
59+
60+
// Try loading from the Google Code Archive website using the HttpZipLocator.
61+
Assert.assertNotNull("Failed to load from wildhouse.zip on googleapis.com",
62+
am.locateAsset(new ModelKey("glasstile2.png")));
63+
64+
// Try loading from the GitHub website using the UrlLocator.
65+
Assert.assertNotNull("Failed to load from HTTP",
66+
am.locateAsset(new TextureKey("beginner-physics.png")));
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
1-
package jme3test.asset;
2-
3-
import com.jme3.asset.AssetInfo;
4-
import com.jme3.asset.AssetLoader;
5-
import java.io.IOException;
6-
import java.util.Scanner;
7-
8-
/**
9-
* An example implementation of {@link AssetLoader} to load text
10-
* files as strings.
11-
*/
12-
public class TextLoader implements AssetLoader {
13-
@Override
14-
public Object load(AssetInfo assetInfo) throws IOException {
15-
Scanner scan = new Scanner(assetInfo.openStream());
16-
StringBuilder sb = new StringBuilder();
17-
try {
18-
while (scan.hasNextLine()) {
19-
sb.append(scan.nextLine()).append('\n');
20-
}
21-
} finally {
22-
scan.close();
23-
}
24-
return sb.toString();
25-
}
26-
}
1+
package com.jme3.asset;
2+
3+
import java.util.Scanner;
4+
5+
/**
6+
* An example implementation of {@link AssetLoader} to load text
7+
* files as strings.
8+
*/
9+
public class TextLoader implements AssetLoader {
10+
@Override
11+
public Object load(AssetInfo assetInfo) {
12+
Scanner scan = new Scanner(assetInfo.openStream());
13+
StringBuilder sb = new StringBuilder();
14+
try {
15+
while (scan.hasNextLine()) {
16+
sb.append(scan.nextLine()).append('\n');
17+
}
18+
} finally {
19+
scan.close();
20+
}
21+
return sb.toString();
22+
}
23+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
* Copyright (c) 2019-2021 jMonkeyEngine
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are
7+
* met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
*
12+
* * Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
*
16+
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17+
* may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
package com.jme3.test;
33+
34+
import com.jme3.anim.AnimComposer;
35+
import com.jme3.anim.Joint;
36+
import com.jme3.anim.SkinningControl;
37+
import com.jme3.app.LegacyApplication;
38+
import com.jme3.app.SimpleApplication;
39+
import com.jme3.app.state.AppState;
40+
import com.jme3.app.state.ScreenshotAppState;
41+
import com.jme3.asset.AssetManager;
42+
import com.jme3.asset.DesktopAssetManager;
43+
import com.jme3.input.InputManager;
44+
import com.jme3.input.dummy.DummyKeyInput;
45+
import com.jme3.input.dummy.DummyMouseInput;
46+
import com.jme3.math.Vector3f;
47+
import com.jme3.renderer.Camera;
48+
import com.jme3.renderer.RenderManager;
49+
import com.jme3.renderer.ViewPort;
50+
import com.jme3.scene.Node;
51+
import com.jme3.system.JmeSystem;
52+
import com.jme3.system.NullRenderer;
53+
import org.junit.Assert;
54+
import org.junit.Test;
55+
56+
import java.lang.reflect.Field;
57+
import java.util.List;
58+
59+
/**
60+
* The Test Suite to prevent regressions from previously fixed Core issues
61+
* @author Stephen Gold &lt;[email protected]&gt;
62+
*/
63+
public class PreventCoreIssueRegressions {
64+
65+
/**
66+
* Test case for JME issue #1421: ScreenshotAppState never cleans up.
67+
*/
68+
@Test
69+
public void testIssue1421() throws NoSuchFieldException, IllegalAccessException {
70+
ScreenshotAppState screenshotAppState = new ScreenshotAppState("./", "screen_shot");
71+
72+
SimpleApplication app = new SimpleApplication(new AppState[]{}) {
73+
// Dummy application because SimpleApp is abstract
74+
@Override
75+
public void simpleInitApp() { }
76+
};
77+
78+
app.setAssetManager(new DesktopAssetManager(true));
79+
Field f1 = LegacyApplication.class.getDeclaredField("inputManager");
80+
f1.setAccessible(true);
81+
f1.set(app, new InputManager(new DummyMouseInput(), new DummyKeyInput(), null, null));
82+
83+
Field f2 = LegacyApplication.class.getDeclaredField("renderManager");
84+
f2.setAccessible(true);
85+
f2.set(app, new RenderManager(new NullRenderer()));
86+
87+
app.getRenderManager().createPostView("null", new Camera(1, 1));
88+
89+
Assert.assertTrue(app.getStateManager().attach(screenshotAppState));
90+
app.getStateManager().update(0f); // Causes SAS#initialize to be called
91+
92+
// Confirm that the SceneProcessor is attached.
93+
List<ViewPort> vps = app.getRenderManager().getPostViews();
94+
Assert.assertEquals(1, vps.size());
95+
Assert.assertEquals(1, vps.get(0).getProcessors().size());
96+
Assert.assertTrue(app.getInputManager().hasMapping("ScreenShot")); // Confirm that KEY_SYSRQ is mapped.
97+
Assert.assertTrue(app.getStateManager().detach(screenshotAppState));
98+
99+
app.getStateManager().update(0f); // Causes SAS#cleanup to be called
100+
101+
// Check whether the SceneProcessor is still attached.
102+
Assert.assertEquals(0, vps.get(0).getProcessors().size());
103+
Assert.assertFalse(app.getInputManager().hasMapping("ScreenShot")); // Confirm that KEY_SYSRQ is unmapped.
104+
}
105+
106+
/**
107+
* Test case for JME issue #1138: Elephant's legUp animation sets Joint translation to NaN.
108+
*/
109+
@Test
110+
public void testIssue1138() {
111+
AssetManager am = JmeSystem.newAssetManager(PreventCoreIssueRegressions.class.getResource("/com/jme3/asset/Desktop.cfg"));
112+
Node cgModel = (Node)am.loadModel("Models/Elephant/Elephant.mesh.xml");
113+
cgModel.rotate(0f, -1f, 0f);
114+
cgModel.scale(0.04f);
115+
116+
AnimComposer composer = cgModel.getControl(AnimComposer.class);
117+
composer.setCurrentAction("legUp");
118+
SkinningControl sControl = cgModel.getControl(SkinningControl.class);
119+
120+
for (Joint joint : sControl.getArmature().getJointList()) {
121+
Assert.assertTrue("Invalid translation for joint " + joint.getName(),
122+
Vector3f.isValidVector(joint.getLocalTranslation()));
123+
}
124+
125+
cgModel.updateLogicalState(1.0f);
126+
cgModel.updateGeometricState();
127+
128+
for (Joint joint : sControl.getArmature().getJointList()) {
129+
Assert.assertTrue("Invalid translation for joint " + joint.getName(),
130+
Vector3f.isValidVector(joint.getLocalTranslation()));
131+
}
132+
}
133+
}

jme3-examples/src/main/java/jme3test/animation/TestIssue1138.java

Lines changed: 0 additions & 85 deletions
This file was deleted.

0 commit comments

Comments
 (0)