- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 phongmaterial 将图像应用到我的 meshview 立方体,但屏幕上只显示没有颜色的黑色立方体。它曾经与 Box 和立方体一起工作,但现在也不能与它们一起工作。
还有,谁能告诉我如何获得特定立方体的面??
这是我的代码:
Rotate rxBox = new Rotate(30, 0, 0, 0, Rotate.X_AXIS);
Rotate ryBox = new Rotate(50, 0, 0, 0, Rotate.Y_AXIS);
Rotate rzBox = new Rotate(30, 0, 0, 0, Rotate.Z_AXIS);
@Override
public void start(Stage primaryStage) {
float hw = 100/2f;
float hh = 100/2f;
float hd = 100/2f;
float points[] = {
hw, hh, hd,
hw, hh, -hd,
hw, -hh, hd,
hw, -hh, -hd,
-hw, hh, hd,
-hw, hh, -hd,
-hw, -hh, hd,
-hw, -hh, -hd};
float tex[] = {
100, 0,
200, 0,
0, 100,
100, 100,
200, 100,
300, 100,
400, 100,
0, 200,
100, 200,
200, 200,
300, 200,
400, 200,
100, 300,
200, 300};
int faces[] = {
0, 10, 2, 5, 1, 9,
2, 5, 3, 4, 1, 9,
4, 7, 5, 8, 6, 2,
6, 2, 5, 8, 7, 3,
0, 13, 1, 9, 4, 12,
4, 12, 1, 9, 5, 8,
2, 1, 6, 0, 3, 4,
3, 4, 6, 0, 7, 3,
0, 10, 4, 11, 2, 5,
2, 5, 4, 11, 6, 6,
1, 9, 3, 4, 5, 8,
5, 8, 3, 4, 7, 3};
int[] facesSmoothingGroups = {0,0,1,1,2,2,3,3,4,4,5,5};
// URL resource = Main.class.getResource("DFv8z.png");
Image diffuseMap = new Image(Main.class.getResource("PCmIW.png").toExternalForm());
TriangleMesh mesh = new TriangleMesh();
mesh.getPoints().addAll(points);
mesh.getTexCoords().addAll(tex);
mesh.getFaces().addAll(faces);
// mesh.getFaceSmoothingGroups().addAll(facesSmoothingGroups);
Material cubeMaterial = new PhongMaterial(Color.TRANSPARENT, diffuseMap, null, null, null);
MeshView m = new MeshView(mesh);
m.getTransforms().addAll(rxBox, ryBox, rzBox);
m.setMaterial(cubeMaterial);
final Group g = new Group(m);
g.setTranslateX(400/2);
g.setTranslateY(400/2);
//g.setTranslateZ(400/2);
g.setRotationAxis(Rotate.Y_AXIS);
g.setRotationAxis(Rotate.X_AXIS);
//g.setRotationAxis(Rotate.Z_AXIS);
Scene scene = new Scene(g, 400, 400, Color.SKYBLUE);
primaryStage.setTitle("Hello World");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
@Override
public void handle(MouseEvent event) {
// TODO Auto-generated method stub
}
最佳答案
您走在正确的轨道上,但您需要:
对于第一部分,只需定义网络图像的总长度和高度:
float L = 400f;
float H = 300f;
然后归一化纹理坐标:
float tex[] = {
100f / L, 0f / H,
200f / L, 0f / H,
0f / L, 100f / H,
100f / L, 100f / H,
200f / L, 100f / H,
300f / L, 100f / H,
400f / L, 100f / H,
0f / L, 200f / H,
100f / L, 200f / H,
200f / L, 200f / H,
300f / L, 200f / H,
400f / L, 200f / H,
100f / L, 300f / H,
200f / L, 300f / H};
对于第二部分,只需使用setter:
PhongMaterial cubeMaterial = new PhongMaterial();
cubeMaterial.setDiffuseMap(diffuseMap);
并且您拥有带纹理的立方体(启用平滑组):
编辑
为了找出顶面,在任何可能的旋转之后,如果您根据网络图像和面的定义顺序定义当前颜色和法线,这可以很容易地完成:
final String[] colors = {"Blue", "Red", "White", "Yellow", "Cyan", "Green"};
float normals[] = {
1f, 0f, 0f,
-1f, 0f, 0f,
0f, 1f, 0f,
0f, -1f, 0f,
0f, 0f, 1f,
0f, 0f, -1f,
};
然后,您要跟踪顶面,它对应于场景坐标中的正常 {0, -1, 0}
。
所以基本上你需要在网格坐标中表达法线:
Point3D normal = m.sceneToLocal(0, -1, 0);
最后,您必须将此法线与 normals
中定义的任何法线相匹配。那个的索引会给你颜色:
private String getColor(MeshView m, float[] normals) {
Point3D normal = m.sceneToLocal(0, -1, 0);
for (int i = 0; i < normals.length; i += 3) {
if (normals[i] * normal.getX() + normals[i+1] * normal.getY() + normals[i+2] * normal.getZ() > 0.99) {
return colors[i / 3];
}
}
return "no color found";
}
关于Javafx:将图像应用于 meshview 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47946126/
我不知道这是不是问这种问题的最佳地点, 我看到一些 JavaFX伙计们,重新标记 一些问题通过替换 javafx来自 javafx-2并采用新的 javafx-8 .它被弃用了还是什么? 编辑 : 不
错误本身: Error:java: invalid flag: --add-modules=javafx.fxml,javafx.graphics,javafx.controls,javafx.bas
这个想法是让一个应用程序在每个显示器上显示两个不同的窗口(阶段),该应用程序应该知道计算机有多少个显示器及其分辨率。 javafx有可能吗? 最佳答案 对于当前版本的 JavaFX (2.2),您可以
我正在将我的项目从 javafx 1.3 转换为 javafx 2.1。但我对 javafx.lang 有疑问包裹。 最佳答案 JavaFX 1.3 lang 包内容被拆分并移至下一个位置: 时长变为
当我尝试将标签添加到 gridpane 中时,如第二张图片所示,它不起作用。我已经尝试了很多东西,比如添加 CSS,但它仍然无法正常工作。为什么第 113 和 114 行不起作用? (opcje.se
我有一个JavaFX ContextMenu分配给滚动面板的鼠标右键单击。它会打开,但在滚动 Pane 外部单击时不会关闭。我可以在滚动 Pane 中添加另一个鼠标事件以将其隐藏,但这只能解决1个问题
我有一个tableview,其中附有一个可观察到的自定义类对象的列表(类类型:SalesInvoiceNetSale)。该表中的所有数据都可以正常显示。可观察列表中的最后一项是总计行(类类型:Sale
关闭。这个问题需要更多 focused .它目前不接受答案。 想改进这个问题?更新问题,使其仅关注一个问题 editing this post . 2年前关闭。 Improve this questi
我想知道如何在JavaFX中绘制半圆。我尝试使用Shape和QuadCurve,但无法制作出完美的半圆。 这是我要绘制的图片: 最佳答案 您链接的图片实际上是一个半圆环。您可以通过绘制嵌套的2条圆弧和
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
我正在寻找 JavaFX 支持的图像类型(最新)列表,例如PNG、JPEG、TIFF。不同的搜索引擎没有帮助......知道从哪里开始吗? 更特别的是,我对 16 位灰度图像(不同格式)和罕见的受支持
我希望在 javafx 中让标签每 0.1 秒闪烁一次。文本显示在后台运行的 ImageView gif 的顶部。我将如何去做,或者您对最佳方法有什么建议? 谢谢 最佳答案 @fabian 的解决方案
我需要测试所选项目的值以调用不同的方法,因此我编写了添加侦听器的代码,但是该代码生成语法错误 @FXML private JFXComboBox cmbComp; cmbComp.valuePrope
我正在 Javafx 中编写一个非常简单的应用程序,其中舞台上有一个带有文本框的按钮作为一个场景。现在,我想要的行为是,当我单击按钮时,我可以使用另一个按钮加载另一个场景和舞台上的一个文本框,然后删除
编辑:如果用户单击“删除”以删除 ListView 中的项目,我会弹出一个警告框。它有效,但我希望它能超越原来的舞台。它出现在我的第一台显示器上。有什么方法可以设置警报显示时的位置吗? 请注意,“所有
我想使用 JavaFX 编写一个笔画绘图应用程序。我有一个压敏绘图板,如果能够读取笔的压力和倾斜值,那就太好了。 JavaFX 有一个 API 可以处理鼠标、触摸和滑动输入,但似乎没有任何东西可以产生
我在 JavaFX 中使用条形图和折线图。当我使两个图表大小相同并将它们放在同一位置时,它们完美地相互重叠。我如何使折线图显示在条形图的顶部。 目前我已将它们的不透明度设置为 0.7,这样它们“看起来
此问题与 this 相关。现在我想为字段值等于某个值的行着色。 @FXML private TableView tv_mm_view; @FXML private Ta
我有一个程序,可以生成高度图(0-255 的整数的 2D 数组),并使用 Shape3D“Box”对象为每个“像素”构建 3D View ,其高度与其在高度图中的值成比例。这会创建一个看起来很酷的四四
我想为 JavaFX 创建上下文菜单。这是我测试过的代码。但是由于某种原因,当我右键单击树节点时没有上下文菜单。你能帮我找出我的错误吗。 import java.util.Arrays; import
我是一名优秀的程序员,十分优秀!