目录
dihedral —— 计算旋转矩阵或四元数(将vector a旋转到vector b)
maketransform —— 构建3*3或4*4变换矩阵
packedtransform —— 对packed primtive进行变换
getpackedtransform —— 获取packed primitive的变换
setpackedtransform —— 设置packed primitive的变换
solvecurve —— 返回本地骨旋转的vector/matrix3矩阵
solvefbik —— 应用full-body反向运动学算法
solvephysfbik —— 应用full-body反向运动学算法及可选的质心控制
ntransform —— 变换表示normal的vector
fromNDC —— 将位置从NDC空间变换为合适空间的坐标
ow_space —— 将位置从object空间变换到world空间
ow_nspace —— 将normal从object空间变换到world空间
ow_vspace —— 将方向从object空间变换到world空间
tw_space —— 将位置从texture空间变换到world空间
tw_nspace —— 将normal从texture空间变换到world空间
tw_vspace —— 将方向从texture空间变换到world空间
wo_space —— 将位置从world空间变换到object空间
wo_nspace —— 将normal从world空间变换到object空间
wo_vspace —— 将方向从world空间变换到object空间
wt_space —— 将位置从world空间变换到texture空间
wt_nspace —— 将normal从world空间变换到texture空间
wt_vspace —— 将方向从world空间变换到texture空间
dihedral —— 计算旋转矩阵或四元数(将vector a旋转到vector b)
//计算旋转矩阵 matrix3 dihedral(vector a, vector b) //计算四元数 vector4 dihedral(vector a, vector b)
- VOP中对应的节点 Align ;
//提取v1到v2的旋转矩阵,并应用
vector v1 = point(1, 'v1', 0);
vector v2 = point(1, 'v2', 0);
matrix3 m = dihedral(v1, v2);
@P *= m;
maketransform —— 构建3*3或4*4变换矩阵
//物体z轴对应zaxis,up对应yaxis,如为maketransform({0,0,1}, {0,1,0})将为单位矩阵 matrix3 maketransform(vector zaxis, vector yaxis) //与maketransform(int trs, ...)规则一样,但仅用于旋转 matrix3 maketransform(int xyz, vector angles) //yaxis为up,类似lookat;maketransform({0,0,1}, {0,1,0})为单位矩阵; matrix maketransform(vector zaxis, vector yaxis, vector translate)
//按变换顺序构建4*4变换矩阵 matrix maketransform(int trs, int xyz, vector t, vector r) 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)
- 不像大多数VEX函数,旋转单位为角度而不是弧度;
- p中心点偏移,pr坐标系旋转,此两个参数会形成新的坐标系;
- VOP中对应的节点 Make Transform ;
vector4 q = quaternion(set(0,0,1)*ch('z'));
//等价于
matrix m = maketransform(0,set(0,0,1)*degrees(ch('z')));
packedtransform —— 对packed primtive进行变换
void packedtransform(int input, int primnum, matrix transform)
- 将修改P属性和transform内在属性;
- 相当于直接在point层级应用变换;
- 相当于在prim层级,先自旋转(intrinsic:transform),在将本身位置(P)变换;
//等价于,prim层级
// matrix to transform by
matrix transform = ident();
rotate(transform, radians(45), {0,1,0});
translate(transform, {0,1,0});
// get current packed transform
matrix3 primtf = primintrinsic(0, "transform", primnum);
setprimintrinsic(0, "transform", primnum, primtf * (matrix3)transform);
int primpoint = primpoint(0, primnum, 0);
vector pos = point(0, "P", primpoint);
setpointattrib(0, "P", primpoint, pos * transform);
//等价于,point层级直接应用变换
@P *= transform;
getpackedtransform —— 获取packed primitive的变换
matrix getpackedtransform(int input, int primnum)
- 此函数构建一变换,从P属性和transform内在属性,忽略packedfulltransform内的各种细节;
- pivot内在属性;
- 实例instance属性如orient(当pointinstancetransform使用,crowd agent);
- packedlocaltransform内在属性(alembic);
- 此函数不会返回预期的变换在这几种情况;
- setpackedtransform函数也有同样的问题,如有非零的packed pivot或以上情况,packedfulltransform将不会包含所期望的矩阵;
// matrix to transform by
matrix transform = ident();
rotate(transform, radians(45), {0,1,0});
translate(transform, {0,1,0});
matrix tf = getpackedtransform(0, @primnum);
setpackedtransform(0, @primnum, transform * tf);
setpackedtransform —— 设置packed primitive的变换
void setpackedtransform(int input, int primnum, matrix transform)
- 修改P属性和transform内在属性;
- 相当于先把模型归到原点,在应用变换;
// matrix to transform by
matrix tf = ident();
rotate(tf, radians(45), {0,1,0});
translate(tf, {0,1,0});
matrix transform = getpackedtransform(0, @primnum);
setpackedtransform(0, @primnum, transform * tf);
instance —— 创建一个实例变换矩阵
matrix instance(vector P, vector N) matrix instance(vector P, vector N, vector scale) matrix instance(vector P, vector N, vector scale, vector pivot) matrix instance(vector P, vector N, vector scale, vector4 rotate, vector up) matrix instance(vector P, vector N, vector scale, vector4 rotate, vector up, vector pivot) matrix instance(vector P, vector N, vector scale, vector4 rotate, vector4 orient) matrix instance(vector P, vector N, vector scale, vector4 rotate, vector4 orient, vector pivot)
- 类似Copy节点,变换其实例;
- pivot会影响位置,是因为影响坐标系;
- 先计算orient,在计算rotate;
- 支持两种方法设置旋转
- 方法一,要求显式的矢量up(应是N的切线方向),与N一起确定方向;
- 方法二,使用显式的orient(相对的XYZ轴);
- VOP中对应的节点 Make Instance Transform ;
//类似copy应用
vector P = point(1, 'P', chi('num'));
vector N = point(1, 'N', chi('num'));
@P *= instance(P, N);
lookat —— 创建旋转矩阵或角度去定向-Z轴
matrix3 lookat(vector from, vector to) matrix3 lookat(vector from, vector to, float roll) matrix3 lookat(vector from, vector to, vector up) vector lookat(vector from, vector to, float roll, int xyz) vector lookat(vector from, vector to, vector up, int xyz)
- -Z轴匹配指定矢量(方向=to减from),即摄像机是朝向-Z轴的,可理解为摄像机方向;
- roll 单位为degree;
- VOP中对应的节点 Look At ;
vector v = point(0, 'v1', 0);
@P *= lookat(chv('from'), chv('to'), ch('roll'));
pretranslate —— 对矩阵应用预位移
void pretranslate(matrix &m, vector amount)
prerotate —— 对矩阵应用预旋转
void prerotate(matrix3 &m, float amount, vector axis) void prerotate(matrix &m, float amount, vector axis)
void prerotate(matrix3 &m, vector angles, int xyz) void prerotate(matrix &m, vector angles, int xyz)
//XAXIS=1、YAXIS=2、ZAXIS=4 void prerotate(matrix3 &m, float angle, int axis) void prerotate(matrix &m, float angle, int axis)
- 单位需为弧度,轴应标准化;
prescale —— 对矩阵应用预缩放
void prescale(matrix &m, vector scale_vector) void prescale(matrix3 &m, vector scale_vector)
translate —— 对矩阵应用位移
void translate(matrix &m, vector amount) void translate(matrix &m, vector4 amount)
rotate —— 对矩阵应用旋转
void rotate(matrix2 &m, float amount) void rotate(matrix3 &m, float amount, vector axis) void rotate(matrix &m, float amount, vector axis)
void rotate(matrix3 &m, vector angles, int xyz) void rotate(matrix &m, vector angles, int xyz)
//XAXIS=1、YAXIS=2、ZAXIS=4 void rotate(matrix3 &m, float angle, int axis) void rotate(matrix &m, float angle, int axis)
- 单位需为弧度,轴应为标准化;
rotate_x_to —— 将x方向旋转指定方向
vector2 rotate_x_to(vector2 direction, vector2 v) vector rotate_x_to(vector direction, vector v) vector4 rotate_x_to(vector4 direction, vector4 v)
- 可被函数sample_direction_cone和sample_sphere_cone使用;
vector2 u = set(rand(@ptnum+0.1),rand(@ptnum-0.1));
@N = sample_direction_cone({1,0,0},0.2,u);
@N = rotate_x_to({0,1,0},@N);
scale —— 对矩阵应用缩放
void scale(matrix2 &m, vector2 scale_vector) void scale(matrix &m, vector scale_vector) void scale(matrix3 &m, vector scale_vector)
//模型中心点在原点
matrix m = ident();
float fade = relbbox(0, @P).y;
float scale = max(sin(fit01(fade,0,$PI)),0.01); //不要为0,会影响xform还原
rotate(m, ch('ang_twist')*$PI*fade+@Time*4, {0,1,0});
scale(m, set(scale,1,scale));
translate(m, chv('rad_bend'));
rotate(m, ch('ang_bend')*$PI*fade-@Time, {0,0,1});
@P *= m;
4@xform = invert(m);
smoothrotation —— 返回欧拉旋转
vector smoothrotation(int order, vector r, vector r_reference)
solveconstraint —— 返回本地骨旋转的矩阵
vector[] solveconstraint(float lengths[], vector targetpos, float tolerance, matrix relmat, vector constraints[])
solvecurve —— 返回本地骨旋转的vector/matrix3矩阵
vector [] solvecurve(float lengths[], int closed, int orienttonormal, vector tangent, vector points[], vector normals[]) matrix3 [] solvecurve(float lengths[], int closed, int orienttonormal, vector tangent, vector points[], vector normals[]) vector [] solvecurve(float &outlength, vector &outpos, float lengths[], int closed, int orienttonormal, int normalmode, vector tangent, vector points[], vector normals[]) matrix3 [] solvecurve(float &outlength, vector &outpos, float lengths[], int closed, int orienttonormal, int normalmode, vector tangent, vector points[], vector normals[]) vector [] solvecurve(float &outlength, vector &outpos, float lengths[], int closed, int orienttonormal, int normalmode, vector tangent, vector points[], vector normals[], float twists[], float initialtwists[], int fmt, int order, float lod) matrix3 [] solvecurve(float &outlength, vector &outpos, float lengths[], int closed, int orienttonormal, int normalmode, vector tangent, vector points[], vector normals[], float twists[], float initialtwists[], int fmt, int order, float lod) vector [] solvecurve(string op, float lengths[], int closed, int orienttonormal, vector tangent, int normalcalcmethod, matrix relmat) matrix3 [] solvecurve(string op, float lengths[], int closed, int orienttonormal, vector tangent, int normalcalcmethod, matrix relmat) vector [] solvecurve(string op, float lengths[], int closed, int orienttonormal, vector tangent, int normalcalcmethod, matrix relmat, int primnum, float lod) matrix3 [] solvecurve(string op, float lengths[], int closed, int orienttonormal, vector tangent, int normalcalcmethod, matrix relmat, int primnum, float lod)
solveik —— 应用反向运动学算法
vector [] solveik(float lengths[], vector targetpos, vector twistpos, float twist, int twistflag, float dampen, int resiststraight, float trackingthres, matrix relmat, vector constraints[]) matrix3 [] solveik(float lengths[], vector targetpos, vector twistpos, float twist, int twistflag, float dampen, int resiststraight, float trackingthres, matrix relmat, vector constraints[])
solvefbik —— 应用full-body反向运动学算法
matrix [] solvefbik(matrix xforms[], int parents[], dict jointoptions[], matrix targetxforms[], int targets[], dict targetoptions[], int iters, float tolerance, int pinroot) matrix [] solvefbik(matrix xforms[], int parents[], int targets[], matrix targetxforms[], int iters) matrix [] solvefbik(matrix xforms[], int parents[], int targets[], matrix targetxforms[], int iters, float tolerance, int pinroot) matrix [] solvefbik(matrix xforms[], int parents[], int targets[], matrix targetxforms[], int iters, float tolerance, int pinroot, float targetweights[], int targetpriorities[], int targetdepths[]) matrix [] solvefbik(matrix xforms[], int parents[], int targets[], matrix targetxforms[], int iters, float tolerance, int pinroot, float targetweights[], int targetpriorities[], int targetdepths[], int targettypes[], matrix targetoffsets[]) matrix [] solvefbik(matrix xforms[], int parents[], int targets[], matrix targetxforms[], int iters, float tolerance, int pinroot, float targetweights[], int targetpriorities[], int targetdepths[], matrix goalxforms[], vector4 constrainedxforms[], vector jointlimits[]) matrix [] solvefbik(matrix xforms[], int parents[], int targets[], matrix targetxforms[], int iters, float tolerance, int pinroot, float targetweights[], int targetpriorities[], int targetdepths[], int targettypes[], matrix targetoffsets[], matrix goalxforms[], vector4 constrainedxforms[], vector jointlimits[])
solvephysfbik —— 应用full-body反向运动学算法及可选的质心控制
matrix [] solvephysfbik(matrix xforms[], int parents[], dict jointoptions[], matrix targetxforms[], int targets[], dict targetoptions[], int iters, float damping, float tolerance)
ptransform —— 从一空间到另一空间变换一矢量
//使用给定矩阵变换矢量 vector ptransform(vector vec, matrix transform) vector4 ptransform(vector4 vec, matrix transform) //从当前空间变换 vector ptransform(string tospace, vector vec) vector4 ptransform(string tospace, vector4 vec) //从一空间到另一空间变换矢量 vector ptransform(string fromspace, string tospace, vector vec) vector4 ptransform(string fromspace, string tospace, vector4 vec)
- ptransform,将vector解释为位置;
- vtransform,将vector解释为方向;
- ntransform,将vector解释为normal;
Pworld = ptransform("space:world", P);
//等价于
Pworld = ptransform("space:current", "space:world", P);
ospace = ptransform("space:object", P)
ospace = ptransform("space:object", "space:current", P)
ntransform —— 变换表示normal的vector
vector ntransform(vector v, matrix transform) vector ntransform(string tospace, vector v) vector ntransform(string fromspace, string tospace, vector v)
vtransform —— 变换表示方向的vector
vector vtransform(vector v, matrix transform) vector vtransform(string tospace, vector v) vector vtransform(string fromspace, string tospace, vector v)
fromNDC —— 将位置从NDC空间变换为合适空间的坐标
- NDC(normal device coordinate)空间仅在以下上下文语境中很好定义,Displacement、Surface、Light;
//将矢量从NDC空间变换为当前空间 vector fromNDC(vector v)
//将矢量从NDC空间变换为指定空间 vector fromNDC(string space, vector
“space:object” | 当前object的物体空间 |
“space:light” | 当前light的物体空间(当计算shadow、light shader时) |
“space:world” | houdini世界空间 |
“space:camera” | mantra相机空间 |
“space:ndc” | NDC空间 |
“space:lightndc” | 当前light的NDC空间(当计算shadow、light shader时) |
“space:current” | 当前所在的空间 |
toNDC —— 将位置变换NDC空间坐标
vector toNDC(vector point) vector toNDC(string camera_name, vector point)
ndcdepth —— 返回相机空间z-depth
float ndcdepth(float z)
vector ndc = ptransform("space:ndc", P);
float pz_camera = ndcspace(ndc.z);
// This value can also be computed using
float pz_camera = -ptransform("space:camera", P).z;
orthographic —— 创建正交投射矩阵
matrix orthographic(float zoom, float orthowidth, float image_aspect, float pixel_aspect, float clip_near, float clip_far) matrix orthographic(float zoom, float orthowidth, float image_aspect, float pixel_aspect, float clip_near, float clip_far, vector4 window)
perspective —— 创建透视投射矩阵
matrix perspective(float zoom, float image_aspect, float pixel_aspect, float clip_near, float clip_far) matrix perspective(float zoom, float image_aspect, float pixel_aspect, float clip_near, float clip_far, vector4 window)
polardecomp —— 对矩阵计算极轴分解
matrix3 polardecomp(matrix3 transform)
void polardecomp(matrix3 transform, matrix3 &rot, matrix3 &stretch, int check_determinant=1)
getspace —— 返回从一空间到另一空间的变换矩阵
matrix getspace(string fromspace, string tospace)
ow_space —— 将位置从object空间变换到world空间
matrix ow_space() vector ow_space(vector v) vector4 ow_space(vector4 v)
ow_nspace —— 将normal从object空间变换到world空间
vector ow_nspace(vector v)
ow_vspace —— 将方向从object空间变换到world空间
vector ow_vspace(vector v)
tw_space —— 将位置从texture空间变换到world空间
matrix tw_space() vector tw_space(vector v) vector4 tw_space(vector4 v)
tw_nspace —— 将normal从texture空间变换到world空间
vector tw_nspace(vector v)
tw_vspace —— 将方向从texture空间变换到world空间
vector tw_vspace(vector v)
wo_space —— 将位置从world空间变换到object空间
matrix wo_space()
vector wo_space(vector pos) vector4 wo_space(vector4 pos)
wo_nspace —— 将normal从world空间变换到object空间
vector wo_nspace(vector v)
wo_vspace —— 将方向从world空间变换到object空间
vector wo_vspace(vector v)
wt_space —— 将位置从world空间变换到texture空间
matrix wt_space() vector wt_space(vector v) vector4 wt_space(vecto
wt_nspace —— 将normal从world空间变换到texture空间
vector wt_nspace(vector v)
wt_vspace —— 将方向从world空间变换到texture空间
vector wt_vspace(vector v)
今天的文章VEX —— Functions|Transforms and Space分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/87483.html