将变换应用于 3D 模型 - 法线 pb
我正在尝试将变换应用于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
重整化不会解决这个问题:假设法线是 (1,0,0),然后将其转换为 (-2,0,0) => 法线将是 (-1,0,0),这是标准化的并且是错误的,因为法线应该保持不变。
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.
您需要将矩阵的逆转置应用于法线,而不是使用原始矩阵。
另外,在变换法线时,您需要将法线的 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.
您应该查看变换法线。
事实上,杰夫,你只说对了一部分。 对于向量来说,你是对的。 但对于法线来说,意义有点不同,你必须通过上面的 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.
您可以对两者应用几乎相同的变换,但请记住这两点:
不应应用 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:
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.
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.)
变换向量与变换点不同——你不能应用变换,只能应用旋转。
Transforming a vector is different than transforming a point -- you can't apply the transformation, only the rotations.