maya动力学有以下几套系统:
1.刚体、柔体系统
刚体系统的典型节点连接方法如下:
物体的变换节点、形状节点连接rigidBody节点,刚体节点输出力到解算器节点,解算器输出新的变换到变换节点值得注意的是柔体系统实际上是用粒子实现的,通过给每个网格顶点赋予一个粒子,再让粒子反过来操纵网格,实现网格的变形。通过在粒子之间创建大量弹簧,实现粒子之间的相互影响,于是物体看上去就像发生了弹性变形一样。弹簧的节点连接方法如下:
2.普通粒子系统
普通粒子系统可以同网格物体发生碰撞。典型节点连接方法:
网格的形状节点输出到geoConnector节点,这个节点输出一个sweptGeometry,粒子根据sweptGeometry数据计算自身是否应该反弹。sweptGeometry表示一个几何体一帧之内每个三角形扫过的区域。其存放几何体每个三角形在此帧前后的位置。可以发现此种连接方式没有影响形状节点的输入,也就是影响是
单向的,物体影响粒子系统,但是粒子系统不影响物体。
3.n粒子系统、n布料系统
默认情况下,n粒子系统可以同n布料系统发生碰撞。n布料系统通过调整物体的刚性参数,可以模拟布料,也可以模拟柔体、刚体,是一个多功能的系统。n粒子系统的节点连接方式是:
n粒子的形状节点的current state、start state输出分别连到nucleus解算器节点的inputActive、inputActiveStart输入中,解算器节点的outputObjects属性连到形状节点的nextState属性中。这几个属性都是Nobject类型。n布料的连接方式与此相同。
还有一种称为Passive Object,也就是会影响n粒子、n布料,但是自身我行我素不受影响的物体。这种物体的连接方式如下:
nRigid物体的输出连入nucleus解算器,但解算器无输出连到物体本身。值得注意的是nRigid物体在模拟过程中是允许变形的,但是网格拓扑不能变。可见n系统工作方式是:
把所有n物体都输入nucleus节点,再把节点的解算结果传回给对应的n物体。n粒子可以实现粒子之间的堆叠(因为粒子之间可以存在作用力)几个与粒子有关的mel命令:
命令 | 功能 | 典型用法 |
event | 插入一个碰撞事件,可以是粒子分裂、粒子出生,或者调用外部函数 | event -proc myProc myCloud;
// Call the MEL proc // "myProc(name, id, name) each time a particle // of myCloud collides with anything. |
getParticleAttr | 获得粒子系统的属性,返回平均值,或者是数组 | getParticleAttr -at velocityparticle1;
// This will return the average velocity for the entire particle
// object as well as the maximum offset from the average. getParticleAttr -at velocity particleShape1.pt[0:7] particleShape1.pt[11];// This will return the average velocity for particles 0-7 and 11// as well as the maximum offset from the average. |
particle | 创建粒子、编辑、修改粒子属性 | particle -attribute velocity -order 7 -q; // Returns the velocity of the 7th particle in the currently selected// particle object particle -e -attribute velocity -order 7 -vectorValue 0.0 1.0 0.0; // Edits the velocity of the 7th particle in the currently selected // particle object to be 0.0, 1.0, 0.0 |
nParticle | 与particle命令类似 | nParticle -attribute velocity -order 7 -q; // Returns the velocity of the 7th particle in the currently selected// particle object nParticle -e -attribute velocity -order 7 -vectorValue 0.0 1.0 0.0; // Edits the velocity of the 7th particle in the currently selected// particle object to be 0.0, 1.0, 0.0 |
发现n粒子可以用以下方法查询碰撞的力:1.首先在粒子形状节点添加以下属性:
2. 然后用以下命令nParticle -attribute collisionForce -id 1 -q nParticle1;可以返回特定粒子的属性若用getAttr nParticleShape1.collisionForce,则可以返回所有粒子的属性也就是说,粒子自定义属性是一些由用户添加上去的属性,用户添加了之后,
粒子系统每一帧会根据自身情况,设置这些属性的值。下面是碰撞相关属性的含义。其中World表示世界空间(但似乎仍然是局部空间……)
名称 | 大小 | 含义 |
collision(World)Force | 粒子数*3 | 碰撞过程中粒子所受的力 |
collision(World)Position | 粒子数*3 | 碰撞位置 |
collision(World)IncomingVelocity | 粒子数*3 | 碰撞前速度 |
collision(World)OutgoingVelocity | 粒子数*3 | 碰撞后速度 |
collision(World)Normal | 粒子数*3 | 碰撞地点法线 |
collisionTime | 粒子数 | 碰撞发生时间 |
collisionGeometryIndex | 粒子数 | 一个位图,每一元素表示一个粒子,若该粒子发生碰撞,对应元素为0,否则为碰撞的几何体序号,可以通过以下方法获得几何体int $idx = particleShape1.collisionGeometryIndex;if( $idx != -1 ){ string $geoC[] = `listConnections particleShape1.collisionGeometry[$idx]`...} |
collisionComponentId | 粒子数 | 一个位图,每一元素表示与粒子发生碰撞的多边形面(face)序号,注意这些序号可能来自不同物体。此时可以通过为碰撞事件绑定一个回调函数(见前述event命令),通过回调函数的参数获得碰撞物体名称 |
值得注意的是前面几个关于碰撞点数据的属性,只有在碰撞发生的粒子对应的数组位置才会被设置,其余位置为未知值,一般为-999.99之类。使用时应该先查询collisionGeometryIndex,再对确实发生碰撞的粒子处理。
来自为知笔记(Wiz)