我已经用python编写了一些代码,其中将创建圆柱体形状的land。半径值将来自用户输入。但是,我想从半径计算圆柱体的高度。我已经想出了一个fromula这样做,但我不知道如何把它在代码中。它一直给我h是不确定的错误。你知道吗
def createLand(landRadius):
'''Creates flat land, circle-shaped for city to be built on.
Extruded tunnels for rivers.
landHeight(h) : the height/thickness of the Land
landRadius(r) : the size/radius of the land
zsubdivisions(sz) : the number of subdivisions along z axis for tunnel extrusion
'''
#Creates circle-shaped land, moves edges and faces around for tunnels
land = cmds.polyCylinder(name='Land', sx=0, sy=0, sz=5, h=landRadius*0.2/4, r=landRadius);
cmds.polyMoveEdge('Land.e[160:179]', s=(0.57, 0.57, 0.57));
cmds.polyMoveEdge('Land.e[120:139]', s=(1.08, 1.08, 1.08));
cmds.polyMoveEdge('Land.e[140:159]', s=(1.32, 1.32, 1.32));
cmds.rotate(0, '15deg', 0, 'Land');
#Tunnels extrusion
cmds.polyExtrudeFacet('Land.f[120:139]', 'Land.f[160:179]', 'Land.f[105:106]', 'Land.f[115:116]', 'Land.f[100:101]', 'Land.f[110:111]', 'Land.f[145:146]', 'Land.f[155:156]', 'Land.f[140:141]', 'Land.f[150:151]', kft=True, ty=-h/2);
cmds.polyMoveEdge('Land.e[110:111]', 'Land.e[115:116]', 'Land.e[100:101]', 'Land.e[105:106]', ty=-h/2);
cmds.move(0, -h/2, 0, 'Land');
你有
land = cmds.polyCylinder(name='Land', sx=0, sy=0, sz=5, h=landRadius*0.2/4, r=landRadius); <snip> cmds.move(0, -h/2, 0, 'Land');
注意,第一行中的
h=landRadius*0.2/4
将h参数设置为cmds.polyCylinder公司(我猜它看起来像def polyCylinder(self,name,sx,sy,sz,h,r): #stuff
这不会在代码的其余部分设置h。我看你想把高度调整到原来的水平。你可以这样做
cmds.move(0, -landRadius*0.2/8, 0, 'Land');
或者有可能
cmds.move(0, -land.h/2, 0, 'Land');
看起来您还没有将“h”定义为变量。但是,您确实在
polyCylinder()
函数中设置了“h”参数。您可以先声明“h”。你知道吗然后在后面的代码中当你有以下
在有
ty=-h/2
的地方,将定义“h”。你知道吗相关问题 更多 >
编程相关推荐