Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

High-quality test and example scene #2237

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,233 changes: 1,233 additions & 0 deletions jme3-examples/src/main/java/jme3test/TestScene.java

Large diffs are not rendered by default.

84 changes: 46 additions & 38 deletions jme3-examples/src/main/java/jme3test/audio/TestAmbient.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,49 +40,57 @@
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import jme3test.TestScene;

public class TestAmbient extends SimpleApplication {

public static void main(String[] args) {
TestAmbient test = new TestAmbient();
test.start();
}
public static void main(String[] args) {
TestAmbient test = new TestAmbient();
test.start();
}

@Override
public void simpleInitApp() {
float[] eax = new float[]{15, 38.0f, 0.300f, -1000, -3300, 0,
1.49f, 0.54f, 1.00f, -2560, 0.162f, 0.00f, 0.00f,
0.00f, -229, 0.088f, 0.00f, 0.00f, 0.00f, 0.125f, 1.000f,
0.250f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.00f, 0x3f};
Environment env = new Environment(eax);
audioRenderer.setEnvironment(env);
@Override
public void simpleInitApp() {

TestScene scene = new TestScene(assetManager, viewPort);
scene.configureBackgroundColor();
scene.configureCameraPosition(cam);
scene.configureFlyCamSpeed(flyCam);
rootNode.attachChild(scene.load());

float[] eax = new float[]{15, 38.0f, 0.300f, -1000, -3300, 0,
1.49f, 0.54f, 1.00f, -2560, 0.162f, 0.00f, 0.00f,
0.00f, -229, 0.088f, 0.00f, 0.00f, 0.00f, 0.125f, 1.000f,
0.250f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.00f, 0x3f};
Environment env = new Environment(eax);
audioRenderer.setEnvironment(env);

AudioNode waves = new AudioNode(assetManager,
"Sound/Environment/Ocean Waves.ogg", DataType.Buffer);
waves.setPositional(true);
waves.setLocalTranslation(new Vector3f(0, 0,0));
waves.setMaxDistance(100);
waves.setRefDistance(5);
AudioNode waves = new AudioNode(assetManager,
"Sound/Environment/Ocean Waves.ogg", DataType.Buffer);
waves.setPositional(true);
waves.setLocalTranslation(new Vector3f(0, 0, 0));
waves.setMaxDistance(100);
waves.setRefDistance(5);

AudioNode nature = new AudioNode(assetManager,
"Sound/Environment/Nature.ogg", DataType.Stream);
nature.setPositional(false);
nature.setVolume(3);

waves.playInstance();
nature.play();

// just a blue box to mark the spot
Box box1 = new Box(.5f, .5f, .5f);
Geometry player = new Geometry("Player", box1);
Material mat1 = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md");
mat1.setColor("Color", ColorRGBA.Blue);
player.setMaterial(mat1);
rootNode.attachChild(player);
}
AudioNode nature = new AudioNode(assetManager,
"Sound/Environment/Nature.ogg", DataType.Stream);
nature.setPositional(false);
nature.setVolume(3);

@Override
public void simpleUpdate(float tpf) {
}
waves.playInstance();
nature.play();

// just a blue box to mark the spot
Box box1 = new Box(.5f, .5f, .5f);
Geometry player = new Geometry("Player", box1);
Material mat1 = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md");
mat1.setColor("Color", ColorRGBA.Blue);
player.setMaterial(mat1);
rootNode.attachChild(player);
}

@Override
public void simpleUpdate(float tpf) {
}
}
58 changes: 23 additions & 35 deletions jme3-examples/src/main/java/jme3test/bullet/TestBrickWall.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.jme3.asset.TextureKey;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.PhysicsSpace;
import com.jme3.bullet.collision.shapes.BoxCollisionShape;
import com.jme3.bullet.collision.shapes.SphereCollisionShape;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.font.BitmapText;
Expand All @@ -53,20 +52,20 @@
import com.jme3.scene.shape.Sphere;
import com.jme3.scene.shape.Sphere.TextureMode;
import com.jme3.texture.Texture;
import com.jme3.texture.Texture.WrapMode;
import jme3test.TestScene;

/**
*
* @author double1984
*/
public class TestBrickWall extends SimpleApplication {

final private static float bLength = 0.48f;
final private static float bWidth = 0.24f;
final private static float bHeight = 0.12f;
final private static float bLength = 0.96f;
final private static float bWidth = 0.48f;
final private static float bHeight = 0.24f;
private TestScene scene;
private Material mat;
private Material mat2;
private Material mat3;
private static Sphere bullet;
private static Box brick;

Expand All @@ -83,19 +82,26 @@ public void simpleInitApp() {
bulletAppState = new BulletAppState();
bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
stateManager.attach(bulletAppState);

scene = new TestScene(assetManager, viewPort);
scene.setPhysicsSpace(bulletAppState.getPhysicsSpace());
scene.configureBackgroundColor();
scene.configureCameraPosition(cam);
scene.configureFlyCamSpeed(flyCam);
scene.setLocalTranslation(0, -0.1f, 0);
rootNode.attachChild(scene.load());

bullet = new Sphere(32, 32, 0.4f, true, false);
bullet.setTextureMode(TextureMode.Projected);
brick = new Box(bLength, bHeight, bWidth);
brick.scaleTextureCoordinates(new Vector2f(1f, .5f));
brick.scaleTextureCoordinates(new Vector2f(1f, .2f));

initMaterial();
initWall();
initFloor();
initCrossHairs();
this.cam.setLocation(new Vector3f(0, 6f, 6f));
cam.lookAt(Vector3f.ZERO, new Vector3f(0, 1, 0));
cam.setFrustumFar(15);
//cam.setFrustumFar(15);
inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
inputManager.addListener(actionListener, "shoot");
inputManager.addMapping("gc", new KeyTrigger(KeyInput.KEY_X));
Expand All @@ -122,7 +128,7 @@ public void onAction(String name, boolean keyPressed, float tpf) {
// RigidBodyControl bulletNode = new RigidBodyControl(bulletCollisionShape, 1);
bulletNode.setLinearVelocity(cam.getDirection().mult(25));
bulletGeometry.addControl(bulletNode);
rootNode.attachChild(bulletGeometry);
scene.attachChild(bulletGeometry);
getPhysicsSpace().add(bulletNode);
}
if (name.equals("gc") && !keyPressed) {
Expand All @@ -144,38 +150,20 @@ public void initWall() {
}
}

public void initFloor() {
Box floorBox = new Box(10f, 0.1f, 5f);
floorBox.scaleTextureCoordinates(new Vector2f(3, 6));

Geometry floor = new Geometry("floor", floorBox);
floor.setMaterial(mat3);
floor.setShadowMode(ShadowMode.Receive);
floor.setLocalTranslation(0, -0.1f, 0);
floor.addControl(new RigidBodyControl(new BoxCollisionShape(new Vector3f(10f, 0.1f, 5f)), 0));
this.rootNode.attachChild(floor);
this.getPhysicsSpace().add(floor);
}

public void initMaterial() {
mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat = new Material(assetManager, "Common/MatDefs/Light/PBRLighting.j3md");
TextureKey key = new TextureKey("Textures/Terrain/BrickWall/BrickWall.jpg");
key.setGenerateMips(true);
Texture tex = assetManager.loadTexture(key);
mat.setTexture("ColorMap", tex);
mat.setTexture("BaseColorMap", tex);
mat.setFloat("Metallic", .5f);

mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat2 = new Material(assetManager, "Common/MatDefs/Light/PBRLighting.j3md");
TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
key2.setGenerateMips(true);
Texture tex2 = assetManager.loadTexture(key2);
mat2.setTexture("ColorMap", tex2);

mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
TextureKey key3 = new TextureKey("Textures/Terrain/Pond/Pond.jpg");
key3.setGenerateMips(true);
Texture tex3 = assetManager.loadTexture(key3);
tex3.setWrap(WrapMode.Repeat);
mat3.setTexture("ColorMap", tex3);
mat2.setTexture("BaseColorMap", tex2);
mat2.setFloat("Metallic", .5f);
}

public void addBrick(Vector3f ori) {
Expand All @@ -187,7 +175,7 @@ public void addBrick(Vector3f ori) {
brickGeometry.addControl(new RigidBodyControl(1.5f));
brickGeometry.setShadowMode(ShadowMode.CastAndReceive);
brickGeometry.getControl(RigidBodyControl.class).setFriction(0.6f);
this.rootNode.attachChild(brickGeometry);
this.scene.attachChild(brickGeometry);
this.getPhysicsSpace().add(brickGeometry);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@
import com.jme3.shadow.SpotLightShadowRenderer;
import com.jme3.texture.Texture.WrapMode;
import com.jme3.util.TangentBinormalGenerator;
import jme3test.TestScene;

public class TestSpotLightShadows extends SimpleApplication {

final private Vector3f lightTarget = new Vector3f(12, 3.5f, 30);
final private Vector3f lightTarget = new Vector3f(12, 3.5f, 0);
private FilterPostProcessor fpp;

public static void main(String[] args) {
TestSpotLightShadows app = new TestSpotLightShadows();
Expand All @@ -63,6 +65,7 @@ public static void main(String[] args) {
private Geometry lightMdl;

public void setupLighting() {

AmbientLight al = new AmbientLight();
al.setColor(ColorRGBA.White.mult(0.02f));
rootNode.addLight(al);
Expand All @@ -74,7 +77,7 @@ public void setupLighting() {
spot.setSpotRange(1000);
spot.setSpotInnerAngle(5f * FastMath.DEG_TO_RAD);
spot.setSpotOuterAngle(10 * FastMath.DEG_TO_RAD);
spot.setPosition(new Vector3f(70.70334f, 34.013165f, 27.1017f));
spot.setPosition(new Vector3f(70.70334f, 34.013165f, -3));
spot.setDirection(lightTarget.subtract(spot.getPosition()).normalizeLocal());
spot.setColor(ColorRGBA.White.mult(2));
rootNode.addLight(spot);
Expand All @@ -87,7 +90,7 @@ public void setupLighting() {
// rootNode.addLight(pl);
lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
lightMdl.setLocalTranslation(new Vector3f(77.70334f, 34.013165f, 27.1017f));
lightMdl.setLocalTranslation(new Vector3f(77.70334f, 34.013165f, -3));
lightMdl.setLocalScale(5);
rootNode.attachChild(lightMdl);

Expand All @@ -113,7 +116,7 @@ public void setupLighting() {
slsf.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);
slsf.setEnabled(false);

FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
fpp = new FilterPostProcessor(assetManager);
fpp.addFilter(slsf);
viewPort.addProcessor(fpp);

Expand All @@ -135,35 +138,13 @@ public void onAction(String name, boolean isPressed, float tpf) {
flyCam.setDragToRotate(true);
}

public void setupFloor() {
Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
mat.getTextureParam("DiffuseMap").getTextureValue().setWrap(WrapMode.Repeat);
mat.getTextureParam("NormalMap").getTextureValue().setWrap(WrapMode.Repeat);
mat.setBoolean("UseMaterialColors", true);
mat.setColor("Diffuse", ColorRGBA.White.clone());
mat.setColor("Ambient", ColorRGBA.White.clone());
// mat.setColor("Specular", ColorRGBA.White.clone());
// mat.getTextureParam("ParallaxMap").getTextureValue().setWrap(WrapMode.Repeat);
mat.setFloat("Shininess", 0);
// mat.setBoolean("VertexLighting", true);


Box floor = new Box(50, 1f, 50);
TangentBinormalGenerator.generate(floor);
floor.scaleTextureCoordinates(new Vector2f(5, 5));
Geometry floorGeom = new Geometry("Floor", floor);
floorGeom.setMaterial(mat);
floorGeom.setShadowMode(ShadowMode.Receive);
rootNode.attachChild(floorGeom);
}

public void setupSignpost() {
Spatial signpost = assetManager.loadModel("Models/Sign Post/Sign Post.mesh.xml");
Material mat = assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m");
// mat.setBoolean("VertexLighting", true);
signpost.setMaterial(mat);
signpost.rotate(0, FastMath.HALF_PI, 0);
signpost.setLocalTranslation(12, 3.5f, 30);
signpost.setLocalTranslation(12, 3.5f, 0);
signpost.setLocalScale(4);
signpost.setShadowMode(ShadowMode.CastAndReceive);
TangentBinormalGenerator.generate(signpost);
Expand All @@ -175,10 +156,17 @@ public void simpleInitApp() {
cam.setLocation(new Vector3f(27.492603f, 29.138166f, -13.232513f));
cam.setRotation(new Quaternion(0.25168246f, -0.10547892f, 0.02760565f, 0.96164864f));
flyCam.setMoveSpeed(30);

setupLighting();
setupFloor();
setupSignpost();

TestScene scene = new TestScene(assetManager, viewPort);
scene.setEnableLights(false);
scene.setShadows(TestScene.Shadows.None);
scene.setEnableFilters(false);
//scene.setMapSize(4, 4);
scene.setLocalScale(5);
rootNode.attachChild(scene.load());


}
Expand Down
Loading
Loading