Don't know if anyone answered this already, but here's how I handled
it (in a subclass of TransformGroup):
{
TransformGroup labelTG = new TransformGroup();
labelTG.setCapability(labelTG.ALLOW_TRANSFORM_WRITE);
Transform3D topTransform = new Transform3D();
getTransform(topTransform);
Text2D label = new Text2D(getTarget().getLabelString(),
new Color3f(1f, 1f, 1f), "Courier",
14, Font.PLAIN);
GeometryArray ga = (GeometryArray) label.getGeometry();
Point3f center = getCenter(ga);
Vector3f centerTranslation = new Vector3f(-center.x, 0, 0);
Vector3f currentTranslation = new Vector3f();
Vector3f offsetTranslation = new
Vector3f(getTarget().getLabelOffset());
topTransform.get(currentTranslation);
currentTranslation.add(centerTranslation);
currentTranslation.add(offsetTranslation);
topTransform.setTranslation(currentTranslation);
setTransform(topTransform);
Billboard billboard = new Billboard(labelTG,
Billboard.ROTATE_ABOUT_POINT,
new Point3f(center.x,
center.y, 0));
billboard.setSchedulingBounds(new BoundingSphere(new Point3d(),
1000.0));
addChild(billboard);
labelTG.addChild(label);
addChild(labelTG);
}
The utility method getCenter:
float [] mins = new float[3];
float [] maxs = new float[3];
float [] curr = new float[3];
public Point3f getCenter(GeometryArray geomArray) {
if((geomArray == null) || geomArray.getVertexCount() == 0)
return null;
geomArray.getCoordinate(0, mins);
geomArray.getCoordinate(0, maxs);
for (int i = 1; i < geomArray.getVertexCount(); i++) {
geomArray.getCoordinate(i, curr);
if (curr[0] < mins[0]) {mins[0] = curr[0];}
if (curr[0] > maxs[0]) {maxs[0] = curr[0];}
if (curr[1] < mins[1]) {mins[1] = curr[1];}
if (curr[1] > maxs[1]) {maxs[1] = curr[1];}
if (curr[2] < mins[2]) {mins[2] = curr[2];}
if (curr[2] > maxs[2]) {maxs[2] = curr[2];}
}
return new Point3f((maxs[0] + mins[0]) / 2, (maxs[1] + mins[1]) /
2,
(maxs[2] + mins[2]) / 2);
}
Hope it helps.
-Brian
--- Saurabh Akhauri <[EMAIL PROTECTED]> wrote:
> I am trying to add 2D text as annotation to a 3D part.
> If i add same behaviour to both and try to rotate the part, the
> text also
> rotates with the part and looks distorted/vanishes.
>
> Is there some way by which the 2D text always remains at same plane
>
> and adjusts its position relative to the 3D part's rotation /
> translation / zoom
> on the screen.
>
> Basically i want to have behaviour of the 2D text effected by the
> behaviour of 3D body.
>
> saurabh
>
__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices.
http://auctions.yahoo.com/
===========================================================================
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".