float -> f@attribute
vector2 -> u@attribute
vector -> v@attribute
vector4 -> p@attribute
integer -> i@attribute
matrix2 -> 2@attribute
matrix3 -> 3@attribute
matrix4 -> 4@attribute
string -> s@attribute
Code
Some snippets that I use in my projects.
VEX attributes
Copy stamping
1. Connect all the different objects to ‘copy’ node to the input.
2. In CopySOP go to the option "stamp inputs"
3. In CopySOP -> Variable1 write the name of the Variable that you want; ex: id
4. In CopySOP -> Value1 write “fit01((rand(@ptnum))0,5,1.5)” .
5. In the input node write this expression: stamp("../”CopySOP node name”","Variable 1 name",1)
Randomize Pscale Attribute
// Useful for setting a believable pscale for things like debris. The number of bigger pieces should be a lot less than smaller ones.
float min = chf("min");
float max = chf("max");
float val = rand(@ptnum);
val = fit01( pow( val, 2,5), min, max);
f@pscale = val;
Infection
// Put this vex code in a wrangle node and then the wrangle node into a solver SOP node
if (@active == 0){
float search = ch('search');
float maxpnts = ch('maxpnts');
int spnts[] = nearpoints(0, @P, search, maxpnts);
int pt;
foreach(pt; spnts){
if(point(0, 'active' , pt) == 1){
@active = 1;
@Cd = {1,0,0};
}
}
}
Creating lines between two points
// example creating two points and then creating a primitive between them.
// Run on detail mode
vector pos0 = chv("pos0");
vector pos1 = chv("pos1");
//add points
int pt0 = addpoint( 0, pos0);
int pt1 = addpoint( 0, pos1);
// add a primitive
int prim = addprim( 0, "polyline");
//connect points to prim through vertex
addvertex( 0, prim, pt0);
addvertex( 0, prim, pt1);
RBD Constraints_Wrangle
[PUT THE RUN OVER ON PRIMITIVES ALWAYS]
//set the constraint name
s@constraint_name = "GLUE";
//set the constraint type
s@constraint_type = "all";
Object always in grid
vector min;
vector max;
getbbox (0, min, max);
if(min.y > 0){
@P.y -= abs(min.y);
}
else if (min.y < 0){
@P.y += abs(min.y);
}
Simple Morph
You must connect one object to the first input to the wrangle and the morphing object to the second input.
@Cd = relbbox(2,@P);
@P = lerp(@P,@opinput1_P, chf("v"));
Normal's Lerp
vector secpos= set(0,0,1);
@N = lerp(@N, secpos, chf("bias"));