将变换应用于 3D 模型 - 法线 pb

发布于 2024-07-08 12:01:27 字数 169 浏览 11 评论 0原文

我正在尝试将变换应用于 STL 文件中的 3D 对象(不创建结构化网格对象)。 我的操作方法如下:我在 STL 文件中一一读取法线和面信息,将变换应用到每个顶点和面法线,并将新的计算值写回另一个 STL 文件中。 生成的文件中的顶点没问题,但我的法线是错误的。 看来我不能像对顶点那样将变换应用于法线。 这怎么可能?

I'm trying to apply a transform to a 3D object in a STL File (without creating a structured mesh object). Here is how I proceed: I read the normals and faces information one by one in the STL file, apply my transform to each vertex and to the face normal and write back the new computed values in another STL file.
The vertex are OK in the generated file but my normals are wrong. It seems that I can't just apply my transform to the normal as I do for the vertice. How is that possible??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

终难遇 2024-07-15 12:01:28

引用 Rodrigo Lopez:法线是方向,因此 4x4 矩阵的位置部分不应该真正应用,尽管重整化无论如何都会修复它

重整化不会解决这个问题:假设法线是 (1,0,0),然后将其转换为 (-2,0,0) => 法线将是 (-1,0,0),这是标准化的并且是错误的,因为法线应该保持不变。

Quote Rodrigo Lopez: Normals are directions, so the position part of a 4x4 matrix shouldn't really be applied though renormalization will fix it anyway.

renormalization will not fix it: suppose the normal is (1,0,0) then translate it with (-2,0,0) => the normal will be (-1,0,0) which is normalized and is wrong, because the normal should stay the same.

伪装你 2024-07-15 12:01:28

您需要将矩阵的逆转置应用于法线,而不是使用原始矩阵。

另外,在变换法线时,您需要将法线的 w 坐标视为 0(而不是点的 1)。

You need to apply the inverse-transpose of your matrix to the normals, instead of using the original matrix.

Also, you need to treat w-coordinate of the normal as 0 (not 1 as with points) when transforming it.

自在安然 2024-07-15 12:01:27

您应该查看变换法线

事实上,杰夫,你只说对了一部分。 对于向量来说,你是对的。 但对于法线来说,意义有点不同,你必须通过上面的 3x3 进行变换,但是反转,然后转置。

You should look at transforming normals.

And actually, Jeff, you're only partly correct. For a vector, you're right. But for a normal, which is a bit different in meaning, you have to transform by the upper 3x3, but inversed, and then transposed.

心头的小情儿 2024-07-15 12:01:27

您可以对两者应用几乎相同的变换,但请记住这两点:

  • 法线是方向,因此
    不应应用 4x4 矩阵的位置部分。 为了避免应用它,您可以在与矩阵相乘之前将向量格式化为 Vector(x,y,z,0),或者使用专用的 TransformVector() 函数来避免最终与零相乘的指令。
  • 如果您应用的矩阵包含一个比例,您的
    正常也会被缩放,
    这意味着,如果你做了典型的
    NL 照明点积您的结果
    会比它更亮或更暗
    应该。 通常你会想要
    应用后重新标准化
    变换,或确保
    变换不会反规范化
    正常(这就是
    矩阵的逆转置为
    为了。)

You can apply pretty much the same transformation for both but keep these two things in mind:

  • Normals are directions, so the
    position part of a 4x4 matrix shouldn't be applied. To avoid applying it you can either format the vector as Vector(x,y,z,0) before multiplying with the matrix, or use a dedicated TransformVector() function to avoid the instructions that will end up multiplying with zero.
  • If the matrix you apply contains a scale, your
    normal will be scaled as well,
    meaning that, if you do the typical
    N.L lighting dot product your result
    will be brighter or darker than it
    should be. Usually you'd want to
    re-normalize after applying the
    transform, or make sure the
    transform doesn't de-normalize the
    normal (which is what the
    inverse-transpose of the matrix is
    for.)
奈何桥上唱咆哮 2024-07-15 12:01:27

变换向量与变换点不同——你不能应用变换,只能应用旋转。

Transforming a vector is different than transforming a point -- you can't apply the transformation, only the rotations.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文