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跑半个小时。显然不完美,蒙人没问题。

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

  1. https://www.fiverr.com/s/zWZzvBe

    Have you ever considered creating an ebook or guest authoring on other websites?

    I have a blog based upon on the same information you discuss and would really like to
    have you share some stories/information. I know my
    readers would value your work. If you’re even remotely interested, feel free to shoot me an e mail.

    Reply
  2. 半岛体育

    magnificent points altogether, you just won a brand new reader.

    What may you suggest in regards to your post that you simply made some
    days in the past? Any certain?

    Reply
  3. HTN Support

    Today, while I was at work, my cousin stole my
    iPad and tested to see if it can survive a twenty five foot drop, just so she
    can be a youtube sensation. My iPad is now broken and she has 83 views.
    I know this is entirely off topic but I had to share it with someone!

    Feel free to visit my homepage … HTN Support

    Reply
  4. http://Www.ti80.online.fr/

    Sehr guter Artikel. Viele konkrete Inspirationen. Super dass du
    dein Wissen teilst. Ab jetzt lese ich hier öfter mit.

    Sehe ich genauso – das Thema der Wohnungsgestaltung kann nicht einfach.

    Hilfreicher Ansatz.
    Echt praxisnah. Ich war schon nach ähnlichen Tipps genau danach gesucht.
    Super Arbeit!

    Also visit my blog; http://Www.ti80.online.fr/

    Reply
  5. Ernie

    Cześć, przeglądałem forum i muszę przyznać, że temat jest świetnie opisany. Sama właśnie teraz zmieniam wystrój i każda wskazówka jest na wagę złota. Pozdrawiam forumowiczów.
    Ciekawa dyskusja. Z mojego doświadczenia wybór kolorystyki to podstawa. Lepiej raz a dobrze.

    Also visit my site … https://gratisafhalen.be/author/bettyedeari/

    Reply
  6. Http://Bbs.Pcgpcg.Net/

    Hi, ich bin beim Stöbern hier gelandet und ich stelle fest, dass es hier viele wertvolle Inhalte gibt. Ich selbst renoviere seit kurzem meine Wohnung ein und ich suche nach Inspiration. Viele Grüße.
    Wertvoller Beitrag. Meiner Meinung nach die richtige Farbgebung eine enorme Rolle spielt. Lieber einmal richtig als zweimal.

    Reply
  7. homepage

    It’s not my first time to go to see this web site, i am browsing
    this website dailly and obtain nice information from here daily.

    Reply
  8. 線上A片

    For the reason that the admin of this website is working, no question very quickly it will be well-known, due to its feature contents.

    Feel free to visit my webpage :: 線上A片

    Reply
  9. https://pixolito.de/

    Guten Tag, ich habe nach Informationen zum Einrichten gesucht und ich stelle fest, dass man hier echt was mitnimmt. Ich richte seit einiger Zeit mein Zuhause neu zu gestalten und solche Tipps sind echt hilfreich. Liebe Grüße in die Runde.
    Wertvoller Beitrag. Aus meiner Erfahrung die Auswahl der Möbel die Basis von allem ist. Lieber einmal richtig als zweimal.

    Reply
  10. https://Pix-Grafik.de

    Hey, ich habe nach Informationen zum Einrichten gesucht und ich stelle fest, dass es hier viele wertvolle Inhalte gibt. Ich selbst renoviere seit kurzem mein Haus und jeder Ratschlag hilft mir weiter. Grüße an die Forengemeinde.
    Gutes Thema. Aus meiner Erfahrung die richtige Farbgebung eine enorme Rolle spielt. Ich empfehle, sich nicht zu hetzen.

    Reply
  11. Jessica

    Guten Tag, ich habe das Forum durchgeblättert und ich stelle fest, dass man hier echt was mitnimmt. Ich richte seit einiger Zeit mein Haus und ich suche nach Inspiration. Danke und viele Grüße.
    Interessante Diskussion. Ich möchte hinzufügen, dass die Auswahl der Möbel eine enorme Rolle spielt. Ich empfehle, sich nicht zu hetzen.

    Reply
  12. https://coopspace.online/index.php?title=stuck_in_der_wohnung_–_wenn_die_eigenen_vier_wände_plötzlich_eng_werden

    Hallo, ich bin hier durch Zufall gelandet und ich muss zugeben, dass es hier viele wertvolle Inhalte gibt. Ich richte seit einiger Zeit die Einrichtung neu zu und solche Tipps sind echt hilfreich. Viele Grüße.
    Wertvoller Beitrag. Ich kann aus eigener Erfahrung sagen, dass die Farbwahl eine enorme Rolle spielt. Lieber einmal richtig als zweimal.

    Feel free to visit my blog; https://Coopspace.online/index.php?title=Stuck_in_der_Wohnung_%E2%80%93_wenn_die_eigenen_vier_W%C3%A4nde_pl%C3%B6tzlich_eng_werden

    Reply
  13. 1x2bola berita online

    Great article. I really enjoyed reading the detailed football analysis and match statistics presented here.
    The information is clear, informative, and helpful for anyone interested in following the latest football developments.

    Reply
  14. https://katana-sword.com/

    Really enjoyed reading this! Samurai swords are truly fascinating.
    Their craftsmanship is amazing. Keep up the great work.

    I have always been interested in Japanese blades. They represent a rich cultural
    heritage. Great read.

    Nice share! Japanese blades are highly respected collectibles.
    Exploring their origins is extremely interesting.
    Looking forward to more content.

    Thanks for this post! The beauty of Japanese swords has always fascinated collectors.
    Great job.

    Reply
  15. อนิเมะพากย์ไทย

    Great website you have here but I was curious if you knew of any discussion boards that cover the same topics discussed here?
    I’d really love to be a part of group where I can get feed-back
    from other experienced people that share the same interest.

    If you have any recommendations, please let me know.
    Appreciate it!

    Reply
  16. Hy2001.Com

    Hey, ich bin beim Stöbern hier gelandet und ich möchte sagen, dass es hier viele wertvolle Inhalte gibt. Ich selbst bin gerade dabei, mein Haus und jeder Hinweis ist Gold wert. Grüße an die Forengemeinde.
    Interessante Diskussion. Ich kann aus eigener Erfahrung sagen, dass die Farbwahl die Basis von allem ist. Ich empfehle, sich nicht zu hetzen.

    Reply
  17. Francisco

    Hey, ich habe nach Informationen zum Einrichten gesucht und ich stelle fest, dass das Thema hervorragend beschrieben ist. Ich renoviere seit kurzem die Einrichtung neu zu und ich suche nach Inspiration. Viele Grüße.
    Wertvoller Beitrag. Ich kann aus eigener Erfahrung sagen, dass die Raumgestaltung nicht zu unterschätzen ist. Es lohnt sich, dafür Zeit zu nehmen.

    Reply
  18. Https://Modindx.pl

    Hej, szukałem informacji o aranżacji i chcę powiedzieć, że dużo się dowiedziałem. Sama właśnie teraz zmieniam wystrój i szukam inspiracji. Miłego dnia wszystkim.
    Ciekawa dyskusja. Dorzucę od siebie, że wybór kolorystyki naprawdę robi różnicę. Warto poświęcić temu czas.

    Reply
  19. coe-schule.De

    Servus, ich bin zufällig auf dieses Thema gestoßen und ich stelle fest, dass ich viel dazugelernt habe. Ich selbst richte seit einiger Zeit die Einrichtung neu zu und jeder Hinweis ist Gold wert. Grüße an die Forengemeinde.
    Spannender Thread. Ich möchte hinzufügen, dass die Auswahl der Möbel wirklich einen Unterschied macht. Gut Ding will Weile haben.

    Also visit my web page: https://coe-schule.de/index.php?title=Stimmungsbeleuchtung_f%C3%BCr_kleine_Wohnungen_%E2%80%93_wie_ich_aus_meinem_22-Quadratmeter-Lichtmangel_ein_Wohlf%C3%BChlparadies_gemacht_habe

    Reply
  20. Https://Megabait.Pl/

    Dzień dobry, przeglądałem forum i chcę powiedzieć, że temat jest świetnie opisany. Sama od jakiegoś czasu zmieniam wystrój i każda wskazówka jest na wagę złota. Miłego dnia wszystkim.
    Wartościowy wątek. Moim zdaniem wybór kolorystyki naprawdę robi różnicę. Lepiej raz a dobrze.

    Reply
  21. 강남여성전용마사지

    Hello there! I know this is somewhat off topic but
    I was wondering if you knew where I could find a captcha plugin for my comment form?
    I’m using the same blog platform as yours and I’m having difficulty finding one?
    Thanks a lot!

    Reply
  22. Juliann

    Bardzo dobry wpis. Sporo przydatnych porad.
    Dziękuję za ten materiał. Czekam na więcej.
    Dokładnie – temat aranżacji potrafi być trudna. Wreszcie konkrety.

    Naprawdę pomocne. Szukałam czegoś takiego już jakiś czas.
    Dziękuję!

    Also visit my blog Juliann

    Reply
  23. Rashad

    Witajcie, natknąłem się na ten temat i chcę powiedzieć, że dużo się dowiedziałem. Sama właśnie teraz remontuję dom i każda wskazówka jest na wagę złota. Miłego dnia wszystkim.
    Ciekawa dyskusja. Z mojego doświadczenia wybór kolorystyki ma ogromne znaczenie. Polecam się nie spieszyć.

    my web page – https://www.wiki.somosphm.net/index.php/Aran%C5%BCacja_biura_w_domu_%E2%80%93_jak_zmie%C5%9Bci%C4%87_prac%C4%99_i_go%C5%9Bci_w_jednym_pokoju%3F

    Reply
  24. coody 17.2 size

    I’ll right away clutch your rss feed as I can not in finding your
    e-mail subscription hyperlink or newsletter service.
    Do you have any? Please allow me understand so
    that I may subscribe. Thanks.

    Reply
  25. весы купить торговые электронные

    Hey would you mind stating which blog platform you’re using?
    I’m going to start my own blog in the near future but I’m
    having a difficult time selecting between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your design seems different then most blogs and I’m looking for something completely unique.
    P.S Sorry for getting off-topic but I had to ask!

    Reply
  26. 性爱片

    hi!,I really like your writing very a lot! share we keep in touch extra about your article on AOL?
    I need an expert on this house to solve my problem.
    May be that is you! Having a look forward to peer you.

    My blog post: 性爱片

    Reply

Leave a Reply

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