在 Maya 中使用 Python 沿着 nurbsPlane 为丝带脊柱创建毛囊?
Creating Hair follicles along a nurbsPlane with Python in Maya for a ribbon Spine?
我实现了沿着 nurbsPlane 的毛囊创建。但是,当我连接 OutTranslate 属性以使它们随顶点移动时,除了第一个之外的所有属性都移动到平面的末端。谁能解释为什么要这样做?我是初学者,所以如果还有什么奇怪的地方写的,请告诉我,以便我改进。提前致谢!
import maya.cmds as cmds
listName = ['spine01', 'spine02','spine03', 'spine04','spine05', 'spine06','spine07', 'spine08', 'spine09', 'spine10' ]
planeLength = 45.00
cmds.select(all=True)
cmds.delete()
cmds.nurbsPlane(p=[planeLength/2,0,0], ax=[0,0,0], w=planeLength, lr=0.1 , d=3, u=9, v=1, n='spineNurbsPlane')
cmds.rotate(0,0,90, 'spineNurbsPlane')
cmds.select(d=True)
cmds.group(em=True, n='follicle_grp')
for i in range( len(listName)):
y=str(i+1)
cmds.createNode( 'follicle', n='follicle'+listName[i])
cmds.parent('follicle'+y,'follicle_grp', s=True )
cmds.setAttr('follicle'+listName[i]+'.simulationMethod', 0)
cmds.makeIdentity('spineNurbsPlane', apply=True, t=1, r=1, s=1, n=0 )
cmds.connectAttr('follicle'+listName[i]+'.outRotate','follicle'+y+'.rotate', f=True )
cmds.connectAttr('follicle'+listName[i]+'.outTranslate','follicle'+y+'.translate')
cmds.connectAttr('spineNurbsPlaneShape.worldMatrix','follicle'+listName[i]+'.inputWorldMatrix')
cmds.connectAttr('spineNurbsPlaneShape.local','follicle'+listName[i]+'.inputSurface')
cmds.setAttr( 'follicle'+y+'.parameterV', 0.5)
cmds.setAttr( 'follicle'+y+'.parameterU', i*5)
问题在于您为毛囊的 parameterU 属性设置的值。此属性的范围是从 0 到 1(是的,您可以设置在 1 以上,但不应该),并且您传递的值远远超过 1,这使得它们都聚集在顶部。
只是为了说明,让我们看一下您当前使用 i*5
获得的一些值,并将 i
替换为循环中的值:
0 * 5 # Outputs 0, puts the follicle on the bottom
1 * 5 # Outputs 5, already beyond attribute's range and puts it on top
2 * 5 # Outputs 10, again puts it on top
3 * 5 # Outputs 15, yup same thing
.. and so on
所以你需要传递一个有意义的值。要重新映射它以使值介于 0 - 1 之间,您可以使用这个简单的公式:loopIndex / (totalFollicleCount - 1)
。就是这样,这将沿着平面的长度正确设置它们,因为它会使值介于 0 - 1 之间。顺便说一句,我们需要将总长度减去 1 以获得最后一个毛囊放置在顶.
import maya.cmds as cmds
listName = ['spine01', 'spine02', 'spine03', 'spine04', 'spine05', 'spine06', 'spine07', 'spine08', 'spine09', 'spine10']
planeLength = 45.00
cmds.select(all=True)
cmds.delete()
cmds.nurbsPlane(p=[planeLength / 2, 0, 0], ax=[0, 0, 0], w=planeLength, lr=0.1 , d=3, u=9, v=1, n='spineNurbsPlane')
cmds.rotate(0, 0, 90, 'spineNurbsPlane')
cmds.select(d=True)
cmds.group(em=True, n='follicle_grp')
for i in range(len(listName)):
y = str(i + 1)
cmds.createNode('follicle', n='follicle' + listName[i])
cmds.parent('follicle' + y,'follicle_grp', s=True)
cmds.setAttr('follicle' + listName[i] + '.simulationMethod', 0)
cmds.makeIdentity('spineNurbsPlane', apply=True, t=1, r=1, s=1, n=0)
cmds.connectAttr('follicle' + listName[i] + '.outRotate', 'follicle' + y + '.rotate', f=True)
cmds.connectAttr('follicle' + listName[i] + '.outTranslate', 'follicle' + y + '.translate')
cmds.connectAttr('spineNurbsPlaneShape.worldMatrix', 'follicle' + listName[i] + '.inputWorldMatrix')
cmds.connectAttr('spineNurbsPlaneShape.local', 'follicle' + listName[i] + '.inputSurface')
cmds.setAttr('follicle' + y + '.parameterV', 0.5)
cmds.setAttr('follicle' + y + '.parameterU', float(i) / (len(listName) - 1))
哦,请利用 white-space 使代码更具可读性,否则我的眼睛会流血!
我实现了沿着 nurbsPlane 的毛囊创建。但是,当我连接 OutTranslate 属性以使它们随顶点移动时,除了第一个之外的所有属性都移动到平面的末端。谁能解释为什么要这样做?我是初学者,所以如果还有什么奇怪的地方写的,请告诉我,以便我改进。提前致谢!
import maya.cmds as cmds
listName = ['spine01', 'spine02','spine03', 'spine04','spine05', 'spine06','spine07', 'spine08', 'spine09', 'spine10' ]
planeLength = 45.00
cmds.select(all=True)
cmds.delete()
cmds.nurbsPlane(p=[planeLength/2,0,0], ax=[0,0,0], w=planeLength, lr=0.1 , d=3, u=9, v=1, n='spineNurbsPlane')
cmds.rotate(0,0,90, 'spineNurbsPlane')
cmds.select(d=True)
cmds.group(em=True, n='follicle_grp')
for i in range( len(listName)):
y=str(i+1)
cmds.createNode( 'follicle', n='follicle'+listName[i])
cmds.parent('follicle'+y,'follicle_grp', s=True )
cmds.setAttr('follicle'+listName[i]+'.simulationMethod', 0)
cmds.makeIdentity('spineNurbsPlane', apply=True, t=1, r=1, s=1, n=0 )
cmds.connectAttr('follicle'+listName[i]+'.outRotate','follicle'+y+'.rotate', f=True )
cmds.connectAttr('follicle'+listName[i]+'.outTranslate','follicle'+y+'.translate')
cmds.connectAttr('spineNurbsPlaneShape.worldMatrix','follicle'+listName[i]+'.inputWorldMatrix')
cmds.connectAttr('spineNurbsPlaneShape.local','follicle'+listName[i]+'.inputSurface')
cmds.setAttr( 'follicle'+y+'.parameterV', 0.5)
cmds.setAttr( 'follicle'+y+'.parameterU', i*5)
问题在于您为毛囊的 parameterU 属性设置的值。此属性的范围是从 0 到 1(是的,您可以设置在 1 以上,但不应该),并且您传递的值远远超过 1,这使得它们都聚集在顶部。
只是为了说明,让我们看一下您当前使用 i*5
获得的一些值,并将 i
替换为循环中的值:
0 * 5 # Outputs 0, puts the follicle on the bottom
1 * 5 # Outputs 5, already beyond attribute's range and puts it on top
2 * 5 # Outputs 10, again puts it on top
3 * 5 # Outputs 15, yup same thing
.. and so on
所以你需要传递一个有意义的值。要重新映射它以使值介于 0 - 1 之间,您可以使用这个简单的公式:loopIndex / (totalFollicleCount - 1)
。就是这样,这将沿着平面的长度正确设置它们,因为它会使值介于 0 - 1 之间。顺便说一句,我们需要将总长度减去 1 以获得最后一个毛囊放置在顶.
import maya.cmds as cmds
listName = ['spine01', 'spine02', 'spine03', 'spine04', 'spine05', 'spine06', 'spine07', 'spine08', 'spine09', 'spine10']
planeLength = 45.00
cmds.select(all=True)
cmds.delete()
cmds.nurbsPlane(p=[planeLength / 2, 0, 0], ax=[0, 0, 0], w=planeLength, lr=0.1 , d=3, u=9, v=1, n='spineNurbsPlane')
cmds.rotate(0, 0, 90, 'spineNurbsPlane')
cmds.select(d=True)
cmds.group(em=True, n='follicle_grp')
for i in range(len(listName)):
y = str(i + 1)
cmds.createNode('follicle', n='follicle' + listName[i])
cmds.parent('follicle' + y,'follicle_grp', s=True)
cmds.setAttr('follicle' + listName[i] + '.simulationMethod', 0)
cmds.makeIdentity('spineNurbsPlane', apply=True, t=1, r=1, s=1, n=0)
cmds.connectAttr('follicle' + listName[i] + '.outRotate', 'follicle' + y + '.rotate', f=True)
cmds.connectAttr('follicle' + listName[i] + '.outTranslate', 'follicle' + y + '.translate')
cmds.connectAttr('spineNurbsPlaneShape.worldMatrix', 'follicle' + listName[i] + '.inputWorldMatrix')
cmds.connectAttr('spineNurbsPlaneShape.local', 'follicle' + listName[i] + '.inputSurface')
cmds.setAttr('follicle' + y + '.parameterV', 0.5)
cmds.setAttr('follicle' + y + '.parameterU', float(i) / (len(listName) - 1))
哦,请利用 white-space 使代码更具可读性,否则我的眼睛会流血!