java 3d开发_java 如何开发3d可视化

本文介绍如何使用Java 8以上的JavaFX 3D特性来实现3D可视化。通过一个简单的Cylinder对象演示,展示了如何设置3D材质、旋转属性,并利用SubScene进行展示。代码中包含一个滑块来控制3D对象的旋转角度,提供了一种交互式的3D体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

展开全部

Java 8以上版本, 可以32313133353236313431303231363533e4b893e5b19e31333365656636尝试JavaFX 3D 来实现

效果图

800ced3655c81ae3a40990f9cba3efe2.gif

下面是模仿的Oracal 的Demo写的一个3D代码import javafx.application.Application;

import javafx.application.ConditionalFeature;

import javafx.application.Platform;

import javafx.geometry.Point3D;

import javafx.scene.Group;

import javafx.scene.Node;

import javafx.scene.PerspectiveCamera;

import javafx.scene.Scene;

import javafx.scene.SceneAntialiasing;

import javafx.scene.SubScene;

import javafx.scene.control.Alert;

import javafx.scene.control.Alert.AlertType;

import javafx.scene.control.Slider;

import javafx.scene.layout.HBox;

import javafx.scene.paint.Color;

import javafx.scene.paint.PhongMaterial;

import javafx.scene.shape.Cylinder;

import javafx.stage.Stage;

public class A07_SubScene extends Application{

public static void main(String[] args) {

launch(args);

}

@Override

public void start(Stage primaryStage) throws Exception {

if(!Platform.isSupported(ConditionalFeature.SCENE3D)) {

Alert alert=new Alert(AlertType.ERROR,"不支持JavaFX SCENE3D!~");

alert.showAndWait();

Platform.exit();

}

Group root=new Group();

Scene scene = new Scene(root,500,500,Color.ALICEBLUE);

HBox hbox=new HBox();

hbox.setLayoutX(60);

hbox.setLayoutY(70);

//创建圆柱体

Cylinder cl=new Cylinder(90,180);

PhongMaterial phongMaterial = new PhongMaterial(Color.color(1.0, 0.7, 0.8));

cl.setMaterial(phongMaterial);

SubScene sub=getSub(cl);

hbox.getChildren().add(sub);

Slider slider=new Slider(0, 360, 0);

slider.setLayoutX(170);

slider.setLayoutY(360);

cl.rotateProperty().bind(slider.valueProperty());

root.getChildren().addAll(hbox,slider);

primaryStage.setScene(scene);

primaryStage.setTitle("SubScene");

primaryStage.show();

}

private SubScene getSub(Node node) {

Group root=new Group();

node.setRotationAxis(new Point3D(2, 1, 0));

node.setTranslateX(180);

node.setTranslateY(150);

root.getChildren().add(node);

SubScene sub=new SubScene(root, 360, 400, true, SceneAntialiasing.BALANCED);

sub.setCamera(new PerspectiveCamera());

return sub;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值