gpt4 book ai didi

python - Maya 的 ShrinkWrap 变形器

转载 作者:行者123 更新时间:2023-12-05 03:40:35 28 4
gpt4 key购买 nike

我正在尝试对两个 3D 模型执行 ShrinkWrap 变形器,以便稍后能够执行从一个模型到另一个模型的变形。当我应用我所做的功能时,当我操纵偏移值或目标通货膨胀时,它不会给我第二个模型的相同形状,它会给我一个不完整的不同形状,这是代码:

import maya.cmds as cmds 

def matchCurveShapes_andShrinkWrap(firstModel, secondModel):
myDict={
".boundingBoxCenter":1,
".axisReference":0 ,
".alongX":1,
".alongY":1,
".alongZ":1,
".offset":0,
".targetInflation":0,
".falloffIterations":1
}
cmds.delete(firstModel, ch=1)
getShrink=cmds.deformer(firstModel, type="shrinkWrap")
cmds.connectAttr(secondModel+".worldMesh[0]", getShrink[0]+".targetGeom", f=1)

for key, value in myDict.items():
cmds.setAttr(getShrink[0]+key, value)

matchCurveShapes_andShrinkWrap('pCylinder1', 'pCube3')

最佳答案

我可以给你我的一段代码来创建一个 shrinkWrap,我没有玛雅所以不能真正检查你的代码:

def getTargetMesh(targetTrans=str):

sh = cmds.ls(targetTrans, dag=True, shapes=True)
# Find if at least one of them is an allowable target type
for s in sh:
io = cmds.getAttr(s+".io")
if io:
continue

mtype = cmds.nodeType(s)
if mtype == "mesh":
return s
return None

def shrinkWrap(mesh, target, **kwargs):

targetMesh = getTargetMesh(target) # find a not intermediate shape

# Find all the surf transforms that have been selected
surf = cmds.listRelatives(mesh, path=True)

surface = surf[0]

# SET A BUNCH OF ATTRIBUTES WITH KWARGS or with default value
projection = kwargs.get('projection') or 0
closestIfNoIntersection = kwargs.get('closestIfNoIntersection') or 0
reverse = kwargs.get('reverse') or 0
bidirectional = kwargs.get('bidirectional') or 0
boundingBoxCenter = kwargs.get('boundingBoxCenter') or 1
axisReference = kwargs.get('axisReference') or 0
alongX = kwargs.get('alongX') or 0
alongY = kwargs.get('alongY') or 0
alongZ = kwargs.get('alongZ') or 0
offset = kwargs.get('offset') or 0
targetInflation = kwargs.get('targetInflation') or 0

shrinkwrapNode = cmds.deformer(surface, type='shrinkWrap')[0]

cmds.setAttr(shrinkwrapNode + ".projection", projection)
cmds.setAttr(shrinkwrapNode + ".closestIfNoIntersection", closestIfNoIntersection)
cmds.setAttr(shrinkwrapNode + ".reverse", reverse)
cmds.setAttr(shrinkwrapNode + ".bidirectional", bidirectional)
cmds.setAttr(shrinkwrapNode + ".boundingBoxCenter", boundingBoxCenter)
cmds.setAttr(shrinkwrapNode + ".axisReference", axisReference)
cmds.setAttr(shrinkwrapNode + ".alongX", alongX)
cmds.setAttr(shrinkwrapNode + ".alongY", alongY)
cmds.setAttr(shrinkwrapNode + ".alongZ", alongZ)
cmds.setAttr(shrinkwrapNode + ".offset", offset)
cmds.setAttr(shrinkwrapNode + ".targetInflation", targetInflation)

# Add the target object
#
cmds.connectAttr(targetMesh + ".w", shrinkwrapNode + ".tgt")
# connect up the smooth target attributes
# so the smoothed target follows the target shape's settings
#
cmds.connectAttr(targetMesh + ".co", shrinkwrapNode + ".co")
cmds.connectAttr(targetMesh + ".suv", shrinkwrapNode + ".suv")
cmds.connectAttr(targetMesh + ".kb", shrinkwrapNode + ".kb")
cmds.connectAttr(targetMesh + ".bnr", shrinkwrapNode + ".bnr")
cmds.connectAttr(targetMesh + ".khe", shrinkwrapNode + ".khe")
cmds.connectAttr(targetMesh + ".peh", shrinkwrapNode + ".peh")
cmds.connectAttr(targetMesh + ".kmb", shrinkwrapNode + ".kmb")

cmds.select(clear=True)
return shrinkwrapNode

这是一个函数,我用它来输出只有四边形的球体

def createSquareSphere(res=4):
cub = cmds.polyCube(n = 'qSphere#')
v = round(sqrt(pow(4, res)))*2
sph = cmds.polySphere(n = 'proj_tmp', sa=v, sh=v)
cmds.polySmooth(cub, dv = 4, mth = 0, sdt = 2, ovb = 1, ofb = 3, ofc = 0, ost = 0, ocr = 0, bnr = 1,
c = 1, kb = 1, ksb = 1, khe = 0, kt = 1, kmb = 1, suv = 1, peh = 0, sl = 1,
dpe = 1, ps = 0.1, ro = 1, ch = 1)
shWrp = shrinkWrap(cub[0], sph[0], projection = 3, reverse = 1)
cmds.delete(cub, ch = True)
cmds.delete(sph)
return cub[0]

关于python - Maya 的 ShrinkWrap 变形器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68058222/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com