简体   繁体   English

JavaFX 3D文字旋转

[英]JavaFX 3D text rotation

I am a newcomer to javaFX-3D and I want to view simple 3D shapes with labels, such as node numbers etc. I've started from oracle's MoleculeSampleApp and I am trying to add text. 我是javaFX-3D的新手,我想查看带有标签的简单3D形状,例如节点号等。我从oracle的MoleculeSampleApp开始,并且尝试添加文本。 Thus far I have arrived at this: 到目前为止,我已经得出以下结论:

Axes with text 带有文字的轴

The text has been added as follows: 文本已添加如下:

     Text t = new Text("Hello world");
     t.setFont(Font.font("Calibri", FontWeight.BOLD, 30));
     t.translateXProperty().set(125 + 10);
     t.translateYProperty().set(125 + 10);
     t.translateZProperty().set(125+10);
     Xform from = new Xform();
     from.getChildren().add(t);
     from.setRotateX(180);
     world.getChildren().add(from);

As soon as I start rotating the view, the text also flips all over and it becomes unreadable. 当我开始旋转视图时,文本也会翻转过来,变得不可读。 Is there a way to make the text not rotate in all directions? 有没有一种方法可以使文本不向各个方向旋转? Ideally the text should always be displayed like normal "2D" text, while moving along with its associated 3D object as the view is adjusted (zoom, rotate, etc.). 理想情况下,在调整视图(缩放,旋转等)时,文本应始终像普通的“ 2D”文本一样显示,同时与其关联的3D对象一起移动。

After a while I settled on using Tooltips instead. 一段时间后,我决定改用工具提示。 This is not exactly what I had in mind but it displays the text correctly when the mouse hovers over the Shape. 这与我的想法不完全相同,但是当鼠标悬停在Shape上时,它可以正确显示文本。 An example is as follows: 示例如下:

Sphere ball= new Sphere(30/2);
Tooltip t = new Tooltip(tooltip);
            Tooltip.install(ball, t);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM