Hi everybody,
another solution for my Text2D problem is to place 2 labels above each
other for one point and attach the billboard behavior to the point.
The problem there is, that I need the height of the labels.
The following code piece creates my Text2D objects with 50 point
size, places them somewhere in the virtual world and scales them with a
factor of 100, so that user can even see them if the viewing platform
moves back. This is necessary, because I have several points with labels,
which should be seen at the same time in the view together with the
labels.
// Text object
Text2D text2D = new Text2D(string[i],new
Color3f(1.0f,0.0f,0.0f),"Helvetica",50,Font.PLAIN);
text2D.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
text2D.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
// Appearance
Appearance textApp = text2D.getAppearance();
textApp.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
textApp.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
textApp.setCapability(Appearance.ALLOW_MATERIAL_WRITE);
textApp.setCapability(Appearance.ALLOW_MATERIAL_READ);
textApp.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_READ);
textApp.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE);
textApp.setCapability(Appearance.ALLOW_TEXTURE_READ);
ColoringAttributes colatt = new
ColoringAttributes(1.0f,0.0f,0.0f,ColoringAttributes.SHADE_GOURAUD);
colatt.setCapability(ColoringAttributes.ALLOW_COLOR_READ);
colatt.setCapability(ColoringAttributes.ALLOW_COLOR_WRITE);
textApp.setColoringAttributes(colatt);
Color3f black = new Color3f(0.0f,0.0f,0.0f);
Color3f red = new Color3f(1.0f,0.0f,0.0f);
Material material = new Material(red,black,red,black,10f);
material.setCapability(Material.ALLOW_COMPONENT_READ);
material.setCapability(Material.ALLOW_COMPONENT_WRITE);
textApp.setMaterial(material);
PolygonAttributes polyAttrib = new PolygonAttributes();
polyAttrib.setCullFace(PolygonAttributes.CULL_NONE);
polyAttrib.setBackFaceNormalFlip(true);
textApp.setPolygonAttributes(polyAttrib);
text2D.setAppearance(textApp);
// Create Scenegraph TransformGroups
TransformGroup textToWorldPlaceTG = new TransformGroup();
Transform3D worldPlaceTransform3D = new Transform3D();
TransformGroup scaleTG = new TransformGroup();
Transform3D scalet3d = new Transform3D();
TransformGroup tgr = new TransformGroup();
tgr.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
// These are needed for billboard behavior
Billboard billboard = new Billboard(tgr);
BoundingSphere bSphere = new BoundingSphere(new
Point3d(),Float.MAX_VALUE);
billboard.setSchedulingBounds(bSphere);
// Do transformations
// Place labels above other labels
if (align == TextLayer3D.ALIGN_LAST) {
System.out.println("texture 1.5
"+text2D.getAppearance().getTexture().getHeight());
heightValues[i]=heightValues[i]+text2D.getAppearance().getTexture().getHeight()/3f;
}
// Set the objects to the place in the virtual universe
// For height scale, scale height values
if (scale == true) {
worldPlaceTransform3D.set(new
Vector3f(eastValues[i],heightScale[i],-northValues[i]));
}
else {
worldPlaceTransform3D.set(new
Vector3f(eastValues[i],heightValues[i],-northValues[i]));
}
textToWorldPlaceTG.setTransform(worldPlaceTransform3D);
// Scale text. It must be a lot bigger to be seen in the
// virtual universe
scalet3d.setScale(new Vector3d(100,100,100));
scaleTG.setTransform(scalet3d);
// build scenegraph
textToWorldPlaceTG.addChild(billboard);
scaleTG.addChild(tgr);
tgr.addChild(text2D);
textToWorldPlaceTG.addChild(scaleTG);
this.addChild(textToWorldPlaceTG);
How can I find the height of the Text2D object. I tried
Font.getSize() returns 0
Font.getSize2D() returns 0
and
text2D.getAppearance().getTexture().getHeight() returns 64 with Helvetica
and Pointsize 50.
However I tested it 64 is to big, I am looking for something around 20.
And I have scaled my Text2D with a factor of 100, so 64 would be much to
big. I am looking for a way to determine the height of the Text2D. And the
user should have the possibility to influence the scale factor.
Please help me, thanks Desiree
o------------------------------------------------------------------------o
| Desiree Hilbring Institut fuer Photogrammetrie und Fernerkundung |
| Universitaet Karlsruhe, Germany |
| |
| email: [EMAIL PROTECTED] |
| # 0721 6083676 |
o------------------------------------------------------------------------o
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".