1, intersect
int intersect(<geometry>geometry, vector orig, vector dir, vector &p, vector &uvw)
dir的距离表示最大的映射方向
2, 添加属性
1 addpointattrib(0, "tmp_dist", 0); 2 int allpoints[] = primpoints(0, 0); 3 int nps = npoints(0); 4 5 for(int i=0;i<nps;i++){ 6 vector tmp = point(0,"P",i+1)-point(0,"P",i); 7 setpointattrib(0, "tmp_dist", i, length(tmp), "set"); 8 }
3,让数字前生成0,比如45变成045
padzero(5, 126) = 00126 不是vex
s@id = sprintf(\'%04d\', @ptnum);
4,if else 缩略写法
1 if (int(ch("flip_green"))) @Cd.g = 1 - @Cd.g; 2 else @Cd.r = 1 - @Cd.r;
5,删除分叉
View Code
6,rotate by vector direction
1 vector up = set(0, 1, 0); 2 matrix m=dihedral(@N, up); 3 @P*=m;
7,测量线的长度 arclen expression function - Returns the arc length of a curve between two U positions.
arclen(surface_node, prim_num, ustart, ustop)
8, Quaternion To Euler ?
matrix m = qconvert(@orient);
v@geoRotation = cracktransform(0, 0, 1, {0,0,0}, m);
9,get transform
v@t = cracktransform(0, 0, 0, {0,0,0}, 4@xform);
v@r = cracktransform(0, 0, 1, {0,0,0}, 4@xform);
v@s = getbbox_size(1);
10, 字符串替换
表达式
`strreplace(chs("root"), \'output\', \'cache\')`
vex
string path = "../shop/principled1";
s@path = re_replace("../shop/", "../shopnet1/", path);
11, 点蔓延
1 if(@infect == 0){ 2 int spnts[] = nearpoints(0, @P, ch(\'search\'), ch(\'searchnum\')); 3 foreach(int pt; spnts){ 4 if(point(0, \'infect\', pt)==1 ){ 5 vector pdir = normalize( @P - point(0, "P", pt) ); 6 float dotflow = dot(pdir, v@flowup); 7 if( dotflow<chf("slope") ){ 8 @infect = 1; 9 @Cd = {1,0,0}; 10 @v = pdir; 11 } 12 } 13 } 14 }
12,均匀点
1 // Average Neighbouring Points 2 int n[] = nearpoints(0, @P, chf("maxdist")); 3 vector avgP = @P; 4 5 // Loops over all elements of n, setting pt 6 // to be the value of each element 7 foreach (int pt; n) 8 { 9 avgP += point(0, "P", pt); 10 } 11 12 // +1 because we included ourself. 13 avgP /= len(n)+1; 14 @P.y = avgP.y;
13, flat curve
1 vector begin_position = point(0, "P", 0); 2 float begin_height = begin_position.y; 3 float last_height = begin_height; 4 5 int i=0; 6 for(i; i<npoints(0);i++){ 7 vector current_pos = point(0, "P", i); 8 float current_height = current_pos.y; 9 if(current_height > last_height){ 10 current_pos = set(current_pos.x, last_height, current_pos.z); 11 setattrib(0, "point", "P", i, 0, current_pos, "set"); 12 } 13 else{ 14 last_height = current_height; 15 } 16 }