Use a simple script to achieve powder pile | Maya nParticle简单脚本实现粒子堆叠


Youtube

Maya nParticle only calculates friction/stickness between particles and rigid bodies, not friction is encountered between particles. My guess is the algorithm complexity is too high. Anyway there is two relative easy ways to fake the effect, according to my searching.

想要用一个一包糖粒堆在物体(对又是它..)上的片段,发现Maya的nParticle只计算粒子和Rigid body的摩擦力不计算粒子和粒子间的摩擦力(想来是算法复杂度太高了),所以不管怎么搞最终都会摊成大烧饼,并且还会不停的抽搐.. 查了下大概有两个相对简单的方法

1. hold particles with a invisible rigid body. 2. Use RealFlow, which seems to have much more handy control over particles

I’m not happy with either. 1 is lame. 2 too much trouble, have to get hang of another environment. If I must do scripting, I choose to learn mel.

So the algorithm is:

It’s unlikely to mess with friction as I guessed above. I tried to modify per particle mass to let them stuck in the space. Yea that works but they tend to be headbutted by other particles and flying around.. for science. Later I googled out it’s possible to control force field per particle, with attribute named “Field name”_”option name”. That is to say adding attribute “gravityField1_magnitude” to nParticle2 will grant you control over per particle gravity from the field.

On creation:

[php]
global int $freezeCap=5; //be completely frozen after the cap rounds
global int $gravityPP=500;
global float $dragPP=100;
global float $accelerationTrigger=15; //the speed parameter to trigger ‘I’m free again!", which leads to free droping.
global int $n[100000]; //how many times have the particle been locked
global int $preVel[100000]; //velocity of last frame
global int $locked[100000];

nParticleShape4.dragField1_magnitude=0;
nParticleShape4.gravityField1_magnitude=$gravityPP;

global int $init=1;
if($init==1) {
int $i;
for($i=0;$i<100000;$i++) {
$n[$i]=0;
$locked[$i]=0;
}
$init=0;
}
[/php]

Before dynamics:
[php]
int $id=nParticleShape4.particleId;
float $vel=abs(nParticleShape4.velocity);

//print("nParticleShape2.velocity "+$nParticleShape2.velocity+"\n");

if($vel>$preVel[$id]+$accelerationTrigger) {
$n[$id]=0;
nParticleShape4.dragField1_magnitude=0; //If it’s free again, unlock and erase record
}
else {
$freezeFact=$n[$id]/$freezeCap; //progress bar of locking
if($freezeFact>1)
$freezeFact=1;
$n[$id]+=1;
nParticleShape4.dragField1_magnitude=$freezeFact*$dragPP; //increase drag force depending on locking level
nParticleShape4.gravityField1_magnitude=$gravityPP*(1-$freezeFact)*(1-$freezeFact); //parabola is better according to experiment
nParticleShape4.velocity=<<0,0,0>>;
}

$preVel[$id]=nParticleShape4.velocity;
[/php]

The script is not bad to me.. adjustable parameters are handy. Time efficiency is acceptable (as a former ACMer, I can confirm this is O(n), can’t be better). 20 million particles * 100 frames cost my i7 half an hour. Not perfect but enough for bragging.
1. 弄个透明的动画的rigid body来把粒子圈起来。 2. 用RealFlow,我只用RealFlow模拟水,但是显然那它对粒子的控制比Maya厉害得多。

两个方法我都不高兴,1太不屌爆,2太麻烦,要做很多熟悉另一个环境的工作,且要写脚本,所以不如来学下mel。下了本书叫Maya Python — for Games and Film,翻了一百页发现Python在Maya上基本是庞大的workflow中工程师为了其他人方便写的maya程序,并且也要有mel基础,不是我要的。

总之,思路是:

想要计算摩擦力显然是不现实的,说过了。我先通过改质量的途径让粒子满足条件时失去质量以停在原地不受重力影响,停是能停住但是会被别的particle撞飞.. 非常科学。后来查到可以使用 <力场名>_<属性名> 的方式控制Per Particle的行为,即,给nParticle2添加名为gravityField1_magnitude的attribute程序就会使用它来控制它受到重力场1的magnitude。然后通过DragField让particle稳定。我在注释里详细说。

粒子生成时脚本:

[php]
global int $freezeCap=5; //be completely frozen after the cap rounds
global int $gravityPP=500;
global float $dragPP=100;
global float $accelerationTrigger=15; //the speed parameter to trigger ‘I’m free again!", which leads to free droping.
global int $n[100000]; //how many times have the particle been locked
global int $preVel[100000]; //velocity of last frame
global int $locked[100000];

nParticleShape4.dragField1_magnitude=0;
nParticleShape4.gravityField1_magnitude=$gravityPP;

global int $init=1;
if($init==1) {
int $i;
for($i=0;$i<100000;$i++) {
$n[$i]=0;
$locked[$i]=0;
}
$init=0;
}
[/php]

动态前的脚本:

[php]
int $id=nParticleShape4.particleId;
float $vel=abs(nParticleShape4.velocity);

//print("nParticleShape2.velocity "+$nParticleShape2.velocity+"\n");

if($vel>$preVel[$id]+$accelerationTrigger) {
$n[$id]=0;
nParticleShape4.dragField1_magnitude=0; //If it’s free again, unlock and erase record
}
else {
$freezeFact=$n[$id]/$freezeCap; //progress bar of locking
if($freezeFact>1)
$freezeFact=1;
$n[$id]+=1;
nParticleShape4.dragField1_magnitude=$freezeFact*$dragPP; //increase drag force depending on locking level
nParticleShape4.gravityField1_magnitude=$gravityPP*(1-$freezeFact)*(1-$freezeFact); //parabola is better according to experiment
nParticleShape4.velocity=<<0,0,0>>;
}

$preVel[$id]=nParticleShape4.velocity;
[/php]

个人感觉这个还不错,有很多参数可以控制,效率也还行(前ACMer表示这个就是O(n)..不能再低了),200万粒子100帧i7跑半个小时。显然不完美,蒙人没问题。

1,386 thoughts on “Use a simple script to achieve powder pile | Maya nParticle简单脚本实现粒子堆叠

  1. Best Neosurf Casinos

    Today, I went to the beach with my children. I found a sea shell and gave
    it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the
    shell to her ear and screamed. There was a hermit crab inside and it pinched her ear.
    She never wants to go back! LoL I know this is totally off topic but I had
    to tell someone!

    Reply
  2. kapsul viagra murah

    you’re truly a excellent webmaster. The site
    loading pace is incredible. It seems that you’re doing any distinctive trick.
    In addition, The contents are masterpiece. you’ve done a fantastic
    activity in this matter!

    Reply
  3. worldcup

    A fascinating discussion is worth comment. I do think that you should write more on this topic, it might not
    be a taboo matter but usually folks don’t talk about these topics.
    To the next! Many thanks!!

    Reply
  4. delicuan situs bodong

    Great blog here! Also your site loads up fast!
    What web host are you using? Can I get your affiliate link to your host?
    I wish my website loaded up as quickly as yours
    lol

    Reply
  5. https://alertplumber.com/

    Have you ever considered writing an e-book or guest authoring on other blogs?
    I have a blog centered on the same topics you discuss and
    would love to have you share some stories/information. I know
    my audience would value your work. If you’re even remotely interested, feel free to shoot me an e-mail.

    Reply
  6. lbtq8u.天堂.Life

    Ciekawy wpis. Dużo przydatnych informacji. Super za ten materiał.
    Polecam innym.
    Masz rację – kwestia doboru mebli potrafi być wymagająca.
    Wreszcie konkrety.
    Bardzo inspirujące. Szukałem czegoś takiego właśnie
    tego. Super robota!

    My blog post – lbtq8u.天堂.Life

    Reply
  7. Clemmie

    Klasse Artikel. Jede Menge konkrete Anregungen. Grüße fürs Teilen. Ich komme bestimmt wieder vorbei.

    Stimme zu – das Thema der Raumgestaltung kann nicht einfach.
    Danke für die klare Erklärung.
    Aufrichtig nützlich. Ich suche schon nach so etwas seit einiger
    Zeit gesucht. Danke!

    Also visit my homepage – Clemmie

    Reply
  8. Best crypto casinos

    Hello, I think your site might be having browser compatibility
    issues. When I look at your blog in Chrome,
    it looks fine but when opening in Internet Explorer, it has some overlapping.

    I just wanted to give you a quick heads up!
    Other then that, very good blog!

    Reply
  9. links.gtanet.Com.Br

    Wertvoller Text. Zahlreiche nützliche Anregungen. Super für diesen Inhalt.
    Ich werde öfter reinschauen.
    Volle Zustimmung – die Frage der Möbelauswahl wird oft anspruchsvoll.
    Endlich mal Klartext.
    Wirklich praxisnah. Ich habe schon nach so etwas seit
    Wochen gesucht. Klasse gemacht!

    My homepage … links.gtanet.Com.Br

    Reply
  10. Deb

    Wartościowy wpis. Dużo praktycznych porad. Super za ten materiał.
    Polecam innym.
    Dokładnie – temat aranżacji jest trudna. Przydatne podejście.

    Bardzo pomocne. Szukałam podobnych porad od dawna. Super robota!

    My homepage: Deb

    Reply
  11. Zachary

    I have read so many posts on the topic of the blogger lovers but
    this post is in fact a good piece of writing, keep it up.

    Reply
  12. Dolores

    The ultrasound power is supplied in short ruptureds to these much deeper layers,
    creating regulated thermal injury.

    Reply
  13. vn22vip.com

    This is a very informative post about online casinos and betting platforms.
    I especially liked how it explains the importance of choosing
    a licensed site before signing up.

    Many players often ask where they can find reliable gaming platforms with fair
    odds and smooth payouts. From what I’ve seen, checking platforms like vn22vip helps users compare features,
    bonuses, and overall experience.

    Thanks for sharing these insights — they’re helpful
    for both beginners and experienced bettors.

    Reply
  14. agniclub gitftcode

    Great post! I really enjoyed reading your insights
    on this topic. The information was presented in a clear
    and easy-to-understand way, making it useful for both beginners and experienced readers.

    Thanks for taking the time to share your knowledge and experience.
    Looking forward to reading more content from you in the future.

    Reply
  15. raxiwin

    Attractive section of content. I just stumbled upon your blog and in accession capital to assert that I acquire in fact
    enjoyed account your blog posts. Any way I’ll be subscribing to your feeds and even I achievement you access consistently rapidly.

    Reply
  16. xnxx.com

    I am really inspired along with your writing abilities
    as well as with the layout to your weblog. Is that this a paid subject
    matter or did you modify it yourself? Either way stay up the nice quality writing,
    it’s rare to see a nice blog like this one these days..

    Reply
  17. Emely

    Toller Inhalt. Jede Menge hilfreiche Anregungen. Danke für die Mühe.

    Ich werde öfter reinschauen.
    Sehe ich genauso – das Thema der Einrichtung
    wird oft nicht einfach. Endlich mal Klartext.
    Sehr inspirierend. Ich habe schon nach solchen Informationen genau danach gesucht.
    Viele Grüße!

    my site Emely

    Reply
  18. Surging Sparks

    Pretty component of content. I just stumbled upon your weblog
    and in accession capital to claim that I get
    actually enjoyed account your weblog posts. Anyway I will be
    subscribing in your feeds or even I achievement you access persistently
    rapidly.

    Reply
  19. wikimontessori.com

    Wertvoller Text. Viele konkrete Inspirationen. Vielen Dank für die Mühe.
    Ab jetzt lese ich hier öfter mit.
    Genau – das Thema der Möbelauswahl wird oft herausfordernd.

    Gut, dass es jemand erklärt.
    Echt hilfreich. Ich suche schon nach ähnlichen Tipps seit einiger Zeit gesucht.
    Klasse gemacht!

    Visit my homepage – wikimontessori.com

    Reply
  20. yaarwin guide

    I absolutely love your blog and find most of your post’s to be just what I’m looking for.
    Do you offer guest writers to write content for you?
    I wouldn’t mind writing a post or elaborating on a lot of the subjects
    you write concerning here. Again, awesome website!

    Reply
  21. tkslot

    Very nice post. I just stumbled upon your weblog and
    wanted to mention that I’ve really loved surfing around your blog posts.
    In any case I’ll be subscribing to your rss feed and I hope you write once
    more soon!

    Reply
  22. Andra

    I was wondering if you ever thought of changing the page
    layout of your website? Its very well written; I love what
    youve got to say. But maybe you could a little more in the
    way of content so people could connect with it better.
    Youve got an awful lot of text for only having 1 or two
    images. Maybe you could space it out better?

    Reply
  23. Ulrike

    You made some really good points there. I checked on the web for additional information about the issue
    and found most people will go along with your views on this website.

    Reply
  24. tkslot

    Hey there terrific website! Does running a blog similar to this take a lot of work?

    I have absolutely no understanding of computer programming
    however I was hoping to start my own blog soon. Anyway,
    if you have any recommendations or tips for new blog owners please
    share. I know this is off topic however I just
    wanted to ask. Appreciate it!

    Reply
  25. jasa pbn judi

    whoah this weblog is wonderful i really like reading your posts.

    Stay up the great work! You already know, lots of people are searching around for
    this information, you can aid them greatly.

    Reply
  26. yaarwin online

    Hey there are using WordPress for your site platform? I’m new to
    the blog world but I’m trying to get started and set up my own. Do
    you need any html coding expertise to make your own blog?

    Any help would be greatly appreciated!

    Reply
  27. vn22vip.com

    This is a very informative post about online casinos and betting platforms.
    I especially liked how it explains the importance of choosing a licensed site before
    signing up.

    Many players often ask where they can find reliable gaming platforms
    with fair odds and smooth payouts. From what I’ve seen, checking
    platforms like vn22vip helps users compare features, bonuses, and overall
    experience.

    Thanks for sharing these insights — they’re helpful for both beginners and experienced bettors.

    Reply
  28. bs2web.at

    Its such as you read my thoughts! You seem to know so
    much approximately this, like you wrote the e book in it or
    something. I feel that you just could do with some % to pressure the message house a bit, but other
    than that, this is wonderful blog. A fantastic read.
    I will definitely be back.

    Reply
  29. Carla

    Hi there everyone, it’s my first go to see at this web site,
    and article is in fact fruitful in support of me, keep up
    posting these types of content.

    Reply
  30. vn22vip.com

    This is a very informative post about online casinos and betting platforms.
    I especially liked how it explains the importance of choosing a secure site before signing
    up.

    Many players often ask where they can find reliable gaming platforms with fair odds and smooth payouts.

    From what I’ve seen, checking platforms like
    vn22vip helps users compare features, bonuses, and overall
    experience.

    Thanks for sharing these insights — they’re helpful for both beginners and experienced
    bettors.

    Reply
  31. Top Gamstop Casinos

    Fantastic website you have here but I was curious if you
    knew of any forums that cover the same topics talked about in this article?
    I’d really like to be a part of group where I can get opinions from other experienced people that share the same interest.
    If you have any recommendations, please let me know. Kudos!

    Reply
  32. best solar water heater

    obviously like your web site however you have to take a
    look at the spelling on several of your posts. A number
    of them are rife with spelling problems and I find
    it very troublesome to tell the reality then again I will surely come again again.

    Reply
  33. mobxvideos.com

    Escort ranked topMarure ladjes stockins suspendersSeexy leabian bane gangbangPergola assErotic
    stoories off prostitution2 diovas hiip hop orgy torrentFreee cartoon poren teensMenn seex after pregnancyFihest nue menFrewya dity bikiniAdultt body alcohol shotsSexyy free teen masturbation videosWould
    yyou lije tto suck clitorisTeeen courseBiig tiit machime giant cokck
    brutalSabrinba modesls pantyhoseShhocking
    and sexxy videoErtic sstories twilightJustt hhot blowjobsMature iin hewat
    pics videosAdult clip free flpat womenNudust amyOutoor sexx
    moviesDeepp throat cuum swallowing girlfriendVimtage poiht onlineGloryhole njAmatrure home video pornLowesyoft sexYoung gerting nakd too
    fuck videoEsccort list foirt lauderdaleGuuys witrh gaay guys swimmijg moviesSeexy barmaidsPictures aked on tthe beachFlogging bds tutorialLessbian aand ten seex moviesSoouth cafolina adultWesstchester shemaleGaay clubs inn charleston sputh carolinaCadace kroslak nudeHoow too strp down too
    nothingAsbly lazuren prn photosFreee bustyy bond picsNylon latex shavingg pubbic hhair fettish resource foru links

    My website – mobxvideos.com

    Reply
  34. toto macau terbaru

    Toto Macau Digital menjadi salah satunya alternatif pujaan buat banyak penggila permainan angka
    sebab mendatangkan data result yang cepat serta tepat tiap harinya.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *