lab00
12-12-2007, 02:46 PM
Hi,
I've some particles arranged in a random way on a poly surface UV space (position of
particles is given by goalU & V = rand(0,1) and the poly surface is the goal object for
particles).
Because i've instanced an object to the particles and i wanted to orient these depending
on
the normal of the face which the particles is on, i used ClosestPointOnMesh node.
(I wished to use CPOM command but i'm using Maya 2008 and by what i knew there isn't
anymore CPOM command, but only the node, isn't it?)
So i attached the polySurface.worldMesh[0] to CPOM1.inMesh and i added this to the
particles runtime expression:
float $Nx, $Ny, $Nz;
vector $norm;
vector $pos = particleShape1.position;
setAttr closestPointOnMesh1.inPositionX ($pos.x);
setAttr closestPointOnMesh1.inPositionY ($pos.y);
setAttr closestPointOnMesh1.inPositionZ ($pos.z);
$Nx =`getAttr closestPointOnMesh1.normalX`;
$Ny =`getAttr closestPointOnMesh1.normalY`;
$Nz =`getAttr closestPointOnMesh1.normalZ`;
$norm = <<$Nx, $Ny, $Nz>>;
This works, and in $norm there is the normal vector of the face which the particle is on.
Despite i've always known that one shouldn't Never use setAttr and getAttr in a runtime
expression because of the resulting slowdown, i've used these here, because i didn't find
another way.
Infact if i used this instead:
float $Nx, $Ny, $Nz;
vector $norm;
vector $pos = particleShape1.position;
closestPointOnMesh1.inPositionX = $pos.x;
closestPointOnMesh1.inPositionY = $pos.y;
closestPointOnMesh1.inPositionZ = $pos.z;
$Nx = closestPointOnMesh1.normalX;
$Ny = closestPointOnMesh1.normalY;
$Nz = closestPointOnMesh1.normalZ;
$norm = <<$Nx, $Ny, $Nz>>;
it wouldn't work, because the $norm vector is filled with the same value for all the
particles, and i think this is because using `=` instead of setAttr and getAttr doesn't
make the DG refresh every particle cycle, instead it refresh only at the start of every
frame calculating the normal once in a frame and not once per particle.
Correct me if i'm wrong, please.
I would know if is it right to use setAttr and getAttr in this case(despite is very sloooww...) or if there is a better way to do this.
Thank you very much for the help.
I've some particles arranged in a random way on a poly surface UV space (position of
particles is given by goalU & V = rand(0,1) and the poly surface is the goal object for
particles).
Because i've instanced an object to the particles and i wanted to orient these depending
on
the normal of the face which the particles is on, i used ClosestPointOnMesh node.
(I wished to use CPOM command but i'm using Maya 2008 and by what i knew there isn't
anymore CPOM command, but only the node, isn't it?)
So i attached the polySurface.worldMesh[0] to CPOM1.inMesh and i added this to the
particles runtime expression:
float $Nx, $Ny, $Nz;
vector $norm;
vector $pos = particleShape1.position;
setAttr closestPointOnMesh1.inPositionX ($pos.x);
setAttr closestPointOnMesh1.inPositionY ($pos.y);
setAttr closestPointOnMesh1.inPositionZ ($pos.z);
$Nx =`getAttr closestPointOnMesh1.normalX`;
$Ny =`getAttr closestPointOnMesh1.normalY`;
$Nz =`getAttr closestPointOnMesh1.normalZ`;
$norm = <<$Nx, $Ny, $Nz>>;
This works, and in $norm there is the normal vector of the face which the particle is on.
Despite i've always known that one shouldn't Never use setAttr and getAttr in a runtime
expression because of the resulting slowdown, i've used these here, because i didn't find
another way.
Infact if i used this instead:
float $Nx, $Ny, $Nz;
vector $norm;
vector $pos = particleShape1.position;
closestPointOnMesh1.inPositionX = $pos.x;
closestPointOnMesh1.inPositionY = $pos.y;
closestPointOnMesh1.inPositionZ = $pos.z;
$Nx = closestPointOnMesh1.normalX;
$Ny = closestPointOnMesh1.normalY;
$Nz = closestPointOnMesh1.normalZ;
$norm = <<$Nx, $Ny, $Nz>>;
it wouldn't work, because the $norm vector is filled with the same value for all the
particles, and i think this is because using `=` instead of setAttr and getAttr doesn't
make the DG refresh every particle cycle, instead it refresh only at the start of every
frame calculating the normal once in a frame and not once per particle.
Correct me if i'm wrong, please.
I would know if is it right to use setAttr and getAttr in this case(despite is very sloooww...) or if there is a better way to do this.
Thank you very much for the help.
