Im going through all of the beginners tutorials. I am running through the HelloNode program and i created the two boxes but only the blue one appears. They are added to the nodes in order to make them visible. I even commented the blue one out and it still appears and the red one doesnt…
Here is the code below:
Box box1 = new Box(1,1,1);
Geometry blue = new Geometry("Box", box1);
blue.setLocalTranslation(new Vector3f(1,-1,1));
Material mat1 = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md");
mat1.setColor("Color", ColorRGBA.Blue);
blue.setMaterial(mat1);
/** create a red box straight above the blue one at (1,3,1) */
Box box2 = new Box(1,2,1);
Geometry red = new Geometry("Box", box2);
red.setLocalTranslation(new Vector3f(1,3,1));
Material mat2 = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md");
mat2.setColor("Color", ColorRGBA.Red);
red.setMaterial(mat2);
/** Create a pivot node at (0,0,0) and attach it to the root node */
Node pivot = new Node("pivot");
//rootNode.attachChild(pivot); // put this node in the scene
/** Attach the two boxes to the *pivot* node. (And transitively to the root node.) */
pivot.attachChild(blue);
pivot.attachChild(red);
/** Rotate the pivot node: Note that both boxes have rotated! */
pivot.rotate(.4f,.4f,0f);
}
Hello, I ran you’re code and found that both boxes rendered, the only issue being weird vectors
I do notice though that you’ve given both geometries the name “Box”, which may lead to some internal conflicts. Try changing the string names and running again?
Me: You don’t actually attach the pivot node
OP: Oh, this isn’t the real code.
Me: Show us the real code or else we can’t help.
OP: But I only showed the part that was wrong.
Me: But if you knew the part that was actually wrong then you’d have already solved the problem. Show us all of the code.
/** Sample 2 - How to use nodes as handles to manipulate objects in the scene.
You can rotate, translate, and scale objects by manipulating their parent nodes.
The Root Node is special: Only what is attached to the Root Node appears in the scene. */
public class HelloNode extends SimpleApplication {
public static void main(String[] args){
HelloNode app = new HelloNode();
app.start();
}
@Override
public void simpleInitApp() {
/** create a blue box at coordinates (1,-1,1) */
Box box1 = new Box(1,1,1);
Geometry blue = new Geometry("Box", box1);
blue.setLocalTranslation(new Vector3f(1,-1,1));
Material mat1 = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md");
mat1.setColor("Color", ColorRGBA.Green);
blue.setMaterial(mat1);
/** create a red box straight above the blue one at (1,3,1) */
Box box2 = new Box(1,2,1);
Geometry red = new Geometry("Box", box2);
red.setLocalTranslation(new Vector3f(1,3,1));
Material mat2 = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md");
mat2.setColor("Color", ColorRGBA.Red);
red.setMaterial(mat2);
/** Create a pivot node at (0,0,0) and attach it to the root node */
Node pivot = new Node("pivot");
//rootNode.attachChild(pivot); // put this node in the scene
/** Attach the two boxes to the *pivot* node. (And transitively to the root node.) */
pivot.attachChild(blue);
pivot.attachChild(red);
/** Rotate the pivot node: Note that both boxes have rotated! */
pivot.rotate(.4f,.4f,0f);
}
Me: You don’t actually attach the pivot node
OP: Oh, this isn’t the real code.
Me: Show us the real code or else we can’t help.
OP: But I only showed the part that was wrong.
Me: But if you knew the part that was actually wrong then you’d have already solved the problem. Show us all of the code.
package jme3test.helloworld;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Box;
/** Sample 2 - How to use nodes as handles to manipulate objects in the scene.
* You can rotate, translate, and scale objects by manipulating their parent nodes.
* The Root Node is special: Only what is attached to the Root Node appears in the scene. */
public class HelloNode extends SimpleApplication {
public static void main(String[] args){
HelloNode app = new HelloNode();
app.start();
}
@Override
public void simpleInitApp() {
/** create a blue box at coordinates (1,-1,1) */
Box box1 = new Box(1,1,1);
Geometry blue = new Geometry("Box", box1);
blue.setLocalTranslation(new Vector3f(1,-1,1));
Material mat1 = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md");
mat1.setColor("Color", ColorRGBA.Green);
blue.setMaterial(mat1);
/** create a red box straight above the blue one at (1,3,1) */
Box box2 = new Box(1,1,1);
Geometry red = new Geometry("Box", box2);
red.setLocalTranslation(new Vector3f(1,3,1));
Material mat2 = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md");
mat2.setColor("Color", ColorRGBA.Red);
red.setMaterial(mat2);
/** Create a pivot node at (0,0,0) and attach it to the root node */
Node pivot = new Node("pivot");
rootNode.attachChild(pivot); // put this node in the scene
/** Attach the two boxes to the *pivot* node. (And transitively to the root node.) */
pivot.attachChild(blue);
pivot.attachChild(red);
/** Rotate the pivot node: Note that both boxes have rotated! */
pivot.rotate(.4f,.4f,0f);
}
}
Edit: fixed the code formatting because it was making my eyes bleed. -pspeed
If nothing is changing when you change stuff then make sure you are really running the code you think you are. It’s not clear from your descriptions so far but the fact that you still have “just a blue box” is a sign that you are running an older version of your class… or maybe the default one that the SDK created.
Let me guess, ATI card?
Got this once with my old ati card. I had to roll back the drivers to a version that was one year old for it to work again.
Then I decided to switch to nvidia.
I analysed the issue back then. it seems that the first render call is just ignored…
I’m running it using the jMonkeyEngine SDK 3.0. When the source code is open, I click on the green arrow, which is the equivalent to F6, that runs the program.
If you have multiple main classes then one of them is run when you press the arrow button. Either set the one that supposed to be run in the project settings or right-click the class you want to run and select “Run”.
Ahhh that worked. so do I have to do that every time? I mean, im learning Java as well and I use Netbeans and I dont have to do that with mulitple source codes open…
wow man. I spent days and hours trying to figure this out and all i had to do was right click instead of clicking on the green button? #bahilearnedsomething
thanks for your help. so is that a bug in that part of the code, as far as pressing the green button?