A collection of useful snippets for Houdini.
View contents
View contents
View contents
View contents
View contents
View contents
View contents
View contents
createAGroup
pointsInAGroup
ToTestAPointGroupMembership
ToTestAPrimitiveGroupMembership
ToTestAVertexGroupMembership
PointsInGroupCounter
PrimitivesInGroupCounter
VerticesInGroupCounter
PointsListInGroup
PrimitivesListInGroup
VerticesListInGroup
PointGroupsList
PrimitiveGroupsList
VertexGroupsList
EdgeGroupsList
GroupExpand
View contents
View contents
View contents
Mask creation from metaball.
// Mask from metaball [Point Wrangle]
f@mask = clamp(metaweight(@OpInput2,@P),0,1);
@Cd = f@mask;
Remapping random from 0:1 to -1:1.
// Remaping random from 0:1 to -1:1 [Point Wrangle]
float random = rand(@ptnum)*2-1;
Sets normals in direction from center of circle (start of coordinate system (0,0,0)).
// Sets normals in direction from center of circle [Point Wrangle]
vector k = set(0,0,0);
v@N = normalize(k+@P);
Sets a geometry to always appear without lighting in scene.
// Set true (1) for ON and false (0) for OFF. Need Detail in Run Over [Attribute Wrangle]
@gl_lit = 1;
Showing a geometry as wireframes.
// Set true (1) for ON and false (0) for OFF. Need Detail in Run Over [Attribute Wrangle]
@gl_wireframe = 1;
Uniformly expanding group by a specified distance.
// Need a group filter ('group1') [Point Wrangle]
int pc = pcopen(0, 'P', @P, ch('radius'), chi('maxpts'));
while (pciterate(pc) > 0)
{
int currentpt;
pcimport(pc, 'point.number', currentpt);
setpointgroup(0, 'group1', currentpt, 1);
}
Create a group.
// Creation of group called 'mask' (@group_ is a virtual attribute)
i@group_mask = 1;
// Creation of group 'mygroup' for each point [Point Wrangle]
setpointgroup(0, "mygroup", @ptnum, 1);
// Creation of group 'mygroup' for each primitive [Primitive Wrangle]
setprimgroup(0, "mygroup", @primnum, 1);
// Creation of group 'mygroup' for each vertex [Vertex Wrangle]
setvertexgroup(0, "mygroup", @primnum, 1);
// Creation of group 'mygroup' for each edge between
// @primnum and @primnum+1 [Attribute Wrangle with Edges Group Type]
setedgegroup(0, "mygroup", @primnum, @primnum+1, 1);
Shows how many elements in a group.
// Points in a group ('mygroup') counter [Point Wrangle]
i@count = npointsgroup(0, 'mygroup');
Shows how many elements in a group.
// Points in a group ('mygroup') counter [Point Wrangle]
i@count = nprimitivesgroup(0, 'mygroup');
Shows how many elements in a group.
// Points in a group ('mygroup') counter [Point Wrangle]
i@count = nverticesgroup(0, 'mygroup');
Returns a string array of existing point groups.
// Array of existing point groups
s[]@list = detailintrinsic(0, 'pointgroups');
Returns a string array of existing primitive groups.
// Array of existing primitive groups
s[]@list = detailintrinsic(0, 'primitivegroups');
Returns a string array of existing vertex groups.
// Array of existing vertex groups
s[]@list = detailintrinsic(0, 'vertexgroups');
Returns a string array of existing edge groups.
// Array of existing edge groups
s[]@list = detailintrinsic(0, 'edgegroups');
Creation of list of points numbers in a group.
// List of points in a group [Point Wrangle]
i[]@list = expandpointgroup(0, 'mygroup');
Creation of list of primitives numbers in a group.
// List of primitives in a group [Primitive Wrangle]
i[]@list = expandprimgroup(0, 'mygroup');
Creation of list of vertices numbers in a group.
// List of primitives in a group [Vertex Wrangle]
i[]@list = expandvertexgroup(0, 'mygroup');
Create an array.
// Local integer array of size 5
int array[] = {0,1,2,3,4};
// Global string array of size 2
s[]@array = {'example_0.rat', 'example_1.rat'};
// Local string array of size 2
string array[] = {'example_0.rat', 'example_1.rat'};
Generate an array.
// Procedurally generated array of size 10
i[]@myarray;
for(int i=0; i<10; i++){
append(@myarray, i);
}
// Output: [ 0,1,2,3,4,5,6,7,8,9 ]
// Procedurally generated vector array of size '@numpt'
v[]@myarray;
for(int i=0; i<@numpt; i++){
vector item = point(0, 'P', i);
insert(@myarray, 0, item);
}
// Output: [ (4.24242, 0.0, 5.0), (3.53535, 0.0, 5.0), etc. ]
Iterating over array elements (every second).
// Need listing input primitive numbers on detail
int importarray[] = detail(0, 'prims');
foreach(int i; importarray){
if(i%2 == 0){
setprimattrib(0, 'Cd', i, {0,1,0.2});
}
}
Visualize of n-gons on geometry.
// Visualize of n-gons on geometry [Primitive Wrangle]
if (primvertexcount(0, @primnum) < 4){
@Cd = set(0, 1, 0.2);
}
Creation of helix from curve.
// Creation of helix from curve [Point Wrangle]
float freq, amp;
vector pos = @P;
freq = chf("freq");
amp = chf("amp");
pos.x += sin(pos.y * freq) * amp;
pos.z += cos(pos.y * freq) * amp;
@P = pos;
Sorting circle points.
//Sorting points in a circle (z and y axis) [Point Wrangle]
vector center = getbbox_center(0);
@P -= center;
@grad = atan2(@P.z,@P.y);
@P += center;
// After that needing sort by attribute 'grad'
Replacing primitives with points and adding points at each of their centers.
// Points in center [Primitive Wrangle]
addpoint(0,@P);
removeprim(0,@primnum,0);
Assigning a point to a group. If points’ position on X axis is more than 0, assign the point to the “mygroup”.
// Points in a group [Point Wrangle]
if(@P.x>0) @group_mygroup = 1;
Returns a boolean value whether a point is a member of specified group.
// Points in a group [Point Wrangle]
i@ismember = inpointgroup(0, "group1", @ptnum);
Returns a boolean value whether a primitive is a member of specified group.
// Primitive in a group [Primitive Wrangle]
i@ismember = inprimgroup(0, "group1", @primnum);
Returns a boolean value whether a vertex is a member of specified group.
// Vertex in a group [Vertex Wrangle]
i@ismember = invertexgroup(0, "group1", @vtxnum);
Cut geometry from selected camera with the ability to crop.
// Camera Frustrum [Point Wrangle]
vector pos = toNDC("/obj/cam1", @P);
if (pos.x < 0+ch('overLeft')) removepoint(0, @ptnum);
if (pos.x > 1-ch('overRight')) removepoint(0, @ptnum);
if (pos.y < 0+ch('overDown')) removepoint(0, @ptnum);
if (pos.y > 1-ch('overUp')) removepoint(0, @ptnum);
Preserves the silhouette of the geometry in the selected camera, regardless of its distance.
// Silhouette Retain [Point Wrangle]
vector pos = toNDC("/obj/cam1", @P);
pos.z += ch("offset");
@P = fromNDC("/obj/cam1", pos);