PDA

View Full Version : point position problem


fbitonti
01-23-2008, 04:42 AM
I am writing two scripts and i am have a problem that I think is effecting both scripts.

this first script takes a polygon object and draws a particle at each vertex... like a softbody.

However, when i deform the mesh like i do in the image bellow the particles take on the form of the original primitive.

the other prolem is that no mater where i place the primitve the particle object is created
at the origin 0,0,0

this is the code right now.


string $selection[] = `ls -sl` ;
string $part = $selection[1];
string $square = $selection[0];
//$numberofpart = `getAttr $part.count`;

//print($numberofpart);
print("\n");
//print($selection[1]);

select -r $selection[0];

int $res[] = `polyEvaluate -vertex`;
int $vert = $res[0];

float $p[3];

float $x;
float $y;
float $z;

int $i;

string $cmd = "particle ";

for( $i = 0; $i < $vert; $i++){

print($i);
select -r $selection[0];
$p = `getAttr $square.vrts[$i]`;
print ($p[0] + "," + $p[1] + "," + $p[2] + "\n");

$cmd += "-p " + $p[0] + " " + $p[1] + " " + " " +$p[2] + " ";

}

// select -r pmove.pt[21];

$cmd += ";";
eval ($cmd);

clear ($selection);
// clear ($cmd);

http://www.fadarch.com/guest/screenshot1.jpg


My other script takes the particle object created by the first script and moves the verticies on the associated particle to register defermations. however when I run the
script the sphere disapears I think it is compressing all the vertices onto one point at the center of the object and seems to vanish.

before you run this script select the particles then the poly object.

this is the code.

string $selection[] = `ls -sl` ;
string $part = $selection[0];
string $square = $selection[1];
$numberofpart = `getAttr $part.count`;

print($numberofpart);
print("\n");
print($selection[1]);

select -r $selection[1];

int $res[] = `polyEvaluate -vertex`;
int $vert = $res[0];

int $i;
for ($i = 0; $i < $numberofpart; $i++) {

//get the particle position and store it in a vector and break it up into xyz parts.
float $pos[];
$pos = `getParticleAttr -at worldPosition $part.pt[$i]`;
$x = $pos[0];
$y = $pos[1];
$z = $pos[2];

print("\n");
print($x);
print("\n");
print($y);
print("\n");
print($z);
print("\n");
print("\n");

//set the vertex position
print($i);
move -ws $x $y $z $square.vtx[$i];



}
//clear ($square);
select -cl;

YourDaftPunk
01-23-2008, 06:32 AM
You need to get the vertices in world space. Instead of this:
$p = `getAttr $square.vrts[$i]`;

try this:
$p = `xform -q -ws -t ($square+".pt["+$i+"]")`;

You can also use pointPosition to get world positions for vertices, uvs...

YourDaftPunk
01-23-2008, 06:55 AM
On the second script, the getParticleAttr and move lines needed a little formatting:
string $selection[] = `ls -sl` ;
string $part = $selection[0];
string $square = $selection[1];
$numberofpart = `getAttr $part.count`;

print($numberofpart);
print("\n");
print($selection[1]);

select -r $selection[1];

int $res[] = `polyEvaluate -vertex`;
int $vert = $res[0];

int $i;
for ($i = 0; $i < $numberofpart; $i++) {
//get the particle position and store it in a vector and break it up into xyz parts.
float $pos[];
$pos = `getParticleAttr -at worldPosition ($part+".pt["+$i+"]")`;
$x = $pos[0];
$y = $pos[1];
$z = $pos[2];

print("\n");
print($x);
print("\n");
print($y);
print("\n");
print($z);
print("\n");
print("\n");

//set the vertex position
print($i);
move -ws $x $y $z ($square+".vtx["+$i+"]");
}

//clear ($square);
select -cl;

fbitonti
01-23-2008, 02:37 PM
thanks a bunch that did it.

CGTalk Moderation
01-23-2008, 02:37 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.