Advertisement
yashpolke

Vex_Codes

Sep 20th, 2017
5,623
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 15.97 KB | None | 0 0
  1. Bend multiples curves randomly
  2. float seed = chf('seed');
  3. int points[] = primpoints(0, @primnum);
  4.  
  5. matrix3 matrx = ident();
  6. float angle = radians( chf('angle') ) * rand(@ptnum+seed);
  7. vector axis = {1, 0, 0};
  8.  
  9. vector init_pos = point(0, "P", points[0]);
  10. vector prev_pos = init_pos;
  11.  
  12. for (int n=0; n<len(points); n++){
  13.     vector curr_pos = point(0, "P", points[n]);
  14.     rotate(matrx, angle, axis);
  15.    
  16.     // init_pos *= 0.01; // spiral
  17.     vector new_pos = (curr_pos - init_pos)*matrx + prev_pos;
  18.     init_pos = curr_pos;
  19.     prev_pos = new_pos;
  20.    
  21.     setpointattrib(0, "P", points[n], new_pos);
  22.     }
  23. ------------------------------------------------------------------------------------------------------------------------
  24.  
  25.  
  26. Control emission direction
  27.  
  28. if(!haspointattrib(0, 'id')) i@id = i@ptnum;
  29.  
  30. vector src    = getbbox_center(0);
  31. vector target = getbbox_center(1);
  32.  
  33. //Get direction
  34. vector dir = `chs('change_dir')`1*normalize(target - src);
  35.  
  36. //Get mmagnitude
  37. float mag = distance(src, target) * chf('magnitude_mult');
  38.  
  39. //Set magnitude randomness
  40. float rand = fit01(rand(@ptnum), ch('rand_v_var_limitx'), ch('rand_v_var_limity'));
  41. int rndss = chi('randomness');
  42. vector condition = (rndss != 1) ? (v@v = dir * mag) : (v@v = dir * mag * rand);
  43.  
  44. //Set directional randomness
  45. vector out = normalize(@P - src) * mag;
  46. int drndss = chi('directional_randomness');
  47. float bias = chf('bias');
  48. float dseed = chf('directional_seed');
  49. v@v = lerp(v@v, out, bias * rand(@ptnum+dseed));
  50.  
  51. //Set initial random rotations
  52. float amount = radians(fit01(rand(@id), -ch('init_anglex'), ch('init_angley')));
  53. vector seed;
  54. seed.x = rand(@id+1);
  55. seed.y = rand(@id+2);
  56. seed.z = rand(@id+3);
  57. vector axis = fit01(rand(seed),{-1,-1,-1},{1,1,1});
  58. matrix rm=ident();
  59. rotate(rm, amount, axis);
  60. v@v = v@v * rm;
  61. v@w = vector(fit01(rand(@ptnum), ch('angular_w_varx'), ch('angular_w_vary'))) * length(v@v);
  62. p@orient = {0, 0, 0, 1};
  63. ----------------------------------------------------------------------------------------------------------------------------
  64. Xform matrix for volumes:
  65.  
  66. float angle      = chf('angle');
  67. vector axis      = chv('axis');
  68. vector translate = chv('translate');
  69. vector scale     = chv('scale');
  70.  
  71. //store old position
  72. vector o_pos = @P;
  73.  
  74. //extract matrix
  75. matrix m4 = primintrinsic(0, 'packedfulltransform', 0);
  76.  
  77. //put to origin
  78. @P *= invert(m4);
  79.  
  80. //make matrix for xforms
  81. matrix rm = ident();
  82. rotate(rm, angle, axis);
  83. translate(rm, translate);
  84. scale(rm, scale);
  85. setprimintrinsic(0, 'transform', i@primnum, rm, 'mult');
  86.  
  87. //put it back
  88. @P = o_pos;
  89. ----------------------------------------------------------------------------------------------------------------------
  90. Minpos ray:
  91. float d = chf('distance');
  92.  
  93. int nearpoint = nearpoint(1, @P);
  94.  
  95. vector nearpos = point(1, 'P', nearpoint);
  96.  
  97. @P = minpos(1, nearpos, d);
  98. ----------------------------------------------------------------------------------------------------------------------
  99. Matrix to origin:
  100. vector min = {0, 0, 0};
  101. vector max = {0, 0, 0};
  102. getpointbbox(0, min, max);
  103. vector centroid = (max + min)/2.0;
  104.  
  105. // Build and apply transformation matrix
  106. vector translate = centroid;
  107. vector rotate = chv('rotation');
  108. vector scale = chv('scale');
  109. matrix xform = invert(maketransform(0, 0, translate, rotate, scale));
  110. @P *= xform;
  111.  
  112. // Store transformation matrix in attribute
  113. 4@xform_matrix = xform;
  114. ----------------------------------------------------------------------------------------------------------------------
  115. Facing ratio:
  116. vector cam_pt = -normalize(point(1, 'P', 0));
  117. vector N      = normalize(@N);
  118.  
  119. v@Cd = chramp("ramp", pow(dot(N, cam_pt), 1));
  120. ----------------------------------------------------------------------------------------------------------------------
  121.  
  122. Lerp dent:
  123.  
  124. float bias = chf('bias');
  125. float e_corr = chf('e_corr');
  126.  
  127. vector primpos;
  128. float u, v;
  129.  
  130. int nearpoint  = nearpoint(1, v@P);
  131. //vector nearpos = normalize(v@P - point(1, 'P', nearpoint));
  132.  
  133. vector orig = v@P;
  134. //vector dir = nearpos;
  135. vector dir = normalize(point(1, 'N', nearpoint));
  136.  
  137. int prim_num = intersect(1, orig, dir, primpos, u, v);
  138.  
  139. v@P += dir*e_corr;
  140. v@P = lerp(primpos, v@P, bias);
  141.  
  142.  
  143. ----------------------------------------------------------------------------------------------------------------------
  144. Facing ratio:
  145. vector cam_pt = -normalize(point(1, 'P', 0));
  146. vector N      = normalize(@N);
  147.  
  148. v@Cd = chramp("ramp", pow(dot(N, cam_pt), 1));
  149. --------------------------------------------------------------------------------------------------------------------------
  150. Create resampled line:
  151.  
  152. int resample = chi('resample');
  153.  
  154. int points[];
  155. resize(points, resample);
  156.  
  157. vector p1 = getbbox_center(1);
  158. vector p2 = getbbox_center(2);
  159.  
  160. float length = length(p2 - p1);
  161. vector dir = normalize(p2 - p1);
  162.  
  163. float step = length/(resample-1);
  164.  
  165. for(int i=0; i<resample; i++){
  166.     vector pos = p1 + (dir * (step * i));
  167.     int id     = addpoint(0, pos);
  168.     points[i]  = id;
  169. }
  170. addprim(0, 'polyline', points);
  171. --------------------------------------------------------------------------------------------------------------------------
  172. Calculate largest piece:
  173. float maxvol = 0;
  174. i@largest = -1;
  175. for (int i=0; i<@numprim; i++) {
  176.     float bounds[] = primintrinsic(0, "bounds", i);
  177.     float volume = (bounds[1]-bounds[0])*(bounds[3]-bounds[2])*(bounds[5]-bounds[4]);
  178.     if (volume>maxvol) {
  179.         maxvol = volume;
  180.         @largest = i;
  181.     }
  182. }
  183.  
  184. --------------------------------------------------------------------------------------------------------------------------
  185. Anim age:
  186.  
  187. float af = fit01(rand(@id), chf('startframe'), chf('endframe'));
  188. float life = chf('life');
  189. f@af = af;
  190.  
  191.  
  192. float anim_value = fit(@Frame, af, af+life, 0, 1);
  193.  
  194. f@age = ((af + anim_value))%1;
  195.  
  196. f@norm_age = f@age / life;
  197.  
  198. float ramp = chramp('grad_ramp', clamp(f@grad*f@age,0,1));
  199.  
  200. //f@test = f@grad * f@age;
  201. if(@Frame < af || @Frame >af+life){
  202.     v@Cd *= {0,0,0};      
  203. }
  204. else{
  205.     v@Cd *= ramp;
  206.  
  207. //    v@Cd = ramp * f@grad * f@age;
  208. }
  209.  
  210. --------------------------------------------------------------------------------------------------------------------------
  211.  
  212.  
  213. //Copy pieces to points with rotations
  214. int seed = chi('seed');
  215.  
  216. vector4 __orient = point(1, 'orient', i@ptnum);
  217. matrix3 __rm     = qconvert(__orient);
  218. float __pscale   = point(1, 'pscale', i@ptnum);
  219.  
  220. //match position to points
  221. v@P = point(1, 'P', i@ptnum+seed);
  222.  
  223. //make identity matrix for scaling
  224. matrix3 __im   = ident();
  225. vector __scale = set(__pscale, __pscale, __pscale);
  226. scale(__im, __scale);
  227. __rm *= __im;
  228.  
  229. //set transform matrix
  230. setprimintrinsic(geoself(), 'transform', i@primnum, __rm, 'mult');
  231.  
  232.  
  233. --------------------------------------------------------------------------------------------------------------------------
  234. Create rotation matrix:
  235. ///Create local matrix
  236. v@pos = v@P;
  237.  
  238. vector zero = point(0, 'P', 0);
  239. vector one = point(0, 'P', 1);
  240. vector two = point(0, 'P', 2);
  241.  
  242. v@x = normalize(one - zero);
  243. v@y = normalize(cross(v@x, (two - zero)));
  244. v@z = normalize(cross(v@x, v@y));
  245.  
  246. ///Create rotation matrix
  247. //Get vectors
  248. vector x = point(1, 'x', i@ptnum);
  249. vector y = point(1, 'y', i@ptnum);
  250. vector z = point(1, 'z', i@ptnum);
  251.  
  252. //make 3x3 matrix current
  253. matrix3 m31 = set(v@x, v@y, v@z);
  254. //make 3x3 matrix destination
  255. matrix3 m32 = set(x, y, z);
  256.  
  257. //matrix to extract
  258. matrix m4 = matrix(invert(m31) * m32);
  259.  
  260. //extract rotation
  261. vector rotation = cracktransform(0, 0, 1, {0,0,0}, m4);
  262.  
  263. vector pos1 = point(1, 'pos', i@ptnum);
  264.  
  265. //get translation
  266. vector translate = pos1 - v@pos;
  267.  
  268. //create rotation matrix
  269. 4@xform = maketransform(0, 0, translate, rotation, {1,1,1}, v@pos, {0,0,0}, {0,0,0});
  270.  
  271. ///After use attribCopy to transfer rotation matrix attribute don't match P along with transform by attribute
  272.  
  273. -------------------------------------------------------------------------------------------------------------------------
  274. Color by bbox:
  275. float e = chf('e');
  276.  
  277. v@Cd = {0,0,0};
  278.  
  279. float value = pow(1-relbbox(v@P).`chs('axis')`, e);
  280.  
  281. setcomp(v@Cd, value, atoi(chs('num_component')));
  282.  
  283. -------------------------------------------------------------------------------------------------------------------------
  284.  
  285. Create lines by proximity:
  286. float maxdist = chf( 'maxdist' );
  287. // Create an array of points to be queried
  288. int nearpts[] = nearpoints( 0, v@P, maxdist );
  289.  
  290. foreach( int pt; nearpts ){
  291.     if( pt != i@ptnum ){
  292.         int line = addprim( 0, 'polyline' );
  293.         addvertex( 0, line, i@ptnum );
  294.         addvertex( 0, line, pt );
  295.         }
  296. }
  297.  
  298. Create Lines:
  299. int i;
  300. int p1 = @opinput1_ptnum;
  301. for ( i = 0; i < i@numpt; i++ )
  302. {
  303.     int line = addprim( geoself(), "polyline" );
  304.     addvertex(geoself(), line, i);
  305.     addvertex(geoself(), line, p1);
  306.    
  307. }  
  308. -------------------------------------------------------------------------------------------------------------------------
  309. Cull by frame duration:
  310. float start = chf( 'start' );
  311. float end   = chf( 'end' );
  312. float duration = chf( 'duration' );
  313.  
  314. if (@Frame < start || @Frame > end ) removepoint(0,@ptnum);
  315. -------------------------------------------------------------------------------------------------------------------------
  316. Curve line in axes:
  317.  
  318. float amp = chf( 'amp' );
  319. float pow = chf( 'pow' );
  320.  
  321. float grad = pow( float( @ptnum ) / ( float( @numpt - 1 ) ), pow);
  322.  
  323. // Cuve in axes
  324. int condition_x = ch( "axis" ) == 0;
  325. int condition_y = ch( "axis" ) == 1;
  326. int condition_z = ch( "axis" ) == 2;
  327.  
  328.  
  329. if ( condition_`chs( "axis" )` ) {
  330.     @P.`chs( "axis" )` `chs( "sign" )`= chramp( "ramp", grad ) * amp;
  331.     }
  332.  
  333. -------------------------------------------------------------------------------------------------------------------------
  334. Group by axis:
  335. vector min, max;
  336. getbbox( min, max );
  337.  
  338. if ( @P.z <= min.z + chf( 'thresh' ) ) ( @group_left = 1 ); else( @group_right = 1 );
  339.  
  340.  
  341. -------------------------------------------------------------------------------------------------------------------------
  342. Group name to attr:
  343. i@`chs("group_name")` = 1;
  344. -------------------------------------------------------------------------------------------------------------------------
  345. Iso by VolumeSample:
  346. float sdf = volumesample( s@OpInput2, 0, v@P );
  347.  
  348. int condition_on = sdf > 0;
  349. int condition_off = sdf < 0;
  350.  
  351. if ( condition_`chs("iso")` )
  352. {
  353.     removepoint( 0, i@ptnum );
  354. }
  355. -------------------------------------------------------------------------------------------------------------------------
  356. Iso pieces by dist:
  357. float maxdist = chf( "maxDist" );
  358. int maxpoints = chi( "maxPoints" );
  359.  
  360. i@pts = pcfind( s@OpInput2, "P", v@P, maxdist, maxpoints )[1];
  361.  
  362. f@dist = distance( v@P, point( 1, "P", i@pts ) );
  363.  
  364. if ( f@dist <= chf( "thresh" ) )
  365. {
  366.     @group_activeChunks = 1;
  367. }
  368. else
  369. {
  370.     @group_inactiveChunks = 1;
  371. }
  372. -------------------------------------------------------------------------------------------------------------------------
  373. Lerp vecs:
  374. float i = chf( 'interpolation' );
  375. string sv = chs( 'sv' );
  376. vector vec1 = point( 1, sv, i@ptnum );
  377.  
  378. v@v = lerp( v@v, vec1, i  );
  379. -------------------------------------------------------------------------------------------------------------------------
  380. Names by class:
  381. s@name = sprintf( "unique_name_&d", i@class );
  382. -------------------------------------------------------------------------------------------------------------------------
  383. Particles rots:
  384. v@N = normalize(fit01(rand(@ptnum+1), (vector) -1, (vector) 1));
  385.  
  386. f@rot_mag = fit01(rand(@ptnum+2), ch("rot_min"), ch("rot_max"));
  387.  
  388. v@rot_axis = fit01(rand(@ptnum+3), (vector) 1, (vector) -1);
  389. v@rot_axis = normalize(v@rot_axis);
  390.  
  391. f@pscale = fit01(chramp("pscaleRamp", rand(@ptnum+4)), ch("pscale_min"), ch("pscale_max"));
  392.  
  393.  
  394. v@v += v@N * 0.1;
  395. -------------------------------------------------------------------------------------------------------------------------
  396. Particles v variation:
  397. //ID ATTRIBUTE
  398. if (!hasattrib(0, 'point', 'id')) i@id = int(i@ptnum + @Frame);
  399.  
  400. //PREOFFSET
  401. v@P += v@v * (@TimeInc * rand(@id) * ch("preoffset"));
  402.  
  403. //ANGLE VARIATION
  404. float amount = radians(fit01(rand(@id), -ch("angle"), ch("angle")));
  405. vector seed;
  406. seed.x = rand(@id+1);
  407. seed.y = rand(@id+2);
  408. seed.z = rand(@id+3);
  409.  
  410. vector axis = fit01(rand(seed),{-1,-1,-1},{1,1,1});
  411. matrix rm=ident();
  412. rotate(rm, amount, axis);
  413. v@v = v@v * rm;
  414.  
  415. //MAGNITUDE VARIATION
  416. v@v *= fit01(rand(@id),ch("min"),ch("max"));
  417.  
  418. //ADDITIONAL VEL DIRECTION
  419. vector v_dir0 = normalize(v@v);
  420. vector v_dir1 = chv("dir1");
  421. vector v_dir2 = chv("dir2");
  422. if (ch("dir1_isRefPoint")) v_dir1 = normalize(v@P - v_dir1);
  423. if (ch("dir2_isRefPoint")) v_dir2 = normalize(v@P - v_dir2);
  424. vector v_dir = normalize(v_dir0*ch("dir0Weight") + v_dir1*ch("dir1Weight") + v_dir2*ch("dir2Weight"));
  425.  
  426. //CLAMP TO MAX VEL
  427. float v_mag = clamp(length(v@v), 0, ch("maxvel"));
  428. v@v = v_dir * v_mag;
  429.  
  430. //POST OFFSET
  431. v@P += v@v * (@TimeInc * rand(@id) * ch("postoffset"));
  432. -------------------------------------------------------------------------------------------------------------------------
  433. Pscale by age:
  434. float pow  = chf( 'exponent' );
  435. float mult = chf( 'mult' );
  436.  
  437. // Declare pscale
  438. f@pscale = fit01(pow(rand(@ptnum * chf( "seed" ) ),chf("pow")),chf("pscale1"),chf("pscale2"));
  439.  
  440. //Mult pscale by age
  441. f@pscale *= pow( chramp( 'ageRamp', f@nage ), pow ) * mult;
  442.  
  443. //Viz
  444. v@Cd = f@pscale;
  445. -------------------------------------------------------------------------------------------------------------------------
  446. Pscale by camdist:
  447. float pow  = chf( 'pow' );
  448.  
  449. vector cp = point( 1, 'P', 0 );
  450. float dist = distance( v@P, cp );
  451.  
  452. v@Cd = pow( chramp( 'ramp', dist ), pow );
  453.  
  454. f@pscale *= pow( chramp( 'ramp', dist ), pow );
  455. -------------------------------------------------------------------------------------------------------------------------
  456. Remove overlapping points:
  457. float @pscale = 0;
  458. vector @P;
  459. int @ptnum;
  460.  
  461. float searchradius = @pscale * 2;
  462.  
  463. if (len(pcfind(1, 'P', @P, searchradius, 1)))
  464.     removepoint(geoself(), @ptnum);
  465. -------------------------------------------------------------------------------------------------------------------------
  466. Rotate vecs:
  467. float x_angle = chf( 'x_angle' );
  468. float y_angle = chf( 'y_angle' );
  469. float z_angle = chf( 'z_angle' );
  470.  
  471. vector x_axis = chv( 'x_axis' );
  472. vector y_axis = chv( 'y_axis' );
  473. vector z_axis = chv( 'z_axis' );
  474.  
  475. vector4 xquats = quaternion( x_angle, x_axis );
  476. vector4 yquats = quaternion( y_angle, y_axis );
  477. vector4 zquats = quaternion( z_angle, z_axis );
  478.  
  479. matrix3 x_rotationMatrix = qconvert( xquats );
  480. matrix3 y_rotationMatrix = qconvert( yquats );
  481. matrix3 z_rotationMatrix = qconvert( zquats );
  482.  
  483. v@v *= x_rotationMatrix;
  484. v@v *= y_rotationMatrix;
  485. v@v *= z_rotationMatrix;
  486. -------------------------------------------------------------------------------------------------------------------------
  487. Sustain:
  488. float frame = @Frame;
  489. float fInterval1 = chf( "fInt1" );
  490. float fInterval2 = chf( "fInt2" );
  491.  
  492. @i = fit01( sin (floor( @Frame ) ),$RFSTART,$RFEND  );
  493. @u = fit01( rint( rand( i@ptnum ) ),1,50 ) * fit01( anoise( @Time ),0,1 );
  494.  
  495. if ( @i <= chf( "iThresh" ) || @u>= chf( "uThresh" )  )
  496. {
  497.     removepoint( 0, i@ptnum );  
  498. }
  499. -------------------------------------------------------------------------------------------------------------------------
  500. POPS rots:
  501. matrix rm=ident();
  502. rotate(rm, radians(f@rot_mag), v@rot_axis);
  503.  
  504. v@N = normalize(v@N * rm);
  505. v@w = (v@rot_axis * radians(f@rot_mag) * (1/@TimeInc));
  506.  
  507. v@up = cross(v@N, v@rot_axis);
  508. -------------------------------------------------------------------------------------------------------------------------
  509. Sops rots:
  510. v@N = normalize(fit01(rand(@ptnum+1), (vector) -1, (vector) 1));
  511.  
  512. f@rot_mag = fit01(rand(@ptnum+2), ch("rot_min"), ch("rot_max"));
  513.  
  514. v@rot_axis = fit01(rand(@ptnum+3), (vector) 1, (vector) -1);
  515. v@rot_axis = normalize(v@rot_axis);
  516.  
  517. f@pscale = fit01(chramp("pscaleRamp", rand(@ptnum+4)), ch("pscale_min"), ch("pscale_max"));
  518.  
  519.  
  520. v@v += v@N * 15;
  521.  
  522. -------------------------------------------------------------------------------------------------------------------------
  523. Blur density by velocity:
  524.  
  525. float fps = 1.0/ch("fps");
  526.  
  527. vector vel = volumesamplev(1, "vel", v@P);
  528. float steps = max(float(ch("steps")), 2);
  529. float d_mult = 1.0/steps;
  530. float s_mult = -d_mult*0.5;
  531. float sum = 0.0;
  532. int i;
  533.  
  534. for(i=0; i<steps; ++i)
  535. {
  536. float d = volumesample(0, "density", v@P - vel*fps*ch("length")*s_mult);
  537. sum += d * d_mult;
  538. s_mult += d_mult;
  539. }
  540.  
  541. f@density = sum;
  542. -------------------------------------------------------------------------------------------------------------------------
  543. ***String concat****
  544. s@`chs('string_attribute')` = concat('`chs('name_value')`_', itoa(int(i@`chs('connectivity_attr')`)));
  545. -------------------------------------------------------------------------------------------------------------------------
  546. ***Attrib expression***
  547.  
  548. if(@`chs('attribute')``chs('condition')` chf('threshold')){
  549.     `chs('operation')`;
  550. }
  551. -------------------------------------------------------------------------------------------------------------------------
  552. ***Nearpoint grad conical***
  553. int nearpt = nearpoint(1, v@P);
  554. float grad = point(1, 'grad', nearpt);
  555. vector p2  = point(1, 'P', nearpt);
  556. float bias = chf('bias');
  557.  
  558. v@P = lerp(v@P, p2, bias * grad);
  559. -------------------------------------------------------------------------------------------------------------------------
  560. ***Stick primuv***
  561. i@sourceprim;
  562. v@sourceprimuv;
  563.  
  564. float d = xyzdist(1, v@P, i@sourceprim, v@sourceprimuv);
  565. vector pos = primuv(1, 'P', i@sourceprim, v@sourceprimuv);
  566.  
  567. v@P = pos;
  568. -------------------------------------------------------------------------------------------------------------------------
  569. ***Stretch along velocity***
  570. vector v = v@v * @TimeInc;
  571. float d = dot( normalize(v@v), normalize(v@N) );
  572.  
  573. v@P += v*d * chf('mult');
  574. -------------------------------------------------------------------------------------------------------------------------
  575. -------------------------------------------------------------------------------------------------------------------------
  576. -------------------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement