I am trying to create a level editor and for that load premade .j3o modes, translate and rotate them in the scene. To store the data i simply save the asset name, location and rotation of them. But when loading the scene in the editor somehow the nodes that are initialy not rotated somehwo can’t be rotated any more.
I am creating the scene like this:
[java]
for (SSIEnviroment enviroment : currentLevel.getEnviroment().values()) {
Node envNode = (Node) assetManager.loadModel(enviroment.getModel());
envNode.setUserData(SSIStatics.NODETYPE, SSIStatics.NODETYPE_ENVIROMENT);
envNode.setUserData(SSIStatics.NODETYPE_ENVIROMENT, enviroment.getUID());
envNode.move(enviroment.getPosition());
envNode.rotate(enviroment.getRotation());
enviromentNode.attachChild(envNode);
uidCounter++;
}
[/java]
To test the whole editor i just added a few objects like this:
[java]
currentLevel = new SSILevel(“new”);
currentLevel.getEnviroment().put(
“1”, new SSIEnviroment(“1”, “Models/SSI/Scenery/BlueHalls/Wall1.j3o”,
Vector3f.ZERO.clone(), Quaternion.ZERO.clone()));
currentLevel.getEnviroment().put(
“2”, new SSIEnviroment(“2”, “Models/SSI/Scenery/BlueHalls/Wall2.j3o”,
Vector3f.ZERO.clone().setZ(8), Quaternion.ZERO.clone()));
currentLevel.getEnviroment().put(
“3”, new SSIEnviroment(“3”, “Models/SSI/Scenery/BlueHalls/Wall4.j3o”,
Vector3f.ZERO.clone().setZ(8).setY(4), PITCH090.clone()));
[/java]
Moving the nodes works perfectly, but rotating does only work for the node with if “3”. All the other nodes simply wont rotate in any direction.
I rotate the nodes like this:
[java]
public static final Quaternion PITCH045 = new Quaternion().fromAngleAxis(FastMath.PI / 4, new Vector3f(1, 0, 0));
public static final Quaternion PITCH090 = new Quaternion().fromAngleAxis(FastMath.PI / 2, new Vector3f(1, 0, 0));
switch (direction) {
case ArroundX: {
switch (turnAngle) {
case Turn45: {
selectedNode.rotate(PITCH045);
break;
}
case Turn90: {
selectedNode.rotate(PITCH090);
break;
}
}
break;
}
}
[/java]
And getting the selected node like this:
[java]
CollisionResults results = new CollisionResults();
Vector2f click2d = inputManager.getCursorPosition();
Vector3f click3d = cam.getWorldCoordinates(new Vector2f(click2d.x, click2d.y), 0f).clone();
Vector3f dir = cam.getWorldCoordinates(new Vector2f(click2d.x, click2d.y), 1f).subtractLocal(click3d).normalizeLocal();
Ray ray = new Ray(click3d, dir);
rootNode.collideWith(ray, results);
if (results.size() > 0) {
Node picked = results.getClosestCollision().getGeometry().getParent();
selectedNode = picked;
Geometry g = results.getClosestCollision().getGeometry().clone();
g.setName("selectionshape");
g.setMaterial(selectedMat);
g.scale(1.01f);
setCoordinateAxes(selectedNode.getWorldTranslation());
while (selectedNode.getUserData(SSIStatics.NODETYPE) == null) {
selectedNode = selectedNode.getParent();
}
selectedNode.attachChild(g);
}
[/java]
Anyone got an idea where the problem is ?
The last node with id 3 is the only one that accepts rotation. It is also the only one that gets created with an initial rotation, but that shouldn’t be a problem i think ?