Gui Node not attached to anything?

After the recently solved problem of the collision for hands, I attempted to attach my first person hands to the GUI node, but at first, it appears as if they don’t even attach/appear, but then I discovered, they are stuck randomly in the ground somewhere:







I’m not entirely sure why this is occuring, this is the code for creating them:



[java]public void initPlayer(SimpleApplication app)

{

matWire = new Material(Main.api.getAssetManager(), “Common/MatDefs/Misc/Unshaded.j3md”);

matWire.getAdditionalRenderState().setWireframe(true);

matWire.setColor(“Color”, ColorRGBA.Green);

console = false;

guiFont = app.getAssetManager().loadFont(“Interface/Fonts/Default.fnt”);

player = new CharacterControl(capsuleShape, 0.1f);

player.setJumpSpeed(45);

player.setFallSpeed(50);

player.setGravity(100);

player.setMaxSlope(30f);

player.setPhysicsLocation(new Vector3f(0, 10, 0));

hands = Main.api.getAssetManager().loadModel(“Models/hands.j3o”);

//hands.setModelBound(new BoundingBox(new Vector3f(0,0,0),0,0,0));

hands.scale(1f);

handsnode = Main.spawn.create_model(Main.api, Main.api.getGuiNode().getLocalTranslation(), hands, “01ddf”);

Main.api.getGuiNode().attachChild(handsnode);

physics_controller.add_child(player);

lastpressed = System.currentTimeMillis();

}[/java]



and this is the create_model function:



[java]public Spatial create_model(SimpleApplication app, Vector3f loc, Spatial model, String mats )

{

Spatial temp;

if(!mats.equals(“01ddf”))

{

temp = model;

Material mat = new Material(app.getAssetManager(),“Common/MatDefs/Light/Lighting.j3md”);

mat.setTexture(“DiffuseMap”, app.getAssetManager().loadTexture(mats));

mat.setColor(“Specular”, ColorRGBA.White);

mat.setFloat(“Shininess”, 12);

temp.setMaterial(mat);

temp.setLocalTranslation(loc);

}

else

{

temp = model;

Material mat = new Material(app.getAssetManager(),“Common/MatDefs/Light/Lighting.j3md”);

mat.setBoolean(“UseMaterialColors”, true);

mat.setColor(“Diffuse”, ColorRGBA.Magenta);

mat.setColor(“Specular”, ColorRGBA.White);

mat.setFloat(“Shininess”, 12);

temp.setMaterial(mat);

temp.setLocalTranslation(loc);

}

return temp;

}[/java]



the initPlayer function is called in this stage of loading

[java]if(gi.frameCount == 3)

{

//high level: dynamic objects, player, lights etc.

cam.setFrustum(1f, 2500.0f, -0.55f, 0.55f, 0.4125f, -0.4125f);

cam.setLocation(new Vector3f(0, 25, -10));

cam.lookAtDirection(new Vector3f(0, -1, 0).normalizeLocal(), Vector3f.UNIT_Y);

play.setupKeys(this);

play.initPlayer(this);

play.initCrossHairs(this);

play.player_teleport(new Vector3f(0, 50, 50));

play.create_wire();

lights.setup_light();

lights.setup_shadows();

Main.api.getViewPort().addProcessor(Main.fpp);

gi.load_progress(0.7f, “Instantiating the null”);

}[/java]



If there is any other pieces of code you need, they can be found here, in spawncontroller.java (for the model creation), object_player.java (for the player) and Main.java (for the loading/loops).



Personally, I have no idea why this is happening…

You do understand that they guiNode is not a node in the 3d scene, right?



It’s the root node of an orthogonal 2D viewport that overlays the 3D scene. x,y locations of guiNode children are the x,y pixel on screen and z controls the render order.

1 Like
@pspeed said:
You do understand that they guiNode is not a node in the 3d scene, right?

It's the root node of an orthogonal 2D viewport that overlays the 3D scene. x,y locations of guiNode children are the x,y pixel on screen and z controls the render order.


Yes, I'm aware of that.

I was told in a previous thread that the way to add first person hands without clipping is to add them to the guiNode, hence why I tried attached it to 0,0,0, hoping that it'd at least show up, but that didn't work. The current position it's creating it at is because i'm clueless to as what to do.

Theoretically if attached the 3d model to the guiNode, it'd still appear 3d, correct?

I'm just confused to as why it's rendering itself in the middle of the ground of nowhere, and not on the gui, or not at all..
@koaandl said:
Yes, I'm aware of that.

I was told in a previous thread that the way to add first person hands without clipping is to add them to the guiNode, hence why I tried attached it to 0,0,0, hoping that it'd at least show up, but that didn't work. The current position it's creating it at is because i'm clueless to as what to do.

Theoretically if attached the 3d model to the guiNode, it'd still appear 3d, correct?

I'm just confused to as why it's rendering itself in the middle of the ground of nowhere, and not on the gui, or not at all..


Say you have an object that is 1 meter wide. Then you attach that to the guiNode at 0,0. It will be 1 pixel in the lower left of the screen. I doubt you will ever see it.

You can render 3D objects in the gui viewport but you need take all of this into consideration. The hands will never clip with the scene and they will be flattened (lose perspective).
1 Like

I’ve run into the scaling thing before, but what exactly am I doing wrong here that is causing them to render in the world, I mean how is it even possible if i’m attaching them to the guiNode?



What i’m trying to ask, is how do I get them to correctly attach to the guiNode and render on screen?



(also sorry if my previous post sounded snappy, I wasn’t sure how to word it correctly.)

a) how are you verifying that they are rendering in the world?



b) if they are rendering in the world then somewhere you are attaching them to the rootNode.



It is otherwise physically impossible for a guiNode child to render in the 3D scene. It must have been attached to the 3D scene somewhere.

1 Like

The picture in the OP shows they are rendering in the world, and I can’t find anywhere in my code where they would be attached to the root node,



Hence, I am utterly confused.



Edit:



The hands are attached to the guiNode here:



[java]Main.api.getGuiNode().attachChild(handsnode);[/java]



api is created here:



[java]public static void main(String[] args)

{

Main app = new Main();

app.start();

api = app;

}[/java]



The hand’s last indirect reference is here during loading:

[java]play.initPlayer(this);[/java]



You can check all my source, linked in the OP, but I cannot find ANYWHERE it’s connected and i’m absolutely stumped, how do I fix this?

Never mind, I did find a spot that I was attaching it to the rootNode (It was in the handsUpdate, no idea why I overlooked that… Derp.), moral of the story, never code at 2am without caffeine.



Now i’m just having the problem of the of the hands not appearing, no matter where I stick it/what scale on the GUI.

If they are using Lighting.j3md then you will need to add a light to the guiNode.

1 Like

Already one on there:



[java]public void setup_light()

{

playerlight.setDirection(new Vector3f(-.10f, -.10f, -.10f));

playerlight.setColor(ColorRGBA.White);

guilight.setColor(playerlight.getColor());

guilight.setDirection(playerlight.getDirection());

Main.api.getRootNode().addLight(playerlight);

Main.api.getGuiNode().addLight(guilight);

}[/java]

Things to try:

-normalize the direction of the light

-make sure your object is scaled up appropriately or it will generally only be one pixel in size.

-make sure your object is located within the screen bounds… or give it a test location of 100,100,0 temporarily.

1 Like

I have just tried all that and none of it worked;



I tried scales 1, 10, 100 and 1000, none of them had any visible effect, and I tried normalize and normalizeLocal on the light.



Setting the location of the handsnode to new Vector3f(100,100,0) had no visible effect, neither did setting it to new Vector3f(app.getGuiViewPort().getCamera().getWidth() / 2,app.getGuiViewPort().getCamera().getWidth() / 2,0).



I’ve got to be doing something wrong here…



Just to add additional information in case you haven’t looked at the source code, api is a static main variable declared in Main.java, declared in the block posted before, the other things (can’t thing of the name off hand right now, such as Main.play, Main.spawn) are also static, declared in Main.java like so:



[java]static gameinterface gi = new gameinterface();

static spawncontroller spawn = new spawncontroller();

static object_player play = new object_player();

static object_npc npcp = new object_npc();

static lighting_controller lights = new lighting_controller();

static terrain_control ter = new terrain_control();

static inventory_controller inventory = new inventory_controller();

static animation_helper anims = new animation_helper();

static Main api;

static consoleCommand cons = new consoleCommand();

static network_controller net = new network_controller();[/java]

I don’t know what else to suggest. If you can put together a simple test case then maybe someone else can spot the issue.

1 Like

I’m not sure if that would work or not, because I have a feeling I may have messed up somewhere else in my code, causing them to not render correctly.



All of my source code is linked up there, if anyone can find errors in that, but as for a test case, I’d be boned trying to make one. There is a compiled version of it on the Google code page, and all the assets/data for it to compile it, but beyond that, I think the error is probably wrapped up in my piles of bad code.

I don’t have time to go through your whole application to spot an error that you might easily spot if you created a simple test case.



There are two points to a test case:

  1. you might find that the test case works and now you have something to compare to your non-working code
  2. failing that, the rest of us have something much easier to look at and test. Maybe you’ve found a bug in JME but we’d never know without a test case.
1 Like

I can try, but It will be confusing for all of us, I’m horrible at cutting stuff down. :roll:

Start from scratch. Make a new main class and attach a 3D model to the guiNode. It could even by a JME box. It will still prove the point.

1 Like

Okay, I’ve made a test case, that loads things in the same order and attaches them, and still no cigar. Here it is (you can replace hands.j3o with any model or a box).



[java]package mygame;



import com.jme3.app.SimpleApplication;

import com.jme3.light.DirectionalLight;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.renderer.RenderManager;

import com.jme3.scene.Geometry;

import com.jme3.scene.Spatial;

import com.jme3.scene.shape.Box;



public class Main extends SimpleApplication {



static Main api;

Spatial hands;

Spatial handsnode;

DirectionalLight playerlight = new DirectionalLight();

DirectionalLight guilight = new DirectionalLight();



public void initHands()

{

playerlight.setDirection(new Vector3f(-.10f, -.10f, -.10f));

playerlight.setColor(ColorRGBA.White);

guilight.setColor(playerlight.getColor());

guilight.setDirection(playerlight.getDirection().normalize());

Main.api.getRootNode().addLight(playerlight);

Main.api.getGuiNode().addLight(guilight);

hands = Main.api.getAssetManager().loadModel(“Models/hands.j3o”);

hands.scale(10f);

Spatial temp = hands;

Material mat = new Material(api.getAssetManager(),“Common/MatDefs/Light/Lighting.j3md”);

mat.setBoolean(“UseMaterialColors”, true);

mat.setColor(“Diffuse”, ColorRGBA.Magenta);

mat.setColor(“Specular”, ColorRGBA.White);

mat.setFloat(“Shininess”, 12);

temp.setMaterial(mat);

temp.setLocalTranslation(new Vector3f(0,0,0));

handsnode = temp;

handsnode.setLocalTranslation(100,100,0);

Main.api.getGuiNode().attachChild(handsnode);

}



public static void main(String[] args)

{

Main app = new Main();

app.start();

api = app;

}



@Override

public void simpleInitApp()

{

initHands();

}



@Override

public void simpleUpdate(float tpf)

{

}



@Override

public void simpleRender(RenderManager rm)

{



}

}

[/java]



Sorry if it’s a page stretcher!

Okay, after more testing, I’ve found that in the configuration I have, i’m able to render a box (as geometry) on the guiNode, but I cant render any models (originally in obj form, converted to j3o, tried using both and casting to geometry). What is going on? 8O

Did you use lighting or unshaded for your box material? How big was the box?



It would be interesting to get this worked out but I think ultimately you will be disappointed. The limitations for rendering 3D objects in the guiNode are significant. You might have better luck creating another 3D viewport.

1 Like