Skip to content

Commit

Permalink
separates demo from library
Browse files Browse the repository at this point in the history
  • Loading branch information
capdevon committed Sep 17, 2024
1 parent 115f5e4 commit 857e5d1
Show file tree
Hide file tree
Showing 84 changed files with 107 additions and 143 deletions.
104 changes: 0 additions & 104 deletions src/main/java/com/jme3/recast4j/demo/utils/GameObject.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.jme3.renderer.ViewPort;
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.Spatial.CullHint;
Expand Down Expand Up @@ -181,30 +182,32 @@ private Node createDebugCylinder(float radius, float height) {
body.attachChild(line);
}

Geometry c1 = createCircle(16, radius);
c1.setName("Bottom.Circle");
Geometry c1 = createCircle(radius);
c1.setName("Bottom-Circle");
c1.setLocalTranslation(0, 0, 0);
body.attachChild(c1);

Geometry c2 = createCircle(16, radius);
c1.setName("Top.Circle");
Geometry c2 = createCircle(radius);
c1.setName("Top-Circle");
c2.setLocalTranslation(0, height, 0);
body.attachChild(c2);

return body;
}

private Geometry createCircle(int samples, float radius) {
private Geometry createCircle(float radius) {
int samples = 16;
Circle circle = new Circle(radius, samples);
Geometry geo = new Geometry("Circle", circle);
geo.setMaterial(wireMaterial);
geo.setShadowMode(ShadowMode.Off);
return geo;
return makeGeometry("Circle", circle);
}

private Geometry createLine(Vector3f start, Vector3f end) {
Line line = new Line(start, end);
Geometry geo = new Geometry("Line", line);
return makeGeometry("Line", line);
}

private Geometry makeGeometry(String name, Mesh mesh) {
Geometry geo = new Geometry(name, mesh);
geo.setMaterial(wireMaterial);
geo.setShadowMode(ShadowMode.Off);
return geo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@
*/
package com.jme3.recast4j.demo.states;

import static com.jme3.recast4j.demo.JmeAreaMods.AREAMOD_DOOR;
import static com.jme3.recast4j.demo.JmeAreaMods.AREAMOD_GRASS;
import static com.jme3.recast4j.demo.JmeAreaMods.AREAMOD_GROUND;
import static com.jme3.recast4j.demo.JmeAreaMods.AREAMOD_ROAD;
import static com.jme3.recast4j.demo.JmeAreaMods.AREAMOD_WATER;
import static com.jme3.recast4j.demo.JmeAreaMods.POLYAREA_TYPE_DOOR;
import static com.jme3.recast4j.demo.JmeAreaMods.POLYAREA_TYPE_GRASS;
import static com.jme3.recast4j.demo.JmeAreaMods.POLYAREA_TYPE_GROUND;
import static com.jme3.recast4j.demo.JmeAreaMods.POLYAREA_TYPE_JUMP;
import static com.jme3.recast4j.demo.JmeAreaMods.POLYAREA_TYPE_ROAD;
import static com.jme3.recast4j.demo.JmeAreaMods.POLYAREA_TYPE_WATER;
import static com.jme3.recast4j.demo.JmeAreaMods.POLYFLAGS_DISABLED;
import static com.jme3.recast4j.demo.JmeAreaMods.POLYFLAGS_DOOR;
import static com.jme3.recast4j.demo.JmeAreaMods.POLYFLAGS_JUMP;
import static com.jme3.recast4j.demo.JmeAreaMods.POLYFLAGS_SWIM;
import static com.jme3.recast4j.demo.JmeAreaMods.POLYFLAGS_WALK;
import static com.jme3.recast4j.recast.JmeAreaMods.AREAMOD_DOOR;
import static com.jme3.recast4j.recast.JmeAreaMods.AREAMOD_GRASS;
import static com.jme3.recast4j.recast.JmeAreaMods.AREAMOD_GROUND;
import static com.jme3.recast4j.recast.JmeAreaMods.AREAMOD_ROAD;
import static com.jme3.recast4j.recast.JmeAreaMods.AREAMOD_WATER;
import static com.jme3.recast4j.recast.JmeAreaMods.POLYAREA_TYPE_DOOR;
import static com.jme3.recast4j.recast.JmeAreaMods.POLYAREA_TYPE_GRASS;
import static com.jme3.recast4j.recast.JmeAreaMods.POLYAREA_TYPE_GROUND;
import static com.jme3.recast4j.recast.JmeAreaMods.POLYAREA_TYPE_JUMP;
import static com.jme3.recast4j.recast.JmeAreaMods.POLYAREA_TYPE_ROAD;
import static com.jme3.recast4j.recast.JmeAreaMods.POLYAREA_TYPE_WATER;
import static com.jme3.recast4j.recast.JmeAreaMods.POLYFLAGS_DISABLED;
import static com.jme3.recast4j.recast.JmeAreaMods.POLYFLAGS_DOOR;
import static com.jme3.recast4j.recast.JmeAreaMods.POLYFLAGS_JUMP;
import static com.jme3.recast4j.recast.JmeAreaMods.POLYFLAGS_SWIM;
import static com.jme3.recast4j.recast.JmeAreaMods.POLYFLAGS_WALK;

import java.io.File;
import java.io.FileInputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ public class TogglePhysicsDebugState extends BaseAppState implements ActionListe

private static final String TOGGLE_PHYSICS_DEBUG = "TOGGLE_PHYSICS_DEBUG";

private BulletAppState bulletAppState;
private BulletAppState physics;
private InputManager inputManager;

@Override
protected void initialize(Application app) {
this.bulletAppState = getState(BulletAppState.class, true);
this.physics = getState(BulletAppState.class, true);
this.inputManager = app.getInputManager();
}

@Override
protected void cleanup(Application app) {}
protected void cleanup(Application app) {
}

@Override
protected void onEnable() {
Expand All @@ -43,8 +44,8 @@ protected void onDisable() {
@Override
public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals(TOGGLE_PHYSICS_DEBUG) && isPressed) {
boolean debug = bulletAppState.isDebugEnabled();
bulletAppState.setDebugEnabled(!debug);
boolean debug = physics.isDebugEnabled();
physics.setDebugEnabled(!debug);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public DebugHelper(AssetManager assetManager) {
public Geometry drawArrow(Vector3f dir) {
Arrow arrow = new Arrow(dir);
Geometry geo = new Geometry("Arrow", arrow);
geo.setMaterial(createWireMat());
geo.setMaterial(createWireMaterial());
debugNode.attachChild(geo);
return geo;
}
Expand All @@ -50,7 +50,7 @@ public Geometry drawArrow(Vector3f dir) {
public Geometry drawLine(Vector3f from, Vector3f to) {
Line line = new Line(from, to);
Geometry geo = new Geometry("Line", line);
geo.setMaterial(createWireMat());
geo.setMaterial(createWireMaterial());
debugNode.attachChild(geo);
return geo;
}
Expand All @@ -64,7 +64,7 @@ public Geometry drawLine(Vector3f from, Vector3f to) {
public Geometry drawCube(Vector3f center, Vector3f size) {
Box box = new Box(size.x, size.y, size.z);
Geometry geo = new Geometry("Box", box);
geo.setMaterial(createColorMat());
geo.setMaterial(createColorMaterial());
geo.setLocalTranslation(center);
debugNode.attachChild(geo);
return geo;
Expand All @@ -85,7 +85,7 @@ public Geometry drawCube(Vector3f center, float size) {
public Geometry drawWireCube(Vector3f center, Vector3f size) {
WireBox box = new WireBox(size.x, size.y, size.z);
Geometry geo = new Geometry("WireBox", box);
geo.setMaterial(createWireMat());
geo.setMaterial(createWireMaterial());
geo.setLocalTranslation(center);
debugNode.attachChild(geo);
return geo;
Expand All @@ -104,7 +104,7 @@ public Geometry drawWireCube(Vector3f center, float size) {
public Geometry drawSphere(Vector3f center, float radius) {
Sphere sphere = new Sphere(10, 30, radius);
Geometry geo = new Geometry("Sphere", sphere);
geo.setMaterial(createColorMat());
geo.setMaterial(createColorMaterial());
geo.setLocalTranslation(center);
debugNode.attachChild(geo);
return geo;
Expand All @@ -121,20 +121,20 @@ public Geometry drawSphere(Vector3f center, float radius) {
public Geometry drawWireSphere(Vector3f center, float radius) {
BoundingSphereDebug sphere = new BoundingSphereDebug();
Geometry geo = new Geometry("WireSphere", sphere);
geo.setMaterial(createWireMat());
geo.setMaterial(createWireMaterial());
geo.setLocalTranslation(center);
geo.setLocalScale(radius);
debugNode.attachChild(geo);
return geo;
}

private Material createColorMat() {
private Material createColorMaterial() {
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", color);
return mat;
}

private Material createWireMat() {
private Material createWireMaterial() {
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", color);
mat.getAdditionalRenderState().setWireframe(true);
Expand Down
64 changes: 64 additions & 0 deletions src/test/java/com/jme3/recast4j/demo/utils/GameObject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.jme3.recast4j.demo.utils;

import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.Control;

/**
*
* @author capdevon
*/
public class GameObject {

/**
* A private constructor to inhibit instantiation of this class.
*/
private GameObject() {
}

/**
* Returns the component of Type type if the game object has one attached, null
* if it doesn't.
*/
public static <T extends Control> T getComponent(Spatial sp, Class<T> type) {
return sp.getControl(type);
}

/**
* Returns the component of Type type in the GameObject or any of its children
* using depth first search.
*/
public static <T extends Control> T getComponentInChildren(Spatial sp, final Class<T> type) {
T control = sp.getControl(type);
if (control != null) {
return control;
}

if (sp instanceof Node) {
for (Spatial child : ((Node) sp).getChildren()) {
control = getComponentInChildren(child, type);
if (control != null) {
return control;
}
}
}

return null;
}

/**
* Retrieves the component of Type type in the GameObject or any of its parents.
*/
public static <T extends Control> T getComponentInParent(Spatial sp, Class<T> type) {
Node parent = sp.getParent();
while (parent != null) {
T control = parent.getControl(type);
if (control != null) {
return control;
}
parent = parent.getParent();
}
return null;
}

}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 857e5d1

Please sign in to comment.