Saori Yoshimoto work notes since 2018

Showing posts with label Houdini/Code/VEX. Show all posts
Showing posts with label Houdini/Code/VEX. Show all posts

Monday, September 20, 2021

[VEX] Modify Packed Primitive: Intrinsic

◆PackedAlembic

--Transform off (= jump to origin)

setprimintrinsic(0, "abcusetransform", @primnum, 0, "set");


--back to default pos

-Transform position on point

@P = point(1, "P", @primnum);

-Transform scale & rot on prim

matrix xform = primintrinsic(1, "packedfulltransform", @primnum);

matrix scale = ident() * 100;

matrix3 rot = matrix3(xform * scale);

setprimintrinsic(0, "transform", @primnum, rot, "set");

Tuesday, August 17, 2021

Tuesday, July 6, 2021

[POP] Kill node code sample

if((@Frame > 50) && (@id % 5 == 0)) { dead = 1; }

-Pop Kill how to set conditions to kill particles after certain frames

Wednesday, August 12, 2020

[VEX] uniqueval, nuniqueval

uniqueval()

int|string uniqueval(<geometry>geometrystring attribclassstring attribute_nameint which)

i.g.)
int count = nuniqueval(0, "point", "foo");
for (int i = 0; i < count; i++) {
    string val = uniqueval(0, "point", "foo", i);
    // ...do something with the value...
}

nuniqueval()

int  nuniqueval(<geometry>geometrystring attribclassstring attribute_name)

i.g.)
int test = nuniqueval(0, "point", "foo") == npoints(0)

Saturday, October 19, 2019

[VEX] string functions

re_replace()
string  re_replace(string regex, string replacement, string input, int maxreplace=0)
e.g.)
string label = "apple0";
s@name = re_replace("0", "1", label);

split()
string [] split(string s)
string [] split(string s, string separators)
string [] split(string s, string separators, int maxsplits)
e.g.)

Friday, October 18, 2019

[VEX] get the current OP name : opfullpath

e.g.1)
string dir, name;
splitpath(opfullpath("."), dir, name);
return opdigits(name);
e.g.2)
opfullpath(".") - The full path of the current node being evaluated
opfullpath("..") - The full path of the current node’s parent

Thursday, October 17, 2019

[VEX] get attrib VEX function

getattrib()
<type>   getattrib(<geometry>geometry, string attribclass, string attribute_name, int elemnum, int &success)
<type>[] getattrib(<geometry>geometry, string attribclass, string attribute_name, int elemnum, int &success)
e.g.)
int success;
v@accel = getattrib(1, "point", "accel", opdigits(s@name), success);

Wednesday, October 9, 2019

[VEX] Loops and flow control

https://www.sidefx.com/docs/houdini/vex/statement.html

-for loop
for( int i=0; i<10; i++ ){
   int pp = addpoint(geoself(), set(0,i,0));
}

-foreach loop
foreach (value; array) statement
foreach (index, value; array) statement

Wednesday, September 25, 2019

[VEX] get bbox

------- getbbox
void  getbbox(<geometry>geometryvector &minvector &max)
void  getbbox(<geometry>geometrystring primgroupvector &minvector &max)
void  getbbox(vector &minvector &max)
------- getbbox_center
------- getbbox_max

Thursday, September 12, 2019

[VEX] get primitive info from hit point (xyzdist, prim_normal, primuv)

ray node(SOP): Automatically generate attributes int hitprim, vector hitprimuv
e.g.)
int    success;
s@name = getattrib(1, "prim", "name", i@hitprim, success);

xyzdist() (Can get distance to the surface &amp; primnum &amp; Parametric UV)
float  xyzdist(<geometry>geometry, vector origin)
float  xyzdist(<geometry>geometry, vector origin, int &prim, vector &uv)
float  xyzdist(<geometry>geometry, vector origin, int &prim, vector &uv, float maxdist)
e.g.)
float maxdist = 10;
@dist      = xyzdist(1,@P,i@pr,v@uv,maxdist);
@P         = primuv(1,"P",@pr,@uv);

Thursday, September 5, 2019

[VEX] Custom pivot location on packed primitives

How cool this method, isn't it?!
  • sample
https://forums.odforce.net/topic/29350-custom-pivot-location-on-packed-primitives/


vector pivotOffset= chv("PivotOffset");
vector pivotCentroid =  primintrinsic(0, "pivot", @ptnum);
vector newPivot = pivotCentroid + pivotOffset;

setprimintrinsic(0, "pivot", @ptnum, newPivot);
@P += pivotOffset;


Wednesday, September 4, 2019

[VEX] pcopen exsample..

int handle = pcopen(0,"P", @P, chf('cohesion_radius'), chi('max_point')); vector avg_P = pcfilter(handle,"P"); vector dir = normalize(avg_P - @P); v@force += dir * chf('cohesion_strength'); v@dir_co = dir; pcclose(handle);

Monday, July 15, 2019

[VEX] VEX expressions

VEX type Syntax
float f@name
vector2 (2 floats) u@name
vector (3 floats) v@name
vector4 (4 floats) p@name
int i@name
matrix2 (2×2 floats) 2@name
matrix3 (3×3 floats) 3@name
matrix (4×4 floats) 4@name
string s@name



VEX type Attribute names
vector (3 floats) @P, @accel, @Cd, @N, @scale, @force, @rest, @torque, @up, @uv, @v
@center, @dPdx, @dPdy, @dPdz (see Volume Wrangle).
vector4 (4 floats) @backtrack, @orient, @rot
int @id, @nextid, @pstate
@elemnum, @ptnum, @primnum, vtxnum, @numelem, @numpt, @numprim, numvtx (see indexing variables below).
@group_* (see accessing group membership below).
@ix, @iy, @iz, @resx, @resy, @resz (see Volume Wrangle).
string @name, @instance

Thursday, April 4, 2019

[VEX] transform matrix

/*
matrix3  maketransform(vector zaxis, vector yaxis)
matrix  maketransform(vector zaxis, vector yaxis, vector translate)
matrix  maketransform(int trs, int xyz, vector t, vector r, vector s)
matrix  maketransform(int trs, int xyz, vector t, vector r, vector s, vector p)
matrix  maketransform(int trs, int xyz, vector t, vector r, vector s, vector p, vector pr)
matrix  maketransform(int trs, int xyz, vector t, vector r, vector s, vector p, vector pr, vector shears)
*/

vector t,r,s,p,pr;
t = chv('translate');
r = chv('rotate');
s = chv('scale');
p = chv('pivot');
pr= chv('pivotRoatation');

matrix transform = maketransform(0,0,t,r,s,p,pr);

@P *= transform;
---------------------------------------------------

0 - Scale, Rotate, Translate
1 - Scale, Translate , Rotate
2 - Rotate, Scale, Translate
3 - Rotate, Translate, Scale
4 - Translate, Scale, Rotate
5 -  Translate, Rotate, Scale

0 - Rotate - order X, Y, Z
1 - Rotate - order X, Z, Y
2 - Rotate - order Y, X, Z
3 - Rotate - order Y, Z, X
4 - Rotate - order Z, X, Y
5 - Rotate - order Z, Y, X

---------------------------------------------------
---------------------------------------------------
// Defines for the maketransform() VEX function.  The function takes two integer arguments which determine the order that the transform gets made.
#define XFORM_SRT 0 // Scale, Rotate, Translate
#define XFORM_STR 1 // Scale, Translate, Rotate
#define XFORM_RST 2 // Rotate, Scale, Translate
#define XFORM_RTS 3 // Rotate, Translate, Scale
#define XFORM_TSR 4 // Translate, Scale, Rotate
#define XFORM_TRS 5 // Translate, Rotate, Scale

#define XFORM_XYZ 0 // Rotate order X, Y, Z
#define XFORM_XZY 1 // Rotate order X, Z, Y
#define XFORM_YXZ 2 // Rotate order Y, X, Z
#define XFORM_YZX 3 // Rotate order Y, Z, X
#define XFORM_ZXY 4 // Rotate order Z, X, Y
#define XFORM_ZYX 5 // Rotate order Z, Y, X

#include <math.h>
vector t,r,s;
t = chv('translate');
r = chv('rotate');
s = chv('scale');
matrix m = maketransform( XFORM_SRT, XFORM_XYZ, t, r, s);
@P *= m;

Tuesday, March 26, 2019

[VEX] sample_direction_cone VEX function

vector sample_direction_cone(vector center, float maxangle, vector2 u)
 

center
Direction in the center of the cone. This does not need to be normalized.
 

maxangle
Maximum angle, in radians, away from center that any sample of the cone will be, so long as all u values are between 0 and 1.

u
Pair of numbers between 0 and 1.

Returns a unit vector, i.e. a vector of length 1, based on u. Given uniform random u pairs of values in [0,1), the returned unit vectors will be uniform random and continuous with respect to u on the surface of the unit sphere, in the area within maxangle of the direction indicated by center


See also

Monday, March 25, 2019

[VEX] rotate

e.g.1)
float angle = @Time;
vector axis = rand(@ptnum);
matrix3 m = ident();
rotate(m, angle, axis);
@orient = quaternion(m);
e.g.2)
float angle = @Time;
vector axis = rand(@ptnum);
@orient = quaternion(angle, axis);

e.g.3)

float angle = chf("angle");
vector4 rot = quaternion(radian(angle), {0, 1, 0});
@N = qrotate(rot, @N);

Thursday, February 7, 2019

[VEX] centroid in vex

-------calc centroid
vector min, max;
getbbox(min, max);
vector center = (min+max)/2;
 
Thx for reference!! 
 https://forums.odforce.net/topic/21514-centroid-in-pointwrangle/