PDA

View Full Version : Create 1 particle Sprite at Center Pivot of an object !!!


smoluck
12-21-2004, 02:05 PM
How can i create one particle sprite to each center (pivot) of an object ? I would like to create several particle sprite to every center of pivot of several Poly object...

And for more complexity I would like to put on every particle the color of material that the object as. :)

If know how to do that send me an exemple of mel script....

I have to use particle to animate Cube that that I have created ( 600 simple cube in my scene ), and apply field of gravity to those particle sprite and made collision with the ground.

--------------------------------------------------

Simply imagine that you have 3 box located at different positions and with different material.

Material who just have an information of color in Color and Ambiant.

I would like to create a script who can help me to create 1 particle Sprite at each center of the 3 different boxe, and that they can take the color of the different box where they are created.

nobody can help me on that question ???? :shrug:

I know that I can return the center pivot of one object by this command:

getAttr pCube1.scalePivot;
// Result: 0.5 0.5 0.5 //

But I would like to first make a melscript to return the position of the different object that I selected in the world.

smoluck
12-21-2004, 03:41 PM
Ok I found yet the command for the creation of particle, was :

particle -p X Y Z

so I have to found the system to connect the different pCube.scalePivot (X Y Z) to particle -p X Y Z.... thats for the more difficult....:scream:

smoluck
12-21-2004, 04:27 PM
:thumbsup: S. J. Tubbrit:thumbsup: have already done a script that help you to create a locator at the center of an object, so i modified it to create a particle to the center of that object. But now the problem is that it can't create one particle at each center of multiple selection object. so how I can correct that ?


WOUPS that's strarup (http://www.cgtalk.com/member.php?u=26546) that help S J Tubbrit to create that mel script :applause:.

Do I have to use SelectionList to do that...?



proc moveAndParentDaTubbritLoc()

{

string $daObj[]= `ls -sl -l`;

if(size($daObj)!=0)

{

string $daLocName = $daObj[0]+"_TubbritLoc";

float $pos[3] = `xform -q -ws -rp $daObj[0]`;

particle -p 0 0 0 -n $daLocName;

move -ws $pos[0] $pos[1] $pos[2] $daLocName;

parent $daLocName $daObj[0];

}

else

{

print("Nothing selected...\n");

}

}

moveAndParentDaTubbritLoc;

thematt
12-21-2004, 05:43 PM
allez je te le donne..:)

You just had to had a loop and it works..I cleaned up the code a bit so you don't need to make a locator first..

here it goes.

hope that helps

cheers

proc moveAndParentParticles()

{

string $daObj[]= `ls -sl `;

if(size($daObj)!=0)

{

for ($i in $daObj)

{

string $daLocName = "particle_"+ $i;

float $pos[3] = `xform -q -ws -rp $i`;

particle -p $pos[0] $pos[1] $pos[2] -n $daLocName;
parent $daLocName $i;
}
}
else { print("Nothing selected...\n");
}
}
moveAndParentParticles;

smoluck
12-22-2004, 08:20 AM
Ok that's works thematt :bounce: !


But my objective is to learn how to create my melScript, so do you know what book was good for me to learn the basics....?
I can't select by Material a multiselection and apply the script...what's the problem ?
My work consist to select by material , apply the script, and finally apply that material to Sprite particle. So How can I take simple RGB color info of my lambert and send it to particle sprite ?
I already have done a script to get in TXT file, the position in the world of my created particle to export in third party app :) .
Cheers

Marcel
12-22-2004, 08:47 AM
- I can't select by Material a multiselection and apply the script...what's the problem

Does the 'select by material' return face-components? If you have faces selected I can imagine it doesn't work, because faces have no pivot to query. You would have to convert from the face selection to object selection first.

If you want to get the RGB value of the lambert you have to do a couple of things:
(-go from face selection to object selection)
- go from the object to it's Shape
( http://www.ewertb.com/maya/mel/mel.php?howto=08 )
- get the 'Shading Group' from Shape
(http://www.ewertb.com/maya/mel/mel.php?howto=43)
- get the 'Material' from the Shading Group
(http://www.ewertb.com/maya/mel/mel.php?howto=92)
- get the color out of the Materials 'Color'

As you can see it's quite a lot of work, but with the examples on Brian Ewerts site I'm sure
you can make it work.

Here is another example on how to find the material on an object:
http://www.cgtalk.com/showthread.php?t=186641

thematt
12-22-2004, 11:07 AM
Marcel is right, go throught bryan site and you'll find some really usefull piece of information.
You also can buy mel for animator, Istarted with it, it's very informative.

But to get the shader related to an object i usually do it with listHistory, as in the exemple under that.

Then is just a matter of adding your particles to your object like above and assigning the correcponding shader to that particles..am I right? is it what you intend to do.

here the exemple to get the shader from the object..quick and durty..

cheers

string $sel[] = `ls -l -sl -tr`;

int $size =`size $sel`;

int $inc;

for ($inc=0;$inc<$size;$inc++)

{

// fist search shader realted to the object

string $shader[] = `listHistory -f 1 $sel[$inc]`;

string $history[] = `listHistory $shader`;

string $files[] = `ls -type "lambert" $history`;

print $files ;

}

smoluck
12-22-2004, 11:16 AM
Thanks Marcel I understand what you explain to me , but its more difficult for me. realize that melscript make me crazy..... :scream: First off all I've tried to regroup and organize my mel script in my brain and test that, that doesn't work.

I notice that I just work with pCube object, so I already done some copy of cubeShape to create an environement. All of these Cube as different types of lambert with different colors.
I would Like to create 1 Particle Shape ( with n Sprite ) at every position of my n Cube and take our material to patticle that are placed at that position.



// ********* Smoluck Pixel 3D MEL Script *********

// [FR] Retourner la liste des objets (shape)
// [FR] d'une sélection d'objets par Point & Clic ou par materiaux
// [EN] Return the object list of one selection by manual method, or selected by material

string $selectedCube[] = `ls -selection -dag -leaf`;
// [FR] Creation des particules au centre des objets
// [EN] Creation of particle at center pivot of object

proc moveAndParentParticles()
{
string $Pixel3D[]= `ls -sl `;
if(size($Pixel3D)!=0)
{
for ($i in $Pixel3D)
{
string $ParticleName = "particle_"+ $i;
float $pos[3] = `xform -q -ws -rp $i`;
particle -p $pos[0] $pos[1] $pos[2] -n $ParticleName;
parent $ParticleName $i;
}
}
else { print("Nothing selected...\n");
}
}
moveAndParentParticles;

thematt
12-22-2004, 02:54 PM
Ok well, it's only now a matter of compiling the two piece of mel together.

Just make only one loop and do everything in that loop.
Then use the "setAttr" command to transform your particles to sprite.

something like "setAttr myparticle.particleRenderType 5" and the "sets" command to assign a shader to you particle.

The best is always to look in the doc to understand how it works.

To assign a shader you need to assign the shadingEngine in fact so just check for the shading engine instead of the lambert like I made in my exemple.

it should not be more complicated than that.

Unfortunatly you can't have one particleShape with as many particle as object if you want to parent your particle to your object.You really have to have one particle for one object.


cheers

good luck with your mel writing, it take times but it's worth it.

smoluck
12-24-2004, 08:35 AM
Just a clue to inform you , why i would like so much do that mel script !!!

-----------------------early post at Alias Maya section-----------------------

delete internal face of an object ??? (http://www.cgtalk.com/showthread.php?t=196757)

-----------------------------------------------------------------------------

I 'm under beta test with this type of workflow. It's just a test for a special project :thumbsup: . I't could be not more easy to create the low poly object with 90 ° face modeling, and recreate that highpoly with new pCube. I've prepared a mel script to create a particle sprite at each center pivot of that high poly object for third party export XYZ coord information. So I have to do a High poly ( many cube ) for particle export and a low poly object with internal face deleted to reduce polycount.

How can i analyse the highpoly object :
:lightbulb Remove Face who are superposed to another face.
:lightbulb Merge all the vertex who are at the same position.

:wip: Can I do a melScript to do that ? If Yes, How ? Or do I can select just the faces that are at the outside of the object shape by backface culling selection ?

CGTalk Moderation
01-20-2006, 06:00 AM
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.