Showing posts with label zero. Show all posts
Showing posts with label zero. Show all posts

Thursday, 12 September 2024

bringing object to origin

Not entirely sure how this deals with objects that move around A LOT, but for something mostly static that isn't near the origin it's good. Useful for simming stuff at zero then shoving back to where it came from.


In a point wrangle, move object to 0.0.0..

 // Get center of the oject bounding box (centroid)

vector min = {0, 0, 0};

vector max = {0, 0, 0};

getpointbbox(0, min, max);

vector centroid = (max + min)/2.0;


// Build and apply transformation matrix

vector translate = centroid + {0,-0.2,0};

vector rotate = {0,0,0};

vector scale = {1,1,1};

matrix xform = invert(maketransform(0, 0, translate, rotate, scale));

@P *= xform;


// Store transformation matrix in attribute

4@xform_matrix = xform;




Then in a later point wrangle, to revert back to original position


@P *= invert(4@xform_matrix);

Monday, 29 April 2024

padding zeroes in vex

 s@frameNum= sprintf('%04d',clamp((@Frame-1000),0,68));

//s@name = sprintf('%04d',@Frame);

s@textureFile=chs("part1")+@frameNum+chs("end");


slight update on zero padding in vex...

use sprintf to reformat numbers..

Wednesday, 14 September 2022

filename using digits of the node

 use case - you have many texture nodes, eg. Texture1, Texture2,Texture3.....

You want to automate the filename being loaded & use the number contained within the node name.

To do this we can use a combo of expressions -

//server/jobs/build/ion/textures/flooring/tile_`padzero(2,opdigits("$OS"))`.jpg

where the texture node is Texture5 becomes

//server/jobs/build/ion/textures/flooring/tile_05.jpg

So if we copy and paste this many times, it will update to tile_06, tile_99 etc...


padzero(2, SOMETHING) - pads the value SOMETHING with up to TWO zeroes. 5 becomes 05, 99 stays as 99.

opdigits("whatever") - returns the numbers of "whatever". In the example above, I use the $OS expression to get the name of the node itself-  ie; Texture5, so we get back 5. The padzero makes it 05.

these bits are enclosed with backticks  ` `, to execute the expressions.