BUG: Pictures in subNodes of rootNode are not drawn

Hello,

the picture is drawn when attached directly to the rootNode but is not drawn when attached to subNode!





Node subNode = new Node();

rootNode.attachChild(subNode);



Picture cursor = new Picture("Mouse", false);

cursor.setPosition(100, 100);

cursor.setWidth(50);

cursor.setHeight(50);

cursor.setImage(assetManager, "IAS/cursor.png", true);

subNode.attachChild(cursor);



What's wrong? Bug or feature?





UPDATE:



There is a getChildren() but no addChildren(…); - would you mind to change it?

Have a look at this great tutorial that zathras wrote. The only difference I can see is that the subNode is made after the children in the tutorial.



Also, Node has attachChild, detachChild and getChildren. An addChildren method would be superfluous.

So it's a major bug?

Nope. It seems there's a different problem in your code. I modified the tutorial to create the subnode first:

       // create a pivot node at (0,0,0) and attach it to root
        Node pivot = new Node("pivot");
        rootNode.attachChild(pivot);
       
        // create a blue box at coordinates (1,-1,1)
        Box box1 = new Box( new Vector3f(1,-1,1), 1,1,1);
        Geometry blue = new Geometry("Box", box1);
        Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");
        mat1.setColor("m_Color", ColorRGBA.Blue);
        blue.setMaterial(mat1);
 
        // create a red box straight above the blue one at (1,3,1)
        Box box2 = new Box( new Vector3f(1,3,1), 1,1,1);
        Geometry red = new Geometry("Box", box2);
        Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");
        mat2.setColor("m_Color", ColorRGBA.Red);
        red.setMaterial(mat2);
 
        // attach the two boxes to the *pivot* node!
        pivot.attachChild(blue);
        pivot.attachChild(red);


and it works fine.

I guess it's something to do with loading the texture (are you sure it loads it fine?) or a bug with the Picture class.

To quote myself:

The picture is drawn when attached directly to the rootNode but is not drawn when attached to subNode!



(no loading bug!!!)



It has something to do with the way rootNode is drawn. It works fine with the guiNode.

Use pictures instead of boxes in your example and you will see the problem!



// no problem!

Node subNode = new Node();

guiNode.attachChild(subNode);



        Picture cursor = new Picture("Mouse", false);

        cursor.setPosition(400, 400);

        cursor.setWidth(50);

        cursor.setHeight(50);

        cursor.setImage(assetManager, "IAS/cursor.png", true);

        subNode.attachChild(cursor);



// problem!



      Node subNode = new Node();

rootNode.attachChild(subNode);



        Picture cursor = new Picture("Mouse", false);

        cursor.setPosition(400, 400);

        cursor.setWidth(50);

        cursor.setHeight(50);

        cursor.setImage(assetManager, "IAS/cursor.png", true);

        subNode.attachChild(cursor);






You should separate GUI components from 3D components.

The reason it happens, is because the picture is a GUI component, and therefore should not be subject to 3D frustum culling, which its parents' node uses. This causes incorrect behavior since the picture is in 2D space, checked against a camera in 3D space. You can see that culling is explicitly disabled in the initialization of the Picture class, and the creation of the guiNode.

Momoko_Fan said:

You should separate GUI components from 3D components.
The reason it happens, is because the picture is a GUI component, and therefore should not be subject to 3D frustum culling, which its parents' node uses. This causes incorrect behavior since the picture is in 2D space, checked against a camera in 3D space. You can see that culling is explicitly disabled in the initialization of the Picture class, and the creation of the guiNode.


Thanks for clearing that up Kirill, was starting to confuse me  :P