- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
只是试图理解 JavaFX 文档中关于三角形网格的意义。此代码有效并绘制了一个矩形。
public class Shape3DRectangle extends TriangleMesh {
public Shape3DRectangle(float Width, float Height) {
float[] points = {
-Width/2, Height/2, 0, // idx p0
-Width/2, -Height/2, 0, // idx p1
Width/2, Height/2, 0, // idx p2
Width/2, -Height/2, 0 // idx p3
};
float[] texCoords = {
1, 1, // idx t0
1, 0, // idx t1
0, 1, // idx t2
0, 0 // idx t3
};
/**
* points:
* 1 3
* ------- texture:
* |\ | 1,1 1,0
* | \ | -------
* | \ | | |
* | \ | | |
* | \| -------
* ------- 0,1 0,0
* 0 2
*
* texture[3] 0,0 maps to vertex 2
* texture[2] 0,1 maps to vertex 0
* texture[0] 1,1 maps to vertex 1
* texture[1] 1,0 maps to vertex 3
*
* Two triangles define rectangular faces:
* p0, t0, p1, t1, p2, t2 // First triangle of a textured rectangle
* p0, t0, p2, t2, p3, t3 // Second triangle of a textured rectangle
*/
int[] faces = {
2, 2, 1, 1, 0, 0,
2, 2, 3, 3, 1, 1
};
this.getPoints().setAll(points);
this.getTexCoords().setAll(texCoords);
this.getFaces().setAll(faces);
}
}
最后3行评论来自Class TriangleMesh .我的问题是我在代码中看不到他们对 faces 数组的定义和 faces 数组之间的匹配。因此不明白如何在其他情况下使用 faces 数组。不应该是这样吗:
int[] faces = {
2, 3, 0, 2, 1, 0,
2, 3, 1, 0, 3, 1
};
但是没有渲染矩形。我缺少什么以及通常应该将什么放入 faces 数组?
最佳答案
面方向如何工作的解释
定义面的方向很重要。在工作示例中,第一个面的点是 2、1、0(即三角形按逆时针顺序定义)。在您建议的 faces 数组中,第一个面是 2, 0, 1 (顺时针)。以顺时针方式定义的面背对观察者。以逆时针方向定义的面朝向观察者。
如何让你的网格可见
如果采用建议的面部定义并将网格绕 Y 轴旋转 180 度,您将看到面部。如果不旋转网格,默认情况下您将看到脸部的背面,并且网格的背面将被剔除(即不可见)。
另一种查看不旋转网格的方法是 set the cull face of the Mesh至 CullFace.NONE , 然后网格的背面将显示(尽管它只会显示为黑色而不是阴影区域)。
关于您提供的代码中注释的注释
您的代码示例中的注释有点误导,它应该反射(reflect)实际的人脸定义,而不是没有真正按预期工作的人脸定义。
文档请求更改建议
国际海事组织,TriangleMesh文档应该得到增强,我在 JavaFX 问题跟踪器中记录了针对运行时项目的更改请求以请求此增强。
更改文档以突出显示网格面中点的顺序的请求是:
JDK-8122785 Document importance of TriangleMesh order of elements
Java 8 3D API 文档的总体变更请求是:
JDK-8101810 Finish javadoc for FX 8 3D API
演示
这是一个示例测试工具,您可以使用它来尝试这些概念,以便更好地理解它们。
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.*;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import javafx.scene.transform.Rotate;
import javafx.stage.Stage;
// drag the mouse over the rectangle to rotate it.
public class RectangleViewer extends Application {
double anchorX, anchorY, anchorAngle;
private PerspectiveCamera addCamera(Scene scene) {
PerspectiveCamera perspectiveCamera = new PerspectiveCamera(false);
scene.setCamera(perspectiveCamera);
return perspectiveCamera;
}
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
final MeshView rect = new MeshView(
new Shape3DRectangle(200, 200)
);
rect.setMaterial(new PhongMaterial(Color.DARKGREEN));
rect.setRotationAxis(Rotate.Y_AXIS);
rect.setTranslateX(250);
rect.setTranslateY(250);
// try commenting this line out to see what it's effect is . . .
rect.setCullFace(CullFace.NONE);
final Group root = new Group(rect);
final Scene scene = new Scene(root, 500, 500, true);
scene.setOnMousePressed(new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent event) {
anchorX = event.getSceneX();
anchorY = event.getSceneY();
anchorAngle = rect.getRotate();
}
});
scene.setOnMouseDragged(new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent event) {
rect.setRotate(anchorAngle + anchorX - event.getSceneX());
}
});
addCamera(scene);
primaryStage.setScene(scene);
primaryStage.show();
}
public class Shape3DRectangle extends TriangleMesh {
public Shape3DRectangle(float width, float height) {
float[] points = {
-width/2, height/2, 0, // idx p0
-width/2, -height/2, 0, // idx p1
width/2, height/2, 0, // idx p2
width/2, -height/2, 0 // idx p3
};
float[] texCoords = {
1, 1, // idx t0
1, 0, // idx t1
0, 1, // idx t2
0, 0 // idx t3
};
/**
* points:
* 1 3
* ------- texture:
* |\ | 1,1 1,0
* | \ | -------
* | \ | | |
* | \ | | |
* | \| -------
* ------- 0,1 0,0
* 0 2
*
* texture[3] 0,0 maps to vertex 2
* texture[2] 0,1 maps to vertex 0
* texture[0] 1,1 maps to vertex 1
* texture[1] 1,0 maps to vertex 3
*
* Two triangles define rectangular faces:
* p0, t0, p1, t1, p2, t2 // First triangle of a textured rectangle
* p0, t0, p2, t2, p3, t3 // Second triangle of a textured rectangle
*/
// if you use the co-ordinates as defined in the above comment, it will be all messed up
// int[] faces = {
// 0, 0, 1, 1, 2, 2,
// 0, 0, 2, 2, 3, 3
// };
// try defining faces in a counter-clockwise order to see what the difference is.
// int[] faces = {
// 2, 2, 1, 1, 0, 0,
// 2, 2, 3, 3, 1, 1
// };
// try defining faces in a clockwise order to see what the difference is.
int[] faces = {
2, 3, 0, 2, 1, 0,
2, 3, 1, 0, 3, 1
};
this.getPoints().setAll(points);
this.getTexCoords().setAll(texCoords);
this.getFaces().setAll(faces);
}
}
}
演示输出
绘制矩形时矩形网格的正面和背面默认背对观察者(通过顺时针方向定义一个面)并使用 CullFace.NONE 设置 (win7 jdkb115)。
常见问题
Why is it Height/2
我以这种方式定义模型坐标,因为在这种情况下,我希望旋转的 3D 形状的中心为 centroid的形状。这样我就可以围绕其质心旋转形状而无需执行额外的翻译。参见 pivot point rotation查看围绕任意枢轴点旋转所需的额外平移。
is the coordinates origin the bottom right?
涉及多个坐标。有具有局部坐标系的模型的坐标(参见 node 文档):
The Node class defines a traditional computer graphics "local" coordinate system in which the x axis increases to the right and the y axis increases downwards. The concrete node classes for shapes provide variables for defining the geometry and location of the shape within this local coordinate space.
有相机操作场景的坐标。在 3D 透视应用程序中,相机是 PerspectiveCamera。 .关于它如何影响坐标的信息是:
By default, this camera is located at center of the scene and looks along the positive z-axis. The coordinate system defined by this camera has its origin in the upper left corner of the panel with the Y-axis pointing down and the Z axis pointing away from the viewer (into the screen). If a PerspectiveCamera node is added to the scene graph, the transformed position and orientation of the camera will define the position of the camera and the direction that the camera is looking.
mesh 中也有纹理坐标。 .这些是 completely different并将纹理贴图上的点映射到模型上的顶点:
The term texCoord is used to indicate a single pair of 2D texture coordinates (u, v) for a single vertex, while the term texCoords (plural) is used to indicate sets of texture coordinates for multiple vertices.
关于java - 如何理解 JavaFX 三角形网格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19960368/
SDL3 提供了 SDL_RenderGeometry 函数绘制几何图形,用法和 OpenGL 差不多,先定义顶点数据,然后根据顶点数据绘制几何图形。 绘制三角形的代码如下: std::array
我想在图像上使用三角形类型按钮,但我无法执行此操作... 如何做到这一点? 最佳答案 这个project可以帮你。您可以自定义 UIButton 的形状。 关于iphone - 定制非矩形按钮 三角形
我一直在尝试找出如何使用 Python 制作彩虹三角螺旋。我可以制作一个方形螺旋,但它不会导入颜色。而且它不使用三角形。 输出应该是什么样子: 我取得的成就: 我的代码: import tur
我正在使用 this 研究三角形检测算法文章。我编写了这段代码,但不幸的是,当三角形之间存在交集时,该方法返回 false。 private boolean checkTriangleCollisio
我在资源文件中找到了几个关于如何在 Android 中绘制三角形的答案。但是我没有找到任何可以解释如何更改三角形旋转的内容。 我找到的例子:
对于编码类(class)中的作业,我应该找到一种方法让 Python 制作星号三角形,如下所示: x xx xxx 但是,无论我用我的代码做什么,我都无法做到这一点。最好的我可以得到的是:
我在绘制两个多边形时遇到问题。我想填充两个三角形,但一个大于第二个。我在 winforms 中使用 UserControl。代码: Point[] DOWN = new Point[] {new Po
如何测试三角形和正方形是否相交? 当我们知道它是正方形而不是矩形时,有什么方法可以优化它吗?此外,正方形是轴对齐的,这样应该可以进一步提升性能? 或者我应该把正方形分成三角形,然后对三角形-三角形相交
我有一个方法是画一个多边形,然后将多边形向右旋转90度,使其原来的顶点现在指向右边。 这是绘制多边形(三角形)的代码,但我不知道如何旋转它。 Point[] points = new Point[3]
我知道有高效的多边形裁剪算法(例如 Maillot、Vatti、Greiner-Hormann)。然而,这些算法适用于任意多边形,尽管它们适合我的情况,但在我看来,对像我这样的简单情况使用这种通用算法
我的问题可能很愚蠢,但我没有找到三角形 strip 使用的好例子: http://i.stack.imgur.com/KL8jk.png 像这样的顶点: A: -0.5f, -0.5f, // Bo
我正在尝试创建一个等边三角形,您可以在 fiddle 中看到它: 我的想法是,我将笔放在 (0, 0) 处,然后在 (20, 11) 处画线,但三角形看起来不正确。 最佳答案 您的三角形已被
通过编写一些逻辑代码,只是无法弄清楚如何以所需的形式获得 01 三角形的输出,三角形确实打印出来,但不是根据要求的输出。 import java.util.Scanner; import java
我一直在尝试制作一个简单的 pygame 程序来检查光标是否在三角形内部或外部。我通过找到较大三角形的面积,然后从鼠标位置到所有三个点制作三个内部三角形并找到它们的面积来完成此操作。 根据我的理解,如
我有一个方法 drawTriangle,它在 JAVA 中的 OpenGL 程序的 display() 方法中被引用。 public void drawTriangle(GL gl, int x1,
我正在尝试用 C++ 创建一个程序,该程序将数字的三角形模式放入二维数组中。 示例: 1 3 4 5 9 2 9 4 6 1 顶行是一个数字(整数),三角形的每一行比它上面的行多一
所以我最近一直在尝试学习 OpenGL,遵循了几个文本和视频教程。 我无法绘制三角形,我已经双重和三次检查我是否以正确的顺序执行了所有必要的步骤,但我显然遗漏了一些东西 在添加一些代码之前,我应该声明
我遇到了一个用递归绘制谢尔宾斯基三角形的程序。我如何解释这段代码是调用 sierpinski1 直到 n == 0,然后只绘制 3 个小三角形(每次调用一个三角形),因为 n == 0 是绘制某些东西
我有一个需要 3 个点的函数,我将使用这些点来绘制一个三角形,就好像我在使用 glVertex 函数一样。 但由于我想在避免透视变形的同时对这个三角形进行纹理贴图,我必须对其进行 segmentati
下面的代码应该为三角形添加一个 3d 对象,但我收到错误 Assets/Scripts/MakeTriangle.cs(6,28):错误 CS0120:需要对象引用才能访问非静态成员 `UnityEn
我是一名优秀的程序员,十分优秀!