重新计算可编辑多边形对象的法线

发布于 2024-10-02 14:07:11 字数 1223 浏览 13 评论 0原文

我正在为一家出口商工作,但我遇到的问题是正常的计算。

我读过很多关于此的文章,似乎“getnormal”功能没有按预期工作。 (这是为我的出口商创造错误结果的一个)。

所以我需要手动重新计算。

问题是 - 我该怎么做? 计算法线的部分现在看起来像这样:

如果您提供一个函数,那么请记住下面的代码,我不想重写所有内容。

提前致谢。

   for i = 1 to num_faces do
    (
     face = getFace Obj i

     v1 = (MeshArrays[2].count + 1)
     v2 = (MeshArrays[2].count + 2)
     v3 = (MeshArrays[2].count + 3)

     append MeshArrays[1] [v1,v2,v3]

     v1 = coordsys world getvert Obj face.x
     v2 = coordsys world getvert Obj face.y
     v3 = coordsys world getvert Obj face.z


     append MeshArrays[2] v1
     append MeshArrays[2] v2
     append MeshArrays[2] v3

     v1 = (coordsys local getnormal Obj face.x) -- * theInvTM 
     v2 = (coordsys local getnormal Obj face.y) --* theInvTM 
     v3 = (coordsys local getnormal Obj face.z) --* theInvTM 

     append MeshArrays[4] v1
     append MeshArrays[4] v2
     append MeshArrays[4] v3 

     if Obj.numtverts != 0 then 
     ( 
      tvface = getTVFace Obj i
      v1 = getTVert Obj tvface.x
      v2 = getTVert Obj tvface.y
      v3 = getTVert Obj tvface.z
      append MeshArrays[3] v1
      append MeshArrays[3] v2 
      append MeshArrays[3] v3 
     )


    )

I'm working on a exporter, but the problem I'm stuck at is the normal calculation.

I've been reading many posts about this, and it seems like the "getnormal" function does not work like intended. (this is the one creating wrong results for my exporter).

So I need to recalculate it manually.

The question is - How do I do this?
the part that calculates the normal now looks like this:

If you provide a function, then please keep in mind this code below, I'd like to not rewrite everything.

thanks in advance.

   for i = 1 to num_faces do
    (
     face = getFace Obj i

     v1 = (MeshArrays[2].count + 1)
     v2 = (MeshArrays[2].count + 2)
     v3 = (MeshArrays[2].count + 3)

     append MeshArrays[1] [v1,v2,v3]

     v1 = coordsys world getvert Obj face.x
     v2 = coordsys world getvert Obj face.y
     v3 = coordsys world getvert Obj face.z


     append MeshArrays[2] v1
     append MeshArrays[2] v2
     append MeshArrays[2] v3

     v1 = (coordsys local getnormal Obj face.x) -- * theInvTM 
     v2 = (coordsys local getnormal Obj face.y) --* theInvTM 
     v3 = (coordsys local getnormal Obj face.z) --* theInvTM 

     append MeshArrays[4] v1
     append MeshArrays[4] v2
     append MeshArrays[4] v3 

     if Obj.numtverts != 0 then 
     ( 
      tvface = getTVFace Obj i
      v1 = getTVert Obj tvface.x
      v2 = getTVert Obj tvface.y
      v3 = getTVert Obj tvface.z
      append MeshArrays[3] v1
      append MeshArrays[3] v2 
      append MeshArrays[3] v3 
     )


    )

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

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

发布评论

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

评论(1

梦里泪两行 2024-10-09 14:07:11

通过用以下代码替换适当的行来解决它:

--get the object's transformation
myTransform = Obj.transform

-- get the normal * transformation - translation
v1 = (coordsys local getnormal Obj face.x)* myTransform  - (myTransform.translationpart)
v2 = (coordsys local getnormal Obj face.y)* myTransform  - (myTransform.translationpart)
v3 = (coordsys local getnormal Obj face.z) * myTransform - (myTransform.translationpart)

--normalize them / and write normal to a new variable
v11 = normalize v1
v22 = normalize v2
v33 = normalize v3

--append to array
append MeshArrays[4] v11
append MeshArrays[4] v22
append MeshArrays[4] v33

resolved it by replacing the appropriate lines with the following code:

--get the object's transformation
myTransform = Obj.transform

-- get the normal * transformation - translation
v1 = (coordsys local getnormal Obj face.x)* myTransform  - (myTransform.translationpart)
v2 = (coordsys local getnormal Obj face.y)* myTransform  - (myTransform.translationpart)
v3 = (coordsys local getnormal Obj face.z) * myTransform - (myTransform.translationpart)

--normalize them / and write normal to a new variable
v11 = normalize v1
v22 = normalize v2
v33 = normalize v3

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