我对广度优先算法有疑问,我的脚本在 Maya 中生成曲线,定位它们,旋转和缩放它们,以便它们给我树形,我有这些变量
cs=当前状态,
p=父母,
节点=未访问节点列表
lvl=当前深度
maxlvl = 最大深度
问题是我无法确定当前深度,并在那里终止树,它存在而没有访问所有节点
这是我的脚本
import random
import math
import maya.cmds as mc
#----define set-----
#--- curve, #children,angle,l--------
#----define rule----
# l=80% ch<=3 angle<=45
l=0.8
ch=6
ang=50
#---list to track----
nodes=[]
#--- begin-----
#---start curve-----
nodes.append(mc.curve(n="a",d=3,p=((0,0,0),(0,1,0),(0,3,0),(0,5,0),(0,6,0)),k=(0,0,0,1,2,2,2)))
cs="" #---current state----
p="a" #---paretn of the current state----
maxlvl=6 #--max depth for the tree
lvl=1 #-- cuurent level----
while (len(nodes)!=0 and lvl<5):
#---generate children number----
chN=random.randint(0,ch)
for j in range(chN):
#----generate node----
mc.select(p,r=1)
cs=mc.duplicate(rr=1)[0]
#---append to node lst----
nodes.append(cs)
#---adjust pos---
pos=mc.pointPosition(p+".cv[4]")
mc.xform(cs,t=(pos[0],pos[1],pos[2]),ws=1)
#---adjust rotation---
mc.rotate(0,0,(random.random()*45+5)*math.pow(-1,j%2),cs,r=1)
#---adjust scale---
mc.scale(0,math.pow(0.8,lvl),0,cs)
j+=1
#--- go to next parent---
nodes.pop(0)
if nodes:
p=nodes[0]
lvl+=1
先感谢您