原文作者:伍沁憬
-----------------------------------------------------------------------------------------------------------------
HOUDINI VEX源代码
#define TAU 6.283185307179586
#define PI 3.141592653589793
int segment(float rad_min;
float rad_max;
float start_theta;
float end_theta;
int resolution;) {
float theta;
int pt;
int prim = addprim(geoself(), "poly");
float theta_step = (end_theta - start_theta) / (float)resolution;
// inner radius
for(int step=0; step
theta = start_theta + (theta_step * step);
pt = addpoint(geoself(), set(cos(theta)*rad_min, sin(theta)*rad_min, 0));
addvertex(geoself(), prim, pt);
}
// outer radius
for(int step=0; step
theta = end_theta - (theta_step * step);
pt = addpoint(geoself(), set(cos(theta)*rad_max, sin(theta)*rad_max, 0));
addvertex(geoself(), prim, pt);
}
return prim;
}
int ring(float min_arc;
float max_arc;
float radius_min;
float radius_max;
float skip_chance;
int ring_id;
float ring_seed;) {
float theta = 0;
float rand_step;
int seg_num = ring_id;
// ring logic
while (1) {
rand_step = fit(rand(seg_num+ring_seed), 0, 1, min_arc, max_arc);
if (rand(seg_num+9381+ring_seed) > skip_chance) {
segment(radius_min, radius_max, theta, theta+rand_step, 15);
}
theta += rand_step;
seg_num += 1;
if (theta >= TAU)
break;
}
return 1;
}
// entire tron system
int num_rings = chi("ring_count");
float rings_start = 0.5;
float rings_end = 10.0;
float rings_step = (rings_end - rings_start) / (float)num_rings;
float rings_radius = rings_start;
float seed = ch("seed");
for (int i=0; i
ring(0.01, 1.0, rings_radius, rings_radius*1.2, 0.3333, i, seed);
rings_radius += rings_step;
}
-------------------------------------------------------------------------------------------------
MAYA PYTHON 实现脚本
import maya.cmds as cmd
import random
import math
density = 50 #####需要创建得碎片数目
facingRatio = 1 #####创建碎片得面比率数
startRadius = 1 ####初始半径大小
radius = 0.45 ##### 单块模型半径大小
radian = 10 ##### 单块模型弧度数值
space_radius = 0.02 ##### 环状之间得间隙大小
height = 5 ##### 高度变化范围
inoutheight = 0.2 ####内外高度差值
radius_atten = 1.05 ####半径衰减
space_radius_atten = 1.05 ####环状之间间隙衰减变化
height_atten = 1 ####在每一圈中高度是否衰减
inoutheight_atten = 1 ####内外高度差值是否衰减
boolradius = False ####半径之间随机
boolradian = True ####弧度大小数值随机
boolheight = True ####每一圈高度是否需要随机
boolinoutheight =True ###每一圈内外高度是否变化
boolsubradius = False ####局部半径之间随机
boolsubradian = False ####子弧度 位置 完全随机分布
boolsubheight = False ####子高度是否需要随机分布
bool_line_atte_height = True ####所有弧片成整体 由高到低趋势
start_height = 0 ###########初始高度
inc_height = 0.05 ###########增高值
rand_radius = 0.5 ###随机半径
rand_radian = 30 ###随机弧度
rand_height = 1 ###高度随机范围
rand_subradius = 1 ####
count = density
numradian =math.ceil( float(facingRatio*count) / float((facingRatio + 1)) )
numradius =math.floor( float(count) / float((facingRatio + 1)) )
if numradius == 0:
numradius == 1
pos_Radian = 360.0/(numradian-1)
single_Radian = radian
single_Radius = radius
single_Height = height
OBJ_GROUP = []
innerRadius = 0 + startRadius
segment_height = 0
for n in range(int(numradius)):
if boolradius == True:
offset_Radius = (random.random()*2-1)*rand_radius
outRadius =innerRadius + offset_Radius + single_Radius
else:
outRadius =innerRadius + single_Radius
if bool_line_atte_height != True:
if boolheight == True:
offset_rand_height = (random.random()*2-1)*rand_height
outheight = offset_rand_height + height
else:
outheight = height
else:
outheight = start_height + segment_height
startAngle = random.random()*360
poslist=[]
objlist = []
for a in range(int(numradian)):
################################################################################
if boolsubradius == True:
finallyoutRadius = (random.random()*2-1)*rand_radius* rand_subradius + outRadius
finallyinnerRadius =(random.random()*2-1)*rand_radius* rand_subradius + innerRadius
else:
finallyoutRadius = outRadius
finallyinnerRadius = innerRadius
if boolsubradian == True:
startAngle = random.random()*360
endAngle = startAngle + single_Radian
finallystartAngle = startAngle
if boolradian == True:
finallyendAngle = startAngle + (random.random()*2-1)*rand_radian + single_Radian
else:
finallyendAngle = endAngle
###################################################################################
if bool_line_atte_height != True:
if boolsubheight == True:
offset_rand_height = random.random()*rand_height
out_height = outheight + offset_rand_height
in_height = outheight + offset_rand_height
else:
out_height = outheight
in_height = outheight
fin_inc_height = 0
else:
out_height = outheight
in_height = outheight
fin_inc_height = float(inc_height)/10
if boolinoutheight == True:
finally_out_height = out_height + inoutheight
else:
finally_out_height = out_height
finally_in_height = in_height
###################################################################################
arcAngle = abs(finallyendAngle - finallystartAngle)
pointnum = math.ceil(arcAngle/5) + 1
if pointnum <= 2:
pointnum = 2
preAngle = arcAngle
else:
preAngle = arcAngle/(pointnum-1)
inposlist = []
outposlist = []
for i in range(int(pointnum)):
finally_in_height += fin_inc_height
segment_height += fin_inc_height
inpos = (math.sin(math.radians(preAngle*i+finallystartAngle))*finallyinnerRadius,finally_in_height,math.cos(math.radians(preAngle*i+finallystartAngle))*finallyinnerRadius)
inposlist.append(inpos)
for i in range(int(pointnum)):
finally_out_height += fin_inc_height
outpos = (math.sin(math.radians(preAngle*i+finallystartAngle))*finallyoutRadius,finally_out_height,math.cos(math.radians(preAngle*i+finallystartAngle))*finallyoutRadius)
outposlist.append(outpos)
if boolsubradian != True:
startAngle += pos_Radian
print finally_in_height,finally_out_height ##################
inoutheight *= inoutheight_atten
#################################################
outposlist.reverse()
poslist.extend(inposlist)
poslist.extend(outposlist)
##########
cmd.polyCreateFacet( p = poslist)
objlist.append(cmd.rename("ring"))
cmd.select(cl=True)
##########
poslist = []
single_Radius *= radius_atten
space_radius *= space_radius_atten
innerRadius += single_Radius + space_radius
OBJ_GROUP.append(cmd.rename(cmd.group(objlist),"RING"))
cmd.rename(cmd.group(OBJ_GROUP),"RING_GROUP")
###########################################################
,Maya技巧,Maya安装