【问题标题】:Maya: Get/Set vertex Normal in world space?Maya:在世界空间中获取/设置顶点法线?
【发布时间】:2021-10-28 22:57:13
【问题描述】:

我正在研究烘焙自定义枢轴的小工具。听起来没什么特别的。 问题是当我运行命令bakeCustomPivot 时,它还会制动自定义法线,在我的情况下必须始终保持它们的方向。想到的第一个想法是在烘烤之前保存顶点正常并在它们更改后恢复它们。但现在我遇到了真正的问题。

cmds.polyNormalPerVertex( q=1, normalX=1) 返回的值等于我在枢轴被烘烤后得到的值,因为法线以相同的方式随着对象枢轴方向改变它们的方向。

我的步骤是在枢轴烘烤前后获得不同的枢轴方向,下一步是将这个差异添加到正常值。不幸的是,它没有帮助。

所以经过短暂的头脑风暴后,我决定尝试另一种方式,直接在世界空间中获取顶点法线值。

其实这就是头脑风暴停止的地方)

这将有助于更清楚地理解我的意思。运行它

import maya.cmds as cmds
import maya.mel as mel

# create test plane
plane = cmds. polyPlane(axis=[0,0,1], subdivisionsHeight=2, subdivisionsWidth=2)
cmds.select(plane[0]+'.vtx[*]')
objVertices = cmds.ls(sl=1,fl=1)


# Activate normals preview
cmds.select(plane)
mel.eval('ToggleVertexNormalDisplay')

# Change plane normals to any
cmds.polyNormalPerVertex(objVertices, normalXYZ=[0.3, 0.4, 1.0])

# get vtx normal vector for one vtx before bake
cmds.select(objVertices[0])
oldVtxNormalX = cmds.polyNormalPerVertex( q=1, normalX=1)
oldVtxNormalY = cmds.polyNormalPerVertex( q=1, normalY=1)
oldVtxNormalZ = cmds.polyNormalPerVertex( q=1, normalZ=1)
oldVtxValue = list(map(lambda x: x[0], [oldVtxNormalX] + [oldVtxNormalY] + [oldVtxNormalZ]))

# Warning. Why values are differ from custom values? They are smaller
print ( '{} --------- Old normal value '.format(oldVtxValue) ) # [0.26832816004753113, 0.3577708899974823, 0.8944271802902222]


# Rotate pivot, bake it (Modify/Bake Pivot)
cmds.select(plane)
cmds.manipPivot(o=[45.0, 0.0, 0.0])  # apply pivot
mel.eval('BakeCustomPivot')


# get vtx normal vector for one vtx after bake
cmds.select(objVertices[0])
newVtxNormalX = cmds.polyNormalPerVertex( q=1, normalX=1)
newVtxNormalY = cmds.polyNormalPerVertex( q=1, normalY=1)
newVtxNormalZ = cmds.polyNormalPerVertex( q=1, normalZ=1)
newVtxValue = list(map(lambda x: x[0], [newVtxNormalX] + [newVtxNormalY] + [newVtxNormalZ]))
print ( '{} --------- New normal value after bake. Same result '.format(newVtxValue) ) # [0.26832816004753113, 0.3577708899974823, 0.8944271802902222]

# !!!! As you can see normal values still same despite of fact pivot have changed

【问题讨论】:

  • 法线是unit vectors,它们的长度总是1.0。当您将法线设置为[0.3, 0.4, 1.0] 时,该值会标准化,从而产生[0.26832816, 0.35777088, 0.89442718](四舍五入)。

标签: python pivot maya normals


【解决方案1】:

polyNormalPerVertex cmd 返回对象空间中的值。烘焙枢轴将枢轴设置为 0,但将对象的旋转设置为 45 度。如果将旋转设置为 0,则法线指向完全相同的方向。

【讨论】:

  • 嗨!我想我在烘烤之前还是之后需要将旋转设置为 0 时,我没有抓住零件?你能澄清一下吗?这就是我理解你评论的方式。首先,我根据需要设置旋转 foк 自定义枢轴,接下来我将对象旋转 -45 度以补偿自定义枢轴旋转,然后我才要求 Maya 烘焙自定义枢轴,这必须帮助我保持原始法线方向。我试过了,没有运气)
  • 我想说的是,BakeCustomPivot 只是将枢轴设置为 0,但将对象旋转设置为之前自定义枢轴中的值。这意味着对象空间中的法线没有变化。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-13
  • 2013-02-12
  • 2017-02-16
  • 2022-11-28
  • 2012-12-28
相关资源
最近更新 更多