For some reason, this doesn't work

Right. So, I am new to jMonkey, and I started doing the tutorial.

I am quite experienced with Java, so that’s no problem.

I ran, however, into a problem.

I was doing the second tutorial (https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_node) where I was going to create the second red box.

But it doesn’t render. Only the blue one is there.

My code:

[java] @Override

public void simpleInitApp() {

Box box1 = new Box( new Vector3f(1,-1,1), 1,1,1);

Box box2 = new Box( new Vector3f(1,3,1), 1,1,1);



Geometry blue = new Geometry(“Box”, box1);

Geometry red = new Geometry(“Box”, box2);



Material matB = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

matB.setColor(“Color”, ColorRGBA.Blue);

blue.setMaterial(matB);



Material matR = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

matR.setColor(“Color”, ColorRGBA.Red);

red.setMaterial(matR);



/** 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. /

pivot.attachChild(blue);

pivot.attachChild(red);

/
* Rotate the pivot node: Note that both boxes have rotated! */

pivot.rotate(.4f, .4f, .4f);

}[/java]



I also compared this code to a friend’s code, it’s the same as far as I could see.

Am I doing something wrong?

Your scene is missing lights.

@glaucomardano said:
Your scene is missing lights.

How will I add those then? How to fix it?
And why did my friend get the red block, but not me?
I can see the blue one though.

unshaded needs lights? :slight_smile:



the tutorial doesnt rotate in z:

pivot.rotate(.4f,.4f,0f);



you may be hiding the box behind the camera or somewhere more magical :stuck_out_tongue:

unshaded needs lights?


:roll:
@dixel said:
unshaded needs lights? :)

the tutorial doesnt rotate in z:
pivot.rotate(.4f,.4f,0f);

you may be hiding the box behind the camera or somewhere more magical :P

Even if that's the case, why can I see the blue one, but not red? Even if I circle around it I still can't see it.

Oh, I found it.

For some reason another package was created, and it takes the code from there -.-

Problem solved, thanks.

@glaucomardano :wink: Don’t confuse him, Unshaded materials don’t need lights. (That’s why we use them in the tutorials.)



@lolmewn

Hmmm, when I run the code above I see the red box at the top right and the blue one at the bottom, as expected…

Did you see any errors in the output?

Did you move around in the scene (mouse and WASD-QY keys?) Did you move the camera? Did your rotation move the boxes into the camera by chance? If the camera is inside a box (or overlapping), you can’t see the box.

Did the problem reoccur in the meanwhile, can anyone else reproduce it?

1 Like

@zathras I fixed it already, I was putting code in the wrong class apparently (oops!)

Thanks for the help :slight_smile: