如何使用两种颜色填充JavaFX球体

编程入门 行业动态 更新时间:2024-10-10 11:21:17
本文介绍了如何使用两种颜色填充JavaFX球体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何使用线性渐变填充JavaFX 3D球体,如2D圆? 我使用JavaFX Scene Builder。

>

根据你的第一张图片,我创建了这个纹理图片 diffuse.jpg ,并放置在与JavaFX类相同的文件夹下):

您现在可以创建彩色球体:

@Override public void start(Stage primaryStage)throws Exception { // 3D 球面球=新球体(5); PhongMaterial phongMaterial = new PhongMaterial(); phongMaterial.setDiffuseMap(new Image(getClass()。getResource(diffuse.jpg)。toExternalForm())); sphere.setMaterial(phongMaterial); ... }

所以你会看到:

请注意,您可能对杆子有一些副作用。

您还可以看一下 FXyz 项目,一个带有JavaFX 3D复杂形状的库以及复杂的纹理选项。

例如,您可以使用密度图创建所需的相同效果,但不提供纹理图像。

在 org / fxyz / shape / primitives ,您可以找到像 SegmentedSphereMesh 的几个原语。

像球体一样,你可以创建一个给出分割数,裁剪分割(在这种情况下为0和x和y),radiuos和中心: / p>

SegmentedSphereMesh sphere = new SegmentedSphereMesh(200,0,0,100,new Point3D(0f,0f,0f));

现在您可以定义函数:

函数< Point3D,Number>密度= p-> p.y>0≤1:0;

并应用它,颜色数量(本例中为2):

sphere.setTextureModeVertices3D(2,dens);

现在您将拥有:

现在你不会有

请注意,您可以添加创建自己的颜色调色板或使用HSB功能播放 org / fxyz / utils / Palette 。

How can I fill in JavaFX a 3D Sphere with a linear gradient like a 2d Circle? I work with the JavaFX Scene Builder.

解决方案

As @mohsenmadi has pointed out, the diffuse color doesn't allow you using other than one single color.

But you can have different colors on the sphere by using an image as a diffuse map.

Based on your first image, I've created this texture image (called diffuse.jpg, and placed under the same folder as the JavaFX class):

You can create now your bicolored sphere:

@Override public void start(Stage primaryStage) throws Exception { // 3D Sphere sphere = new Sphere(5); PhongMaterial phongMaterial = new PhongMaterial(); phongMaterial.setDiffuseMap(new Image(getClass().getResource("diffuse.jpg").toExternalForm())); sphere.setMaterial(phongMaterial); ... }

So you will see this:

Note that you may have some side effects on the poles.

You can also have a look at the FXyz project, a library with aditional JavaFX 3D complex shapes, and also complex texture options.

For instance, you can use a density map to create the same effect you want, but without providing the texture image.

Under org/fxyz/shapes/primitives you can find several primitives like SegmentedSphereMesh.

Like an sphere you can create one giving the number of divisions, the crop divisions (0 in this case for x and y), the radiuos, and the center:

SegmentedSphereMesh sphere = new SegmentedSphereMesh(200,0,0,100,new Point3D(0f,0f,0f));

Now you can define the function:

Function<Point3D, Number> dens = p->p.y>0?1:0;

and apply it, with the number of colors (2 in this case):

sphere.setTextureModeVertices3D(2,dens);

Now you will have this:

Now you won't have side effects on the poles, and you could modify this function easily to other cases.

Note that you can add create your own palette of colors or play with the HSB function under org/fxyz/utils/Palette.

更多推荐

如何使用两种颜色填充JavaFX球体

本文发布于:2023-11-28 21:55:31,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:球体   两种   如何使用   颜色   JavaFX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!