vex 从放弃到入门
1.point 模式
int snpt = npoints(1); int spt_num = fit(ch("cur_pos"),0,1,0,snpt-1); vector cur_pos = point(1,"P",spt_num); @P += cur_pos;
2.detail 模式
int npt_l = npoints(0); int npt_r = npoints(1); int npt_r1 = fit(ch("cur_pos"),0,1,0,npt_r-1); vector cur_pos = point(1,"P",npt_r1); for(int i =0; i<npt_l;i++) { vector sphere_pos = point(0,"P",i); sphere_pos += cur_pos; setpointattrib(geoself(),"P",i,sphere_pos); }
3.detail 模式 四边形 插入点
int nprm_t = nprimitives(1); int add_points = ch("add_points"); for(int i = 0;i<nprm_t;i++) { int spt_num1 = primpoint(1,i,0); int spt_num2 = primpoint(1,i,1); int spt_num3 = primpoint(1,i,3); vector tmp1 = point(1,"P",spt_num1); vector tmp2 = point(1,"P",spt_num2); vector tmp3 = point(1,"P",spt_num3); vector tmpU = tmp2 - tmp1; vector tmpV = tmp3 - tmp1; vector tmp = set(0,0,0); for(int j = 0; j< add_points ;j++) { float r1 = rand(j+1); float r2 = rand(j*10+3); tmp = tmpU*r1 + tmpV*r2; tmp += tmp1; int rtn = addpoint(geoself(),tmp); } }
4.detail 模式 三角面 插入点
...
5:vex detail
point 模式是每一个点一个线程,在point模式下addpoint(),一次add是npt个点,point模式下要拷贝第一个入口的东东,wrangle不能单独运行。
detail 模式是一个wrangle一个线程,addpoint要用循环,不用连接任何入口,可以单独运行。
wrangle节点要拷贝一份第一个入口的东东。
int point_num = chi("point_num"); float radius = ch("radius"); vector trans = chv("trans"); int row = chi("row"); vector rot_axis = chv("rot_axis"); float pi = 3.1415926; if(ch("radius")>0) { for(float i = 0;i<point_num;i++) { //printf("%f %f %f\n",point.x,point.y,point.z); for(int j = 0;j<row;j++) { if(rot_axis == (0,0,0)) { return; } vector point_t = set(0,0,0); point_t.x = radius*sin(2*pi*i/point_num); point_t.y = radius*cos(2*pi*i/point_num); matrix m_rot = ident(); rotate(m_rot,2*pi*j/row,rot_axis); point_t *= m_rot; //printf("%g\n",m_rot); matrix m_tan = ident(); translate(m_tan,trans); //transpose(m_tan); //printf("%g\n",m_tan); point_t *= m_tan; addpoint(0,point_t); } } }