有没有办法在 javafx 中显示 uv 从 meshview 到平面图?
Is there a way to show uv from meshview to flat drawing in javafx?
有没有办法像搅拌机一样在 gui 上显示 uv 坐标 blender uv?
显示 uv 坐标到路径
没有内置的 gui 对象,但我们可以创建一个带有路径的自定义对象。我们可以从网格对象中的 faces[]
中检索 uv 索引,并在 texcoords[]
中获取其值
这是您可以尝试的单个 javafx 应用程序。据我所知,没有办法从 Shape3D 对象获取网格实例,因此这仅适用于 meshview 对象中的 trianglefaces 自定义网格。我无法设置 mesh.fxml 因为它会溢出字符限制。
App.java
public class App extends Application {
@Override
public void start(Stage stage) throws IOException {
Image uvImage = new Image("/uv.jpg");
PerspectiveCamera pc = new PerspectiveCamera(true);
pc.setTranslateZ(-6);
MeshView mv = loadMeshView();
PhongMaterial pm = new PhongMaterial();
pm.setDiffuseMap(uvImage);
mv.setMaterial(pm);
Group group3d = new Group(pc, mv);
RotateTransition animation = new RotateTransition(Duration.seconds(4), mv);
animation.setInterpolator(Interpolator.LINEAR);
animation.setAxis(Rotate.Y_AXIS);
animation.setByAngle(360);
animation.setCycleCount(100);
animation.play();
SubScene subScene = new SubScene(group3d, 400, 400, true, SceneAntialiasing.BALANCED);
subScene.setFill(Color.AQUAMARINE);
subScene.setCamera(pc);
ImageView imageView = new ImageView(uvImage);
imageView.setFitHeight(400);
imageView.setFitWidth(400);
Group groupUv = new Group(imageView);
makeUvLines(groupUv, mv);
Text u = new Text("U");
Text v = new Text("V");
v.setTranslateY(200);
v.setTranslateX(-20);
u.setTranslateX(200);
u.setTranslateY(420);
Line uLine = new Line(0, 0, 0, 400);
Polygon uArrow = new Polygon(0, 0, 8, 8, -8, 8);
Polygon vArrow = new Polygon(400, 400, 392, 408, 392, 392);
Line vLine = new Line(0, 400, 400, 400);
Pane ap = new Pane(groupUv, uLine, vLine, uArrow, vArrow, u, v);
ap.setPrefSize(400, 400);
ap.setMaxSize(400, 400);
ap.setStyle("-fx-background-color:yellow");
HBox.setHgrow(ap, Priority.NEVER);
HBox hb = new HBox(subScene, ap);
hb.setSpacing(30);
hb.setAlignment(Pos.CENTER);
var scene = new Scene(hb, 800, 600);
stage.setTitle("JavaFX UV Visualizer");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
private void makeUvLines(Group groupUv, MeshView meshView) {
TriangleMesh mesh = (TriangleMesh) meshView.getMesh();
int[] faces = mesh.getFaces().toArray(new int[mesh.getFaces().size()]);
float[] texCoords = mesh.getTexCoords().toArray(new float[mesh.getTexCoords().size()]);
for (int i = 0; i < faces.length; i++) {
float scale = 400;
float startU = texCoords[2 * faces[i + 1]];
float startV = texCoords[((2 * faces[i + 1]) + 1)];
float u1 = texCoords[2 * faces[i + 3]];
float v1 = texCoords[((2 * faces[i + 3]) + 1)];
float endU = texCoords[2 * faces[i + 5]];
float endV = texCoords[((2 * faces[i + 5]) + 1)];
Path p = new Path(
new MoveTo(startU * scale, startV * scale),
new LineTo(u1 * scale, v1 * scale),
new LineTo(endU * scale, endV * scale),
new ClosePath()
);
p.setStroke(Color.ORANGE);
p.setFill(Color.color(0.1, 0.3, 0.1, 0.7));
groupUv.getChildren().add(p);
i += 5;
}
}
private MeshView loadMeshView() throws IOException {
FXMLLoader loader = new FXMLLoader(App.class.getResource("/mesh.fxml"));
loader.load();
MeshView meshView = loader.getRoot();
return meshView;
}
}
uv.jpg
有没有办法像搅拌机一样在 gui 上显示 uv 坐标 blender uv?
显示 uv 坐标到路径
faces[]
中检索 uv 索引,并在 texcoords[]
这是您可以尝试的单个 javafx 应用程序。据我所知,没有办法从 Shape3D 对象获取网格实例,因此这仅适用于 meshview 对象中的 trianglefaces 自定义网格。我无法设置 mesh.fxml 因为它会溢出字符限制。
App.java
public class App extends Application {
@Override
public void start(Stage stage) throws IOException {
Image uvImage = new Image("/uv.jpg");
PerspectiveCamera pc = new PerspectiveCamera(true);
pc.setTranslateZ(-6);
MeshView mv = loadMeshView();
PhongMaterial pm = new PhongMaterial();
pm.setDiffuseMap(uvImage);
mv.setMaterial(pm);
Group group3d = new Group(pc, mv);
RotateTransition animation = new RotateTransition(Duration.seconds(4), mv);
animation.setInterpolator(Interpolator.LINEAR);
animation.setAxis(Rotate.Y_AXIS);
animation.setByAngle(360);
animation.setCycleCount(100);
animation.play();
SubScene subScene = new SubScene(group3d, 400, 400, true, SceneAntialiasing.BALANCED);
subScene.setFill(Color.AQUAMARINE);
subScene.setCamera(pc);
ImageView imageView = new ImageView(uvImage);
imageView.setFitHeight(400);
imageView.setFitWidth(400);
Group groupUv = new Group(imageView);
makeUvLines(groupUv, mv);
Text u = new Text("U");
Text v = new Text("V");
v.setTranslateY(200);
v.setTranslateX(-20);
u.setTranslateX(200);
u.setTranslateY(420);
Line uLine = new Line(0, 0, 0, 400);
Polygon uArrow = new Polygon(0, 0, 8, 8, -8, 8);
Polygon vArrow = new Polygon(400, 400, 392, 408, 392, 392);
Line vLine = new Line(0, 400, 400, 400);
Pane ap = new Pane(groupUv, uLine, vLine, uArrow, vArrow, u, v);
ap.setPrefSize(400, 400);
ap.setMaxSize(400, 400);
ap.setStyle("-fx-background-color:yellow");
HBox.setHgrow(ap, Priority.NEVER);
HBox hb = new HBox(subScene, ap);
hb.setSpacing(30);
hb.setAlignment(Pos.CENTER);
var scene = new Scene(hb, 800, 600);
stage.setTitle("JavaFX UV Visualizer");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
private void makeUvLines(Group groupUv, MeshView meshView) {
TriangleMesh mesh = (TriangleMesh) meshView.getMesh();
int[] faces = mesh.getFaces().toArray(new int[mesh.getFaces().size()]);
float[] texCoords = mesh.getTexCoords().toArray(new float[mesh.getTexCoords().size()]);
for (int i = 0; i < faces.length; i++) {
float scale = 400;
float startU = texCoords[2 * faces[i + 1]];
float startV = texCoords[((2 * faces[i + 1]) + 1)];
float u1 = texCoords[2 * faces[i + 3]];
float v1 = texCoords[((2 * faces[i + 3]) + 1)];
float endU = texCoords[2 * faces[i + 5]];
float endV = texCoords[((2 * faces[i + 5]) + 1)];
Path p = new Path(
new MoveTo(startU * scale, startV * scale),
new LineTo(u1 * scale, v1 * scale),
new LineTo(endU * scale, endV * scale),
new ClosePath()
);
p.setStroke(Color.ORANGE);
p.setFill(Color.color(0.1, 0.3, 0.1, 0.7));
groupUv.getChildren().add(p);
i += 5;
}
}
private MeshView loadMeshView() throws IOException {
FXMLLoader loader = new FXMLLoader(App.class.getResource("/mesh.fxml"));
loader.load();
MeshView meshView = loader.getRoot();
return meshView;
}
}
uv.jpg