I have some sample code which goes something like this:
Font f = new Font("Times New Roman", Font.PLAIN, 12);
app.setAttribute("textShader.font", f);
ifsf.setFaceLabels(labels); //ifsf is an IndexedFaceSet, labels is an array of Strings
This approach works fine if I want a text label for every vertex or edge or face, but for complex objects with hundreds or thousands of vertices, this is more than what is needed. Do you have any sample code showing how to position text at arbitrary locations in the scene (i.e. not tied to each vertex of an IndexedFaceSet object)?
Thanks again for all your help!
Geoff
displaying text
There is no standard moethod for adding text to a scene right now.
If you want billboarded text (allways oriented towards the camera) then the default solution would be to make a PointSet with just one vertex at (0,0,0) (or two or three if you want more text...:-) ) and a label for it.
If you don't want the billboarding you can make a texture image from a string with methods in de.jreality.backends.label.LabelUtility and texture a rectangle with it (I think there are methods for that as well...but I don't remember rigth now)
Tim
If you want billboarded text (allways oriented towards the camera) then the default solution would be to make a PointSet with just one vertex at (0,0,0) (or two or three if you want more text...:-) ) and a label for it.
If you don't want the billboarding you can make a texture image from a string with methods in de.jreality.backends.label.LabelUtility and texture a rectangle with it (I think there are methods for that as well...but I don't remember rigth now)
Tim
Re: displaying text
Edit: Ah I was too slow ;-)
Hi Geoff,
We have no labels on geometry level. The easiest way would be a PointSet with one vertex, and setting the vertex color to transparent:
Then you can set the alignment to "center" and use the text shader's offset to keep the label in front of your geometry:
It is also possible to create a texture from the string and render a quad with this texture. But then you have no billboarding. If you want to try that version I'll post the code.
Bye, Steffen.
Hi Geoff,
We have no labels on geometry level. The easiest way would be a PointSet with one vertex, and setting the vertex color to transparent:
Code: Select all
PointSetFactory psf = new PointSetFactory();
psf.setVertexCount(1);
psf.setVertexCoordinates(new double[]{0,0,0});
psf.setVertexColors(new double[]{0,0,0,0});
psf.setVertexLabels(new String[]{"my label"});
psf.update();
cmp.setGeometry(psf.getPointSet();
Code: Select all
app.setAttribute("pointShader.textShader.alignment", SwingConstants.CENTER);
app.setAttribute("pointShader.textShader.offset", new double[]{offx, offy, offz});
Bye, Steffen.
Hi Geoff,
the code to create a label by hand:
If you want to display more text than a simple label then a swing text area might make more sense. Then you can format the text with HTML - I think the above example doesn't render text with more than one line.
Steffen.
the code to create a label by hand:
Code: Select all
// create the image
Font f = new Font("Sans Serif", Font.PLAIN, 24);
Image img = LabelUtility.createImageFromString("label text", f, Color.blue);
Appearance app = new Appearance();
app.setAttribute("showPoints", false);
// otherwise there is a black border around the letters
app.setAttribute("transparencyEnabled", true);
// create the texture
Texture2D tex = TextureUtility.createTexture(app, "polygonShader", new ImageData(img));
// display it on a quad
SceneGraphComponent cmp = new SceneGraphComponent();
MatrixBuilder.euclidean().rotateX(Math.PI).assignTo(cmp);
IndexedLineSet quad = Primitives.plainQuadMesh(0.01*img.getWidth(null), 0.01*img.getHeight(null),1,1);
cmp.setAppearance(app);
cmp.setGeometry(quad);
ViewerApp.display(cmp);
Steffen.