Attach text to rootNode

I have three axes drawn (X, Y, Z). I want to add labels to that axes denoting name of an axis. Are there any way to attach text to pivot node, so it will change its position when user rotates camera, but text itself is not rotated and always visible to user, it just changes its position to follow rotated axis?



I thought about adding mouse motion listener. In that listener I would update text position (convert vertex coordinates to screen coordinates and change text position in the gui node). But that sounds a bit difficult.



I wonder are there simpler way?

I think you want BillboardControl.

I tried following



[java]Node pivot = new Node("pivot");

BitmapFont font = assetManager.loadFont("Interface/Fonts/Default.fnt");

BitmapText text = new BitmapText(font, false);

text.setLocalTranslation(0, 1, 0);

text.setText("Text");

text.addControl(new BillboardControl());

pivot.attachChild(text);

rootNode.attachChild(pivot);

[/java]



However I can not see text. What am I doing wrong?

could be your text and background are the same color?

I have the same code (almost)



[java]BitmapFont font = assetManager.loadFont("Interface/Fonts/Default.fnt");

BitmapText text = new BitmapText(font, false);

text.setLocalTranslation(0.0F, text.getLineHeight(), 0.0F);

text.setText("Text");

guiNode.attachChild(text);[/java]



And it is visible

your attaching that to the guiNode tho

I explained in the first message why I need to attach text to guiNode.

misha-nesterenko said:
I tried following

[java]Node pivot = new Node("pivot");
BitmapFont font = assetManager.loadFont("Interface/Fonts/Default.fnt");
BitmapText text = new BitmapText(font, false);
text.setLocalTranslation(0, 1, 0);
text.setText("Text");
text.addControl(new BillboardControl());
pivot.attachChild(text);
rootNode.attachChild(pivot);
[/java]

However I can not see text. What am I doing wrong?


The text is probably edge on to the camera. You could maybe put the billboard control on the pivot and then rotate the text geometry 90 degrees about the X axis.

I have similar code that I can look up if that still gives you trouble... but I don't have it handy at the moment.

I have removed BillboardControl, I presume text should be placed in XY plane? But there is no text, I rotated camera to see if it is culled , but it did not appear.



[java]

import com.jme3.app.SimpleApplication;

import com.jme3.font.BitmapFont;

import com.jme3.font.BitmapText;

import com.jme3.input.ChaseCamera;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.FastMath;

import com.jme3.math.Quaternion;

import com.jme3.math.Vector3f;

import com.jme3.scene.Geometry;

import com.jme3.scene.Node;

import com.jme3.scene.Spatial.CullHint;

import com.jme3.scene.debug.Arrow;

import com.jme3.scene.shape.Quad;



public class LightApp extends SimpleApplication {

public static Geometry axis;

@Override

public void simpleInitApp() {

this.flyCam.setEnabled(false);

this.statsView.setCullHint(CullHint.Always);

this.fpsText.setCullHint(CullHint.Always);



Node pivot = new Node("pivot");



{

Arrow normalX = new Arrow(new Vector3f(3, 0, 0));

normalX.setLineWidth(3);

Arrow normalY = new Arrow(new Vector3f(0, 3, 0));

normalY.setLineWidth(3);

Arrow normalZ = new Arrow(new Vector3f(0, 0, 3));

normalZ.setLineWidth(3);



Material normalMaterialX = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

normalMaterialX.setColor("Color", ColorRGBA.Green);

Material normalMaterialY = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

normalMaterialY.setColor("Color", ColorRGBA.Blue);

Material normalMaterialZ = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

normalMaterialZ.setColor("Color", ColorRGBA.Yellow);



Geometry normalGeometryX = axis = new Geometry("normal", normalX);

normalGeometryX.setMaterial(normalMaterialX);

Geometry normalGeometryY = axis = new Geometry("normal", normalY);

normalGeometryY.setMaterial(normalMaterialY);

Geometry normalGeometryZ = axis = new Geometry("normal", normalZ);

normalGeometryZ.setMaterial(normalMaterialZ);



pivot.attachChild(normalGeometryX);

pivot.attachChild(normalGeometryY);

pivot.attachChild(normalGeometryZ);

}



{

BitmapFont font = assetManager.loadFont("Interface/Fonts/Default.fnt");

BitmapText text = new BitmapText(font, false);

text.setLocalRotation(new Quaternion().fromAngleAxis(-10 * FastMath.DEG_TO_RAD, Vector3f.UNIT_Y));

text.setText("Text");

text.setCullHint(CullHint.Never);



pivot.attachChild(text);

}



{

Quad surface = new Quad(15, 15);

Material surfaceMaterial = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

surfaceMaterial.setColor("Color", ColorRGBA.Red);



Geometry surfaceGeometry = new Geometry("surface", surface);

surfaceGeometry.setMaterial(surfaceMaterial);

surfaceGeometry.setLocalTranslation(0, 0, -1);

//surfaceGeometry.setLocalRotation(new Quaternion().fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_Y));



pivot.attachChild(surfaceGeometry);

}



rootNode.attachChild(pivot);



ChaseCamera chaseCam = new ChaseCamera(cam, pivot, inputManager);

chaseCam.setInvertVerticalAxis(true);

chaseCam.setSmoothMotion(true);

chaseCam.setMinDistance(5);

chaseCam.setMinVerticalRotation(0.3f);

chaseCam.setDefaultHorizontalRotation(FastMath.HALF_PI);

chaseCam.setDefaultVerticalRotation(0*FastMath.DEG_TO_RAD);

}



public static void main(String[] args) {

LightApp app = new LightApp();

app.start();

}



}

[/java]

What version of JME are you running?

3.0.0-SNAPSHOT from maven repo

I don’t know how old that is.



You can try specifically putting the bitmap text into the “Inherit” bucket. I think in alpha 4 that BitmapText always put itself in the Gui bucket even if it wasn’t on the GUI node… which is unneeded anyway since the guiNode is already in the Gui bucket. :stuck_out_tongue:

1 Like

Thank you very much! adding to Inherit bucket helped.

Good to know. FYI, this issue was fixed about five months ago or so in case you find a way to upgrade.

Yeah, that maven repo isn’t official, it was set up by some user and is now apparently abandoned as I predicted. There will be no official maven repo, ever.

normen said:
Yeah, that maven repo isn't official, it was set up by some user and is now apparently abandoned as I predicted. There will be no official maven repo, ever.

Heh, why?

no holywar, just interesting

Cause we don’t use maven and it means work maintaining it, its easy to use jars, svn or whatever in maven without expecting every java library to have a maven repository. So basically for the same reason you don’t use OSGI packages or ANT I guess.

Unless you can somehow suggest a way for us to support maven while keeping our setup or somehow keep it automatically maintained … Don’t think it is possible