【发布时间】:2017-02-23 02:32:58
【问题描述】:
我创建了一个脚本,它生成三种不同的多边形,它们的 x y z 坐标是随机的。当前代码根据需要生成这些,但它总是每个生成 40 个。
下一步将使用整数作为random number generator 来生成每种多边形类型的随机数。这需要一个for 循环,其中包含一个if 语句、一个else-if 语句和一个else 语句。代码将完整地执行上述参数(因为我已经取消了它们),除了它只会做一种类型的多边形(环面不可触发)。
我对两件事持怀疑态度:
1:如果 int $rng=rand(1,4); 正确指定创建一个 1-4 的范围以作为 random numbers 使用。
2:如果需要一个带有if-else 语句的for 循环首先获得所有形状的随机数。
This is a desired result I'm trying to get. This is the most recently-executed result of the code.
int $num = 40 ;
int $rng = rand( 1, 4 ) ;
for ( $i = 1; $i <= $num; $i++ ) {
if ( $rng == 1 ) {
polySphere -r 1 -sx 20 -sy 20 -ax 0 1 0 -cuv 2 -ch 1 ;
int $xpos = rand( -20, 100 ) ;
int $ypos = rand( 20, 80 ) ;
int $zpos = rand( 20, 50 ) ;
move -r $xpos $ypos $zpos ;
print ( $i + "sphere \n" ) ;
}
else if ( $rng == 4 ) {
polyTorus -r 1 -sx 20 -sy 20 -ax 0 1 0 -cuv 2 -ch 1 ;
int $xpos = rand( -20, 100 ) ;
int $ypos = rand( 20, 80 ) ;
int $zpos = rand( 20, 50 ) ;
move -r $xpos $ypos $zpos ;
print ($i + "torus \n");
}
else {
polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1 ;
int $xpos = rand( -20, 100 ) ;
int $ypos = rand( 20, 80 ) ;
int $zpos = rand( 20, 50 ) ;
move -r $xpos $ypos $zpos ;
print ( $i + "cube \n" ) ;
}
}
【问题讨论】:
标签: if-statement maya modeling autodesk mel