Hiểu Về VEX Wrangle Houdini

Cơ bản nhất về Node Wrangle Viết VEX

Nên coi 20 ngày với VEX (Joy Of Vex), biên soạn bởi CGWiki, tài liệu rất tốt và miễn phí để tiếp cận VEX dễ dàng.

Thực Hành Vex

Các biến dạng số, thích hợp dùng cho random

@elemnum 

ví dụ có thể dùng rand(@elemnum) cho các số random thay vì lấy từ random point ID.

Value

$FF = @Frame

$PT = @ptnum

$PR = @primnum

$NPT = @ptnum

Array (mảng)

float test[] = {0,1,2,3,4,5}

hoặc

f[]@test = {0,1,2,3,4,5}

Loop (vòng lặp)

f[]@test ;
for (int i = 0; i<10; i++ ){
    push(@test ,i)
}

List Match (dạng danh sách list)

int idlist[];
idlist = {1523,145,1738,1739,1743,1755,1756,159,1711,204,205,211,152,151,1742,1715,1706};
if(find(idlist,@id)>=0){
    @Cd = {0,1,0};
}

Điều kiện (Condition match)

int condition = (@P.x>0) ? 1:0;

ví dụ dùng để tạo noise 

@P=set(@P[0] , noise(set(@P[0],0,@P[2])) , @P[2]);

Using Channel

Just use ch(“parm”)

Importing point attribute from other slot

@P = point(@OpInput2,”P”,@ptnum);

or

@P = point(1,”P”,@ptnum);

or

@P = @opinput1_P;

@P.y = point(@OpInput2,”test”,@ptnum);

@P = point(“op:../box3″,”P”,@ptnum);

Attribute Variable Mapping

f@test = 1;
addvariablename(geoself(), "test", "TEST");

Intrinsic(float value is not supported yet)

i@test = primintrinsic(0,"typeid",@primnum);

Changing Intrinsic Attribute

setattrib(geoself(), “primintrinsic”, “volumebordertype”, @primnum, -1, “constant”, “set”);

setattrib(geoself(), “primintrinsic”, “volumebordervalue”, @primnum, -1, 0.0, “set”);

Mix

@Cd = lerp({1,0,0},{0,1,0},0);

Centroid

vector min, max;
getbbox(min,max);
vector center = (min+max)/2;

getbbox(1,min,max);

can get from other input

Point Cloud

pcopen(@OpInput2, “P”, @P, $radius, $maxpoints)

pcfilter($handle, $channel)

pcnumfound($handle)

pciterate($handle)

Format

int handle = pcopen(@OpInput2, "P", @P, 1000, 1);
@v = pcfilter(handle, "v");

pcclose(handle);

Loop

while (pciterate(handle)){

}

Loop

int closept[] = pcfind(1,"P",@P, 0.5,10);
foreach (int pt; closept){
    test += point(1, "test", pt);
}

SDF push

float volsample = volumesample(1, 0, @P);
vector volumegrad = volumegradient(1, 0, @P);
vector pushOut = volumegrad * -volsample;
@P = @P + pushOut;

Noise

vector freq = {1,1,1};

vector offset = {0,0,0};

float amp = 0;

int turb = 5;

float rough = 0.5;

float atten = 1;

onoise(@P*freq – offset, turb, rough, atten) * amp

snoise(@P*freq – offset, turb, rough, atten) * amp

anoise(@P*freq – offset, turb, rough, atten) * amp

vop_correctperlinNoiseVF(@P*freq – offset, turb, rough, atten) * amp

vop_correctperlinNoiseVV(@P*freq – offset, turb, rough, atten) * amp

vop_simplexNoiseVF(@P*freq – offset, turb, rough, atten) * amp

vop_simplexNoiseVV(@P*freq – offset, turb, rough, atten) * amp

vop_perlinNoiseVF(@P*freq – offset, turb, rough, atten) * amp

vop_perlinNoiseVV(@P*freq – offset, turb, rough, atten) * amp

Remove Points(need to be cleaned. prims still exist)

if (@P.y<0){
    removepoint(geoself(), @ptnum);
}

Remove by NDC

vector ndc=toNDC("/obj/cam1",@P);
float ov = 0;
@Cd = ndc;
if(ndc[0]-ov<0 || ndc[0]+ov>1 || ndc[1]-ov<0 || ndc[1]+ov>1 || ndc[2]>0){
    removepoint(geoself(),@ptnum);
}

Remove Prim

if (@numvtx!=4){
    removeprim(geoself(), @primnum, 1);
}

Remove by vertex UV

if(@uv.x<0.5){
int prim = vertexprim( 0, @vtxnum );
removeprim( 0, prim, 1);
}

Create centre Point(Detail)

vector min, max;
getbbox(min, max);
vector centre = (min+max)/2;
for( int i=0; i<npoints(@OpInput1); i++ ){
    removepoint(geoself(), i);
}
int centPoint = addpoint(geoself(),centre);

Line to next Point

int a = addprim(geoself(), "polyline");
addvertex(geoself(), a, @ptnum);
addvertex(geoself(), a, @ptnum+1);

Isolating Edge Group

int edge_group[] = expandedgegroup(1, "group2");
for (int i = 0; i<len(edge_group); i+=2 ){
    int line = addprim(0, "polyline");
    int point1 = addpoint(0, vector(point(1,"P",edge_group[i])) );
    int point2 = addpoint(0, vector(point(1,"P",edge_group[i+1])) );
    addvertex(0, line, point1);
    addvertex(0, line, point2);
} 

Adding Point and Line

int pp = addpoint(geoself(), @P + set(0,1,0) );
int a = addprim(geoself(), "polyline");
addvertex(geoself(), a, @ptnum);
addvertex(geoself(), a, pp);

For Loop

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

Neighbour Loop

f@A = 0;
for( int i=0; i<neighbourcount(0, @ptnum); i++ ){
    int np = neighbour(0,@ptnum,i);
    @A += point(0,"attr", np);
}

Resample (prim)

int segment = 50;
for( int i=0; i<=segment; i++ ){
vector a = primuv(0, "P", @primnum, set(float(i)/segment,0));
int pp = addpoint(geoself(), a );
addvertex(geoself(), @primnum, pp);
}
for( int i=0; i<primvertexcount(0, @primnum); i++ ){
    removepoint(geoself(), primpoint(0, @primnum, i));
}

Comment Block

/*
comment
*/
 Nguồn

Post Author: Vu Pham