我如何在 javafx 中单击按钮时显示 3d 形状
how do i display a 3d shape on button click in javafx
我的一个个人项目,用于我的编程 class 并将在稍后发布,我遇到了一个我没想到会遇到的问题。我想在单击菜单按钮项时在窗格中显示 3d 形状,我在互联网上搜索了 50-100 种不同的方式(或一个很好的粗略估计),但没有找到任何东西。我对如何在单击菜单项时显示 3d 形状感到困惑,这是我的源代码 (fxml):
<MenuButton layoutX="14.0" layoutY="92.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="72.0" text="shapes">
<items>
<MenuItem mnemonicParsing="false" onAction="#itemcircle" text="circle" />
<MenuItem mnemonicParsing="false" onAction="#itemsquare" text="square/surfice" />
<MenuItem mnemonicParsing="false" onAction="#itemcube" text="cube" />
<MenuItem mnemonicParsing="false" onAction="#itemsphere" text="sphere" />
<MenuItem mnemonicParsing="false" onAction="#itemcyllinder" text="cyllinder" />
</items>
</MenuButton>
我的其他源代码示例(javaFX):
public void itemcyllinder(ActionEvent cyllinderspawn)
{
Cylinder cylinder = new Cylinder(40, 120);
cylinder.setTranslateX(500);
cylinder.setTranslateY(-25);
cylinder.setTranslateZ(600);
}
那么如何使用 javafx/fxml 显示 3d shapes/objects?
编辑:我忘了说我想让它显示在我场景的窗格中
我没试过,但我会尝试在菜单项的 SubScene, and set that as the graphic property 上创建 3D 场景。
编辑: 以为您想将 3D 场景设置为菜单项的图形。无论如何,要混合 2D 和 3D,您需要创建子场景。
我找到了答案,这就是我需要用圆柱体做的所有事情:
public void itemcyllinder(ActionEvent cyllinderspawn)
{
Cylinder cylinder = new Cylinder(40, 120);
cylinder.setTranslateX(368.0);
cylinder.setTranslateY(311.0);
whereitgoes.getChildren().add(cylinder);
}
我调用了我的窗格,然后我只是使用 getChildren 在窗格中显示了圆柱体,我调用了菜单按钮项单击的位置(抱歉,我无法提供图片示例)
我的一个个人项目,用于我的编程 class 并将在稍后发布,我遇到了一个我没想到会遇到的问题。我想在单击菜单按钮项时在窗格中显示 3d 形状,我在互联网上搜索了 50-100 种不同的方式(或一个很好的粗略估计),但没有找到任何东西。我对如何在单击菜单项时显示 3d 形状感到困惑,这是我的源代码 (fxml):
<MenuButton layoutX="14.0" layoutY="92.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="72.0" text="shapes">
<items>
<MenuItem mnemonicParsing="false" onAction="#itemcircle" text="circle" />
<MenuItem mnemonicParsing="false" onAction="#itemsquare" text="square/surfice" />
<MenuItem mnemonicParsing="false" onAction="#itemcube" text="cube" />
<MenuItem mnemonicParsing="false" onAction="#itemsphere" text="sphere" />
<MenuItem mnemonicParsing="false" onAction="#itemcyllinder" text="cyllinder" />
</items>
</MenuButton>
我的其他源代码示例(javaFX):
public void itemcyllinder(ActionEvent cyllinderspawn)
{
Cylinder cylinder = new Cylinder(40, 120);
cylinder.setTranslateX(500);
cylinder.setTranslateY(-25);
cylinder.setTranslateZ(600);
}
那么如何使用 javafx/fxml 显示 3d shapes/objects?
编辑:我忘了说我想让它显示在我场景的窗格中
我没试过,但我会尝试在菜单项的 SubScene, and set that as the graphic property 上创建 3D 场景。
编辑: 以为您想将 3D 场景设置为菜单项的图形。无论如何,要混合 2D 和 3D,您需要创建子场景。
我找到了答案,这就是我需要用圆柱体做的所有事情:
public void itemcyllinder(ActionEvent cyllinderspawn)
{
Cylinder cylinder = new Cylinder(40, 120);
cylinder.setTranslateX(368.0);
cylinder.setTranslateY(311.0);
whereitgoes.getChildren().add(cylinder);
}
我调用了我的窗格,然后我只是使用 getChildren 在窗格中显示了圆柱体,我调用了菜单按钮项单击的位置(抱歉,我无法提供图片示例)