VEX in Houdini

Return Array

function int[] test(){
int m[];
for(int i=0; i<5; i++){
append(m,i);
}
return m;
}

i[]@check = test();

Has Attribute

i@temp = 0;
if(hasattrib(geoself(),”point”,”id”)){
i@temp = 1;
}

Angle on a Curve

int n[] = neighbours(0,@ptnum);
vector dir[];

foreach(int i; n){
vector temp = normalize(@P-point(0,”P”,i));
append(dir,temp);
}

float bias = abs(dot(dir[0],dir[1]));

if(bias>0.9){
i@poop=1;
}

Start Activation Based on the First Impact

if(dopfield(“../../dopnet/”, “object”, “Impacts”, “Impacts”, 0, time)>0, 1, 0)

Constrain a Point on Surface

//input0=point, input1=static_geo, input2=animating_geo
vector goal; float u; float v;
int prim = intersect(1,@P,set(0,10,0),goal,u,v);

vector primuv = set(u,v);
@P = primuv(2, “P”, prim, primuv);

u on Curve

f@u = @ptnum / (npoints(0)-1.0);

Grow Attribute

int n[] = neighbours(0,@ptnum);

foreach(int i; n){
vector temp = point(0,”Cd”,i);
if(temp[1]>0){
@Cd = clamp(@Cd+temp,0,1);
}
}

N along a Curve

vector nextpos = point(0,”P”,@ptnum+1);
@N = normalize(nextpos-@P);

if(@ptnum == npoints(0)-1){
nextpos = point(0,”P”,@ptnum-1);
@N = normalize(@P-nextpos);
}

Intersect

string path = “op:/obj/geo/OUT”;

vector dir = {0,3,0};
vector goal;
float u,v;

int primnum = intersect(path,@P,dir,goal,u,v);

if(primnum == -1){
primnum = intersect(path,@P,dir*-1,goal,u,v);
}

@P = goal;

Center Points

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

for( int i=0; i<npoints(0); i++ ){
removepoint(0, i);
}

addpoint(0,center);

Remove Isolated Points

int handle = pcopen(0, “P”, @P, 100, chi(“pt”));
float pc_dist;
while (pciterate(handle)){
pcimport(handle, “point.distance”, pc_dist);
if ( pc_dist > chf(“dis”)){
removepoint(0, @ptnum);
}
}
pcclose(handle);

Attribute Smooth

int handle = pcopen(0,”P”,@P,1,chi(“pt”));
@N = pcfilter(handle, “N”);
pcclose(handle);

Deforming by xyz distance

int prim;
vector primuv;
float dist = xyzdist(1, @P, prim, primuv, 10000000000);

vector anim_P = primuv(1, “anim_P”, prim, primuv);
vector anim_N = primuv(1, “anim_N” prim, primuv);
vector rest_P = primuv(1, “P”, prim, primuv);

@P += anim_N * (anim_P – rest_P);

Velocity Limitation on RBD State (expression)

{
float vel_max = ch(“max_vel”);
vector velocity = vector3( $velx, $vely, $velz);
float vel_length = vlength( velocity );
if(vel_length > vel_max) {
velocity = normalize( velocity ) * vel_max;
}
float velx = velocity[0];
return velx;
}

Python in Houdini

Excution from Callback Script

exec(hou.pwd().parm(“python”).eval());export()

Collect Geo Nodes

import hou
ne = hou.ui.paneTabOfType(hou.paneTabType.NetworkEditor)
sel = hou.selectedNodes()

if not sel:
—-hou.ui.displayMessage(“Please select a subnet.”, title = “Error”)
else:
—-all = sel[0].children()
—-geo = []

—-for node in all:
——–type = node.type().nameComponents()
——–if type[2] == “geo”:
——–geo.append(node)

—-if not geo:
——–hou.ui.displayMessage(“There is no geo node inside.”, title = “Error”)
—-else:
——–exp_geo = hou.node(“/obj/”).createNode(“geo”, “export_geo”)
——–exp_geo.moveToGoodPosition()
——–mrg = hou.node(exp_geo.path()).createNode(‘merge’, “merge”)

——–for i,temp in enumerate(geo):
————path = temp.path()
————obj_mrg = hou.node(exp_geo.path()).createNode(‘object_merge’, str(temp))
————parm01 = obj_mrg.parm(“objpath1”)
————parm01.set(path)
————parm02 = obj_mrg.parm(“xformtype”)
————parm02.set(1)
————mrg.setInput(i,obj_mrg)

——–mrg.setDisplayFlag(True)
——–mrg.setRenderFlag(True)
——–exp_geo.layoutChildren()
——–ne.cd(exp_geo.path())

Python in Maya

Make Sequence & Unsequence

import maya.cmds as cmds

sel = cmds.ls(sl=True)
min = 1
max = 20
step = 1

for i in range(min,max+1,step):
—–cmds.currentTime(i)
—–dup = cmds.duplicate(sel, n=’temp’)

////////////////////////////////////////////////

import maya.cmds as cmds

sels = cmds.ls(sl=True)
num = len(sels)
cmds.playbackOptions(ast=1,min=1,aet=num,max=num)

for i in xrange(num):
—–each = sels[i]
—–cmds.currentTime(i+1)
—–cmds.hide(sels)
—–cmds.showHidden(each)
—–cmds.select(sels)
—–cmds.setKeyframe(at=’visibility’)

cmds.group()

Rename

import maya.cmds as cmds

name = ‘temp’

sel=cmds.ls(selection=True)
num = 0
for each in sel:
—–if num < 10:
———-cmds.select(each)
———-cmds.rename(name + ‘_0’ + str(num))
—–else:
———-cmds.select(each)
———-cmds.rename(name + ‘_’ + str(num))
—–num += 1

Pyside

# -*-coding: utf-8 -*-

def poop(*args):
—-print u”わんわんわんっ!!!!!!!!”

from PySide2.QtWidgets import *

window = QWidget()
window.resize(350,100)
window.setWindowTitle(u”Pyside Test”)

button01 = QPushButton(u”Push Me”)
button01.clicked.connect(poop)

vertical_layout = QVBoxLayout()
vertical_layout.addWidget(button01)
window.setLayout(vertical_layout)

window.show()

# Windowsで.py作成時は必要
import sys
app = QApplication(sys.argv)
sys.exit(app.exec_())

Qt designer

# -*-coding: utf-8 -*-

from PySide2.QtWidgets import *
from PySide2.QtUiTools import *
from functools import partial

def print_test():
—-print u”やっふ---!!!”

loader = QUiLoader()
main_window = loader.load(“C:/Users/poop/Desktop/Qt/poop.ui”)
main_window.My_Button.clicked.connect(partial(print_test))
main_window.show()