PDA

View Full Version : Non-overlapping particles on surface...? arrgh


Trickz
10-08-2007, 11:58 PM
Hmm I've just built a couple of models for a client made up of particles - emitting from the object with 0 speed. Client loves them BUT - can we make it so they don't overlap...

So I need the object to be covered in spheres but they need to line up against each other. Sounds hard.. Any ideas? :shrug: I'm thinking collisions .. but how?

ctp
10-09-2007, 08:12 AM
sounds to me like you might have to look into goaling the particles to the object, and write some emission expression which emits the particles with goalU and goalV with apropriate spacing. Part of the expression would be to check what "apropriate spacing" is as you go through the UV space.

Maybe someone else got some easier approaches...

Trickz
10-09-2007, 08:14 PM
Thanks Christian, I think you're right - I've been playing with goals to attach the particles to the surface, but they only latch to the UV points, so on a sphere they converge to the point. So maybe I do need an expression to space them evenly.. tricky one :(

Aikiman
10-09-2007, 08:22 PM
You could rebuild your surface to control your cv placement or maybe try using a radial field as per vertex to push each particle away from one another as in your surface emission example, not your goal one.

ashishdantu
10-10-2007, 09:10 AM
hi,

before u try the code, emit your required particles and then add goalU , goalV, parentU, parentV, on ur partilceshape and check the need parent UV on the emitter and

in creation exp :


goalU=parentU;
goalV=parentV;


then after you have all the particles you need (i used a max particle number to limit),, run this code in script editor:


// rename ur particle shape to "ps"
// edit the $span to your liking.. its the number of particles per column

float $partcount=`getAttr ps.count`;
float $span=50;
float $goalu=0;
float $goalv=0;
float $offsetu=1/$span;
float $offsetv=1/($partcount/$span);
int $i=0;

for ($i; $i < $partcount ; $i++)
{
if (fmod($i,$span)==0)
{
$goalu=0;
$goalv+=$offsetv;
}
particle -e -or $i -at goalU -fv $goalu ps;
particle -e -or $i -at goalV -fv $goalv ps;
$goalu+=$offsetu;
}
currentTime -e (`currentTime -q`+1);


then select particle and set intial state and then on, ur particle will follow your object, evenly spaced ! :D

pls post if this did help ! :scream:

Trickz
10-11-2007, 08:23 AM
Hey guys and thank you Ash! Partway there, very helpful. It does place the particles evenly across the surface but if you imagine a sphere, they still converge at the apex when i really need them to sit evenly across the surface. I guess really that means using UVs isn't going to work? Harder than it looks!

kbrown
10-11-2007, 09:54 AM
Sounds like you're using the default UV mapping on the sphere (or maybe a NURBS sphere). That would do what you described. Try with a poly sphere with unfolded UVs...

ashishdantu
10-11-2007, 02:35 PM
hi ,

yes the particle emission does depend on the UV....

but the script does attempt to spread out the particles in a way which later makes it look independent of the UV - it does this b'se it explicitly assigns goalU and goalV which are equally spaced..

works for me. i'l try posting a snap tomorrow. I have tried on poly objects. Have tried on a character too !! have you tried adjusting the $span variable ? try with more greater values like 100 or 150.. this should give you a better distribution..

-cheers,

Trickz
10-12-2007, 02:16 AM
Yes the idea is right, but I have a picky client who wants no overlap :( Here's the result so far. Long way off obviously but I know the end result will have intersections. Don't think I can tweak the UVs enough manually for it to be ok. :(

http://dev.blacksheep.net.nz/home/test/hand2.jpg

ikatz
10-12-2007, 06:02 AM
another idea from what you said regarding collisions, maybe you can instance the spheres to the particles and then make them rigid objects so they dont overlap.. possibly combine this with the UV spacing method.. hope it helps.

Trickz
10-14-2007, 01:15 AM
Hmm thanks I'll try it. Panic time, due tomorrow. You'd think covering a surface in a layer of spheres would be easy ;) well, easy-ish... arrgh

Trickz
10-14-2007, 02:24 AM
Actually one thing I see is Hair paints a pretty good grid across the surface. Is there a way of converting or attaching spheres/particles to follicles?

ikatz
10-14-2007, 09:42 AM
that gives me an idea.. Maybe you can paint on surfaces and have that drive the spread of the spheres so with a simple script you cab say where a sphere should go by the value of the color you painted

ashishdantu
10-14-2007, 03:08 PM
hi trickz,

but u can try this.. will tell my concept and you may try like so:

thinking about the hair system.. select your object and hit automatic mapping and while adding hair (create hair options) there tweak the U and V values to ur required number... and create hair and then delete all the hair system and the hair curves keeping just the follicles ..

to replicate spheres can use this code to have the sphere replicated at each of the follicle.. with this, you can tweak any specific follicle's position on the geometry, by editing its U and V paramaters...

then u select the 'sphere' you want to replicate and run :

string $sphr[]=`ls -sl`; // store the selected sphere
string $follicles[]=`ls -type follicle`;
for ($e in $follicles)
{
string $new[]=`instance -st $sphr[0]`;
string $folshape[]=`listRelatives -p $e`;
delete `parentConstraint $folshape[0] $new[0]`;
parent $new[0] $folshape[0];
}


this should replicate an instance of the sphere at every follicle and also also point and orient the sphere to each follicle. each sphere is parented to the follicle so they follow along..

so effectively you should have spheres spread as per your follicles.. hope this helps ??

Trickz
10-14-2007, 10:04 PM
You are amazing Ash! You've convinced me I need to learn MEL :) It works. It's a huge computation to get enough follicles but your script is perfect. Thanks very much for your help. If the PC holds up I'll post a render. Particles was probably a better way but hey ;)

darktding
10-14-2007, 11:39 PM
you CAN use particles,
Instead of instancing, you use the emit mel command and use parameterU and parameterV off the follicle (read the node help page on follicle) as the goalU and goalV of the particle, also now that you goaled the particles you can even delete the follicles...

Trickz
10-15-2007, 12:19 AM
woah.. haha thanks Dark. Wow that sounds like a nice improvement - this is working but the instancing is totally killing my PC :) Hmm my MEL knowledge is zero though :( I'll see how far I get

ashishdantu
10-15-2007, 03:05 AM
hi,

selecting your base geometry...n run below code.. it will create a particle node.. with each particle in the place of a follicle and the particles stick to the geometry.. (they are goaled to the geometry and follicles are cleaned)

basically doing what darktding said.... and then instance your spheres to this particlenode. But let us know if this is faster than the instance method... ?


// select the base geometry and run this code.
string $baseGeo[]=`ls -sl`;
string $baseGeoShape[]=`listRelatives -s $baseGeo[0]`;
string $follicles[]=`listConnections -type follicle $baseGeoShape[0]`;
string $parts="particle ";
for ($e in $follicles)
{
float $folPos[]=`xform -q -ws -t $e`;
$parts+=("-p "+$folPos[0]+" "+$folPos[1]+" "+$folPos[2]+" ");
}
$parts+="-ch 1";
string $newPart[]=`eval ($parts)`;
addAttr -ln goalU -dt doubleArray $newPart[1];
addAttr -ln goalU0 -dt doubleArray $newPart[1];
addAttr -ln goalV -dt doubleArray $newPart[1];
addAttr -ln goalV0 -dt doubleArray $newPart[1];
goal -w 1 -utr 0 -g $baseGeo[0] $newPart[0];
setAttr ($newPart[1]+".goalSmoothness") 0;

int $p=0;
for ($e in $follicles)
{
float $folU=`getAttr ($e+".parameterU")`;
float $folV=`getAttr ($e+".parameterV")`;
particle -e -or $p -at goalU -fv $folU $newPart[1];
particle -e -or $p -at goalV -fv $folV $newPart[1];
$p++;
}
delete $follicles;



lemme know if this is better for you ?

Trickz
10-15-2007, 08:11 AM
Did you type that off the top of your head?? That's brilliant haha, wow. Yes a hundred times faster than instancing. What a tool, you should submit that to HighEnd. I'll put up a render tomorrow, that's going to come in handy a LOT. Many thanks Ash, amazed you took the time. Wish I could return the favour. Yes, I'm stoked ;) Gotta learn MEL now...

ashishdantu
10-15-2007, 08:50 AM
hey trickz,

hope this code came in before u ran out of time ?? yes,i'll wait for ur render..

it was also darktding who quoted the idea.. :)

and S, you SHUD learn MEL !! i cant stress enough on that !! especialy if u r into rigging and VFX...

what i've written is peanuts before the other masters around ! but it worked for you , i'm happy :)

-cheers,

Trickz
10-16-2007, 06:48 AM
Well here's the final result using particles parented to follicles. Great result I think 0 and these models don't have the best UV layouts but hair does a nice job of mapping. Thanks guys for your suggestions and Ash for your code, the client was very happy. Sure this will come in handy to others.

http://www.rickdavidson.com/files/Gun_mini.jpghttp://www.rickdavidson.com/files/Rockets_mini.jpg

ashishdantu
10-16-2007, 07:55 AM
hey Trickz,

WOW , nice things u made out of these :scream: n glad ur client liked it ! :thumbsup: do u have a anim clip of these ?

ya using hair to grid out follicles kinda makes it independent of the UV on the model. nice trick :twisted:

-cheers !

thomwickes
10-16-2007, 10:34 AM
wow... you actually did it - and it looks great.

I was racking my brain over this initially, but hair follicles is definitely a great solution.

nice work

Trickz
10-16-2007, 12:26 PM
Yeah I didnt think it would be THAT hard, but it came up great with your guys help. Now I'm thinking WOW what if you put dynamics on that. I just want to blow it to bits - when I get time ;) No animation yet Ash, was a print job. But I'll come back to that haha. Ah these forums are great

Duncan
10-16-2007, 05:15 PM
You used the follicles because they have code to layout based on uvs while compensating for worldspace separation. This is actually all done in a mel script:
createHair.mel (in your maya scripts location)

I suppose it might be a bit intimidating( it is a pretty long script ), but the relevant portion is in the block "if($hairCreateType == 1){}". The variable "doEqualize" indicates the wordspace positioning. It positions a follicle then does getAttr on the follicle outTranslate to find the worldspace position at the point on surface. Basically the code looks at the length of the grid lines in u and v and then adjust the number of follicles to create based on this. At any rate one could write a similar mel script to do the positioning directly, without creating the hair system.

Duncan

darktding
10-16-2007, 07:38 PM
also since u have the uv of a follicle, you can add more by simply looping and emitting new points with the following:
(u+dU), (v+dV)
(u+dU), (v-dV)
(u-dU), (v+dV)
(u-dU), (v-dV)

where dU and dV are small increments. That way you keep a min amount of follicles yet have the extra control of adding a lot more points...

And Duncan is right, simply working on paper, you can actually do this without using the follicles stuff...

Trickz
10-16-2007, 10:15 PM
Wow you guys are great. Good suggestions - yes the system was struggling with the number of follicles created - because obviously it created the hair as well, so there would be a limit to how far you pushed it. If you bypassed the hair creation AND added more points you could build pretty complex shapes using particles. I was reading up on coloring the particle based on the surface color. Now THAT would give you some power to create some pretty amazing effects.

Trickz
10-16-2007, 10:19 PM
Haha now I just want to learn MEL so I can select a model, hit a button and have a full particle mesh with colour. Wow :bounce:

CGTalk Moderation
10-16-2007, 10:19 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.