Skip to content
Open
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
2 changes: 1 addition & 1 deletion gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void simpleInitApp() { }
@Test
public void testIssue1138() {
AssetManager am = JmeSystem.newAssetManager(PreventCoreIssueRegressions.class.getResource("/com/jme3/asset/Desktop.cfg"));
Node cgModel = (Node)am.loadModel("Models/Elephant/Elephant.mesh.xml");
Node cgModel = (Node)am.loadModel("Models/Elephant/Elephant.gltf");
cgModel.rotate(0f, -1f, 0f);
cgModel.scale(0.04f);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private void createCameraMotion() {

private void createScene() {

model = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
model = assetManager.loadModel("Models/Oto/Oto.gltf");
model.center();
model.setShadowMode(ShadowMode.CastAndReceive);
rootNode.attachChild(model);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.jme3.scene.Mesh;
import com.jme3.scene.Node;
import com.jme3.scene.VertexBuffer;
import jme3test.app.SpatialUtils;

/**
* Test for JMonkeyEngine issue #2076: software skinning requires vertex
Expand Down Expand Up @@ -100,7 +101,7 @@ private void testOldAnimationSystem(String assetPath) {
skeletonControl.setHardwareSkinningPreferred(false);

// remove its vertex normals:
Geometry oldGeometry = (Geometry) oldJaime.getChild(0);
Geometry oldGeometry = SpatialUtils.findFirstGeometry(oldJaime);
Mesh oldMesh = oldGeometry.getMesh();
oldMesh.clearBuffer(VertexBuffer.Type.Normal);
oldMesh.clearBuffer(VertexBuffer.Type.BindPoseNormal);
Expand All @@ -124,7 +125,7 @@ private void testNewAnimationSystem(String assetPath) {
skinningControl.setHardwareSkinningPreferred(false);

// remove its vertex normals:
Geometry newGeometry = (Geometry) newJaime.getChild(0);
Geometry newGeometry = SpatialUtils.findFirstGeometry(newJaime);
Mesh newMesh = newGeometry.getMesh();
newMesh.clearBuffer(VertexBuffer.Type.Normal);
newMesh.clearBuffer(VertexBuffer.Type.BindPoseNormal);
Expand Down
86 changes: 86 additions & 0 deletions jme3-examples/src/main/java/jme3test/app/SpatialUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package jme3test.app;

import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;

/**
* Utility class for working with spatial hierarchies.
* Provides helper methods for searching and manipulating spatial scene graphs.
*/
public class SpatialUtils {

/**
* Recursively finds the first Geometry in a spatial hierarchy.
* This is useful for handling both simple flat structures (Ogre models) and
* complex nested node trees (glTF models).
*
* @param spatial The root spatial to search from
* @return The first Geometry found, or null if none exists
*/
public static Geometry findFirstGeometry(Spatial spatial) {
if (spatial instanceof Geometry) {
return (Geometry) spatial;
}
if (spatial instanceof Node) {
Node node = (Node) spatial;
for (Spatial child : node.getChildren()) {
Geometry geom = findFirstGeometry(child);
if (geom != null) {
return geom;
}
}
}
return null;
}

/**
* Recursively finds a Geometry by name in a spatial hierarchy.
* Searches depth-first through the entire spatial tree.
*
* @param spatial The root spatial to search from
* @param name The name of the geometry to find
* @return The Geometry with the matching name, or null if not found
*/
public static Geometry findGeometryByName(Spatial spatial, String name) {
if (spatial.getName() != null && spatial.getName().equals(name) && spatial instanceof Geometry) {
return (Geometry) spatial;
}
if (spatial instanceof Node) {
Node node = (Node) spatial;
for (Spatial child : node.getChildren()) {
Geometry geom = findGeometryByName(child, name);
if (geom != null) {
return geom;
}
}
}
return null;
}

/**
* Counts the total number of Geometries in a spatial hierarchy.
* Useful for debugging and understanding scene structure.
*
* @param spatial The root spatial to count from
* @return The total number of geometries in the hierarchy
*/
public static int countGeometries(Spatial spatial) {
if (spatial instanceof Geometry) {
return 1;
}
if (spatial instanceof Node) {
int count = 0;
Node node = (Node) spatial;
for (Spatial child : node.getChildren()) {
count += countGeometries(child);
}
return count;
}
return 0;
}

private SpatialUtils() {
// Utility class, no instantiation
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public void simpleInitApp() {
PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager,
physicsSpace);

model = (Node) assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml");
model = (Node) assetManager.loadModel("Models/Sinbad/Sinbad.gltf");
rootNode.attachChild(model);

composer = model.getControl(AnimComposer.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void simpleInitApp() {
}

private void buildPlayer() {
spaceCraft = assetManager.loadModel("Models/HoverTank/Tank2.mesh.xml");
spaceCraft = assetManager.loadModel("Models/HoverTank/Tank2.gltf");
CollisionShape colShape = CollisionShapeFactory.createDynamicMeshShape(spaceCraft);
spaceCraft.setShadowMode(ShadowMode.CastAndReceive);
spaceCraft.setLocalTranslation(startLocation);
Expand All @@ -164,7 +164,7 @@ public void makeMissile() {
Quaternion rot = spaceCraft.getWorldRotation();
Vector3f dir = rot.getRotationColumn(2);

Spatial missile = assetManager.loadModel("Models/SpaceCraft/Rocket.mesh.xml");
Spatial missile = assetManager.loadModel("Models/SpaceCraft/Rocket.gltf");
missile.scale(0.5f);
missile.rotate(0, FastMath.PI, 0);
missile.updateGeometricState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void simpleInitApp() {
stateManager.attach(bulletAppState);
initCrossHair();

Spatial s = assetManager.loadModel("Models/Elephant/Elephant.mesh.xml");
Spatial s = assetManager.loadModel("Models/Elephant/Elephant.gltf");
s.setLocalScale(0.1f);

CollisionShape collisionShape = CollisionShapeFactory.createMeshShape(s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void simpleInitApp() {
physicsSpace);
initWall(2f, 1f, 1f);

model = (Node) assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml");
model = (Node) assetManager.loadModel("Models/Sinbad/Sinbad.gltf");
rootNode.attachChild(model);
model.lookAt(new Vector3f(0f, 0f, -1f), Vector3f.UNIT_Y);
model.setLocalTranslation(4f, 0f, -7f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ private void createTerrain() {
private void createCharacter() {
CapsuleCollisionShape capsule = new CapsuleCollisionShape(3f, 4f);
character = new CharacterControl(capsule, 0.01f);
model = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
model = (Node) assetManager.loadModel("Models/Oto/Oto.gltf");
model.addControl(character);
character.setPhysicsLocation(new Vector3f(-140, 40, -10));
rootNode.attachChild(model);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import com.jme3.system.AppSettings;
import java.util.ArrayList;
import java.util.List;
import jme3test.app.SpatialUtils;
import jme3test.bullet.PhysicsTestHelper;

/**
Expand Down Expand Up @@ -262,19 +263,19 @@ private void dropTest2(Vector3f offset) {
}

private void dropPot(Vector3f offset) {
drop(offset.add(-12, 7, 15), "Models/Teapot/Teapot.mesh.xml", 1.0f, 2);
drop(offset.add(-12, 7, 15), "Models/Teapot/Teapot.gltf", 1.0f, 2);
}

private void dropSword(Vector3f offset) {
drop(offset.add(-10, 5, 3), "Models/Sinbad/Sword.mesh.xml", 1.0f, 2);
drop(offset.add(-10, 5, 3), "Models/Sinbad/Sword.gltf", 1.0f, 2);
}

private void dropSign(Vector3f offset) {
drop(offset.add(9, 15, 5), "Models/Sign Post/Sign Post.mesh.xml", 1.0f, 1);
drop(offset.add(9, 15, 5), "Models/Sign Post/SignPost.gltf", 1.0f, 1);
}

private void dropRocket(Vector3f offset) {
RigidBodyControl c = drop(offset.add(26, 4, 7), "Models/SpaceCraft/Rocket.mesh.xml", 4.0f, 3);
RigidBodyControl c = drop(offset.add(26, 4, 7), "Models/SpaceCraft/Rocket.gltf", 4.0f, 3);
c.setAngularDamping(0.5f);
c.setLinearDamping(0.5f);
}
Expand All @@ -285,7 +286,7 @@ private RigidBodyControl drop(Vector3f offset, String model, float scale, float
n.setLocalTranslation(offset);
n.rotate(0, 0, -FastMath.HALF_PI);

Geometry tp = ((Geometry) n.getChild(0));
Geometry tp = SpatialUtils.findFirstGeometry(n);
tp.scale(scale);
Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
tp.setMaterial(mat);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private void setupScene() {
shootables.attachChild(torus);

// load a character from jme3-testdata
Spatial golem = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
Spatial golem = assetManager.loadModel("Models/Oto/Oto.gltf");
golem.scale(0.5f);
golem.setLocalTranslation(-1.0f, -1.5f, -0.6f);
shootables.attachChild(golem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void simpleInitApp() {
q.updateBound();
// Geometry teapot = new Geometry("MyGeom", q);

teapot = assetManager.loadModel("Models/Teapot/Teapot.mesh.xml");
teapot = assetManager.loadModel("Models/Teapot/Teapot.gltf");
// teapot.scale(2f, 2f, 2f);
// teapot.move(2f, 2f, -.5f);
teapot.rotate(FastMath.HALF_PI, FastMath.HALF_PI, FastMath.HALF_PI);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void simpleInitApp() {
rootNode.attachChild(geom1);

// load a character from jme3-testdata
golem = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
golem = assetManager.loadModel("Models/Oto/Oto.gltf");
golem.scale(0.5f);
golem.setLocalTranslation(-1.0f, -1.5f, -0.6f);

Expand Down
20 changes: 14 additions & 6 deletions jme3-examples/src/main/java/jme3test/effect/TestEverything.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
import com.jme3.app.SimpleApplication;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.*;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.post.FilterPostProcessor;
import com.jme3.post.filters.ToneMapFilter;
import com.jme3.renderer.Caps;
Expand All @@ -50,6 +54,8 @@
import com.jme3.util.SkyFactory;
import com.jme3.util.mikktspace.MikktspaceTangentGenerator;

import jme3test.app.SpatialUtils;

public class TestEverything extends SimpleApplication {

private DirectionalLightShadowRenderer dlsr;
Expand Down Expand Up @@ -151,21 +157,23 @@ public void setupFloor(){
//
// }

public void setupRobotGuy(){
Node model = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
public void setupRobotGuy() {
Node model = (Node) assetManager.loadModel("Models/Oto/Oto.gltf");
Geometry otoGeometry = SpatialUtils.findFirstGeometry(model);
Material mat = assetManager.loadMaterial("Models/Oto/Oto.j3m");
model.getChild(0).setMaterial(mat);
Comment thread
NwosuTy marked this conversation as resolved.
// model.setAnimation("Walk");
otoGeometry.setMaterial(mat);

model.setLocalTranslation(30, 10.5f, 30);
model.setLocalScale(2);
model.setShadowMode(ShadowMode.CastAndReceive);
rootNode.attachChild(model);
}

public void setupSignpost(){
Spatial signpost = assetManager.loadModel("Models/Sign Post/Sign Post.mesh.xml");
Spatial signpost = assetManager.loadModel("Models/Sign Post/SignPost.gltf");
Material mat = assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m");
signpost.setMaterial(mat);

signpost.rotate(0, FastMath.HALF_PI, 0);
signpost.setLocalTranslation(12, 3.5f, 30);
signpost.setLocalScale(4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static void main(String[] args){
@Override
public void simpleInitApp() {
AssetLinkNode loaderNode=new AssetLinkNode();
loaderNode.addLinkedChild(new ModelKey("Models/MonkeyHead/MonkeyHead.mesh.xml"));
loaderNode.addLinkedChild(new ModelKey("Models/MonkeyHead/MonkeyHead.gltf"));
//load/attach the children (happens automatically on load)
// loaderNode.attachLinkedChildren(assetManager);
// rootNode.attachChild(loaderNode);
Expand Down
3 changes: 2 additions & 1 deletion jme3-examples/src/main/java/jme3test/games/CubeField.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import jme3test.app.SpatialUtils;

/**
* @author Kyle "bonechilla" Williams
Expand Down Expand Up @@ -276,7 +277,7 @@ else if(difficulty>lowCap){
for (int i = 0; i < cubeField.size(); i++){

//better way to check collision
Geometry playerModel = (Geometry) player.getChild(0);
Geometry playerModel = SpatialUtils.findFirstGeometry(player);
Geometry cubeModel = cubeField.get(i);

BoundingVolume pVol = playerModel.getWorldBound();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public void simpleInitApp() {
dl.setDirection(new Vector3f(-0.1f, -1f, -1).normalizeLocal());
rootNode.addLight(dl);

/* Load a model that contains animation */
Node player = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
/* Load a gltf model that contains animation */
Node player = (Node) assetManager.loadModel("Models/Oto/Oto.gltf");
player.setLocalScale(0.5f);
rootNode.attachChild(player);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public void simpleInitApp() {
helloText.setLocalTranslation(300, helloText.getLineHeight(), 0);
guiNode.attachChild(helloText);

/* Load a Ninja model (OgreXML + material + texture from test_data) */
Spatial ninja = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
/* Load a Ninja model (glTF format from test_data) */
Spatial ninja = assetManager.loadModel("Models/Ninja/Ninja.gltf");
Comment thread
NwosuTy marked this conversation as resolved.
ninja.scale(0.05f, 0.05f, 0.05f);
ninja.rotate(0.0f, -3.0f, 0.0f);
ninja.setLocalTranslation(0.0f, -5.0f, -2.0f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private void initCrossHairs() {

private Spatial makeCharacter() {
// load a character from jme3-testdata
Spatial golem = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
Spatial golem = assetManager.loadModel("Models/Oto/Oto.gltf");
golem.scale(0.5f);
golem.setLocalTranslation(-1.0f, -1.5f, -0.6f);

Expand Down
6 changes: 4 additions & 2 deletions jme3-examples/src/main/java/jme3test/light/TestIssue2209.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
*/
package jme3test.light;

import java.util.logging.Logger;

import com.jme3.app.SimpleApplication;
import com.jme3.light.DirectionalLight;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Node;
import com.jme3.shadow.DirectionalLightShadowRenderer;
import java.util.logging.Logger;

import jme3test.bullet.TestIssue1125;

/**
Expand Down Expand Up @@ -81,7 +83,7 @@ public void simpleInitApp() {
dlsr.setLight(dl);
viewPort.addProcessor(dlsr);

Node player = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
Node player = (Node) assetManager.loadModel("Models/Oto/Oto.gltf");
player.setShadowMode(RenderQueue.ShadowMode.Cast);
rootNode.attachChild(player);
}
Expand Down
Loading
Loading