Showing posts with label wrangle. Show all posts
Showing posts with label wrangle. Show all posts

Saturday, July 14, 2018

Houville :: Alembic transform theft

Now that I'm typing this I'll probably not forget it. If I don't post this, I'll definitely forget it.
//Alembic packed info put onto existing geo.
matrix abc = primintrinsic(1,'packedfulltransform',0);
P *= abc;


This is kind of messed up, but handy if you want to freeze geo, affect it, but then have it resume animation from an incoming abc transform animation. Input 1 is the frozen and tweaked geo, 2 is the animated abc and 3 is the abc frozen on the same frame as 1.
//Alembic packed info from static frame subtracted out, then a the animated one put back in/
matrix abc = primintrinsic(1,'packedfulltransform',0);
matrix abcRef = primintrinsic(2,'packedfulltransform',0);

P *= invert(abcRef) * abc;

Saturday, April 1, 2017

Houville :: nice up vectors

This is for arranging your geo for nice behaviour with the copy sop. If you want to distibute geo, like trees or whatever, and control orientation but still respect the angle to the surface this is for you.


You'll need some way to connect the target points with the surface prim they relate to. Scatter has the sourceprim option which is cool, but if you want to manually do it you'll need a pre-pass. Here's an example using the 'stick a point in the middle of the face' technique. This should run over prims.
int newPtNum = addpoint(0,@P);
addpointattrib(0,"sourceprim", 0);
setpointattrib(0,"sourceprim", newPtNum, @primnum, 'set');
removeprim(0,@primnum,1);


Now lets get the surface geo ready. Here we will sneakily say normals run along the U direction and Up is what would typically be considered a normal. This makes sure our orientation makes sense.

Run this over points, assuming point source is in OpInput1, and reference geo for orientation is OpInput2.
vector center = primuv(s@OpInput2, 'P', i@sourceprim, {0.5,0.5,0.0});
vector dPdu = primuv(s@OpInput2, 'P', i@sourceprim, {0.51,0.5,0.0});
vector dPdv = primuv(s@OpInput2, 'P', i@sourceprim, {0.5,0.51,0.0});

vector u = normalize(dPdu - center);
vector v = normalize(dPdv - center);

v@up = normalize(cross(u,v));
v@N = u;

//matrix rotation shiz!
vector rot[];
rot[0] = u;
rot[1] = v@up;
rot[2] = v;
matrix3 mtx[] = unserialize(serialize(rot));
rotate(mtx[0], radians(chf('heading')), v@up);
rot = unserialize(serialize(mtx));
v@N = rot[0];
v@up = rot[1];



** for another post - passing colour information through points to be picked up by "Point Instance Procedural" as material overrides:
string r = sprintf("%d", @Cd.x);
string g = sprintf("%d", @Cd.y);
string b = sprintf("%d", @Cd.z);


s@shop_materialpath = chs('../theInstancesShaderPath');
s@material_override = "{'basecolorr':" + r + ",'basecolorg':" + g + ",'basecolorb':" + b + ",}";



Soooooo.. some of that was overkill. Here are a few ways to optimise that.

You can for example dispense with the serialise/unserialise phase by seting to the matrix directly. Also you can use quarternion to directly pull rotation information out of the matrix. Bear in mind Houdini understands '@orient' as a vector4 aka p@orient.
## direct casting and assignment of a matrix, rotation, extraction as a quaternion.
matrix3 rot = set(u,v@up,v)
rotate(rot, radians(chf('heading')), v@up);
p@orient = quaternion(rot)


And finally, you don't have to derive a @up if you have a normal. Have the points (scattered or otherwise) pick up their normals from the source they are based on. addpointattrib(0,"N",{0,0,0}); setpointattrib(0,"N",newPtNum,@N,"set");

Friday, March 3, 2017

Houville :: put points in the centre of prims

Points in centre of prim, and delete points:
addpoint(0, @P);
removeprim(0, @primnum, 1);


==EDIT== Just realised it can be handy to pull attributes from the prim on to the newly created points in the same primwrangle.
Here's how:
int newPt = addpoint(0, @P);
addpointattrib(0,"N",{0,0,0});
setpointattrib(0,"N", newPt, @N, "add");
removeprim(0, @primnum, 1);