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

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

  1. Jean

    Pretty nice post. I just stumbled upon your blog and wished to say that
    I’ve really enjoyed browsing your blog posts. In any case I will be subscribing to your
    feed and I hope you write again soon!

    Reply
  2. Kathie

    Wirklich guter Inhalt. Jede Menge hilfreiche Tipps.
    Super für diesen Inhalt. Ich empfehle die Seite gerne weiter.

    Du hast recht – die Sache der Einrichtung kann anspruchsvoll.

    Gut, dass es jemand erklärt.
    Aufrichtig hilfreich. Ich war schon nach solchen Informationen seit Wochen gesucht.
    Super Arbeit!

    Also visit my web-site … Kathie

    Reply
  3. Dirk

    Unquestionably believe that which you stated. Your favorite reason seemed to be
    on the net the easiest thing to be aware of. I say to
    you, I certainly get annoyed while people consider worries that they just do not know about.
    You managed to hit the nail upon the top as well as
    defined out the whole thing without having side effect ,
    people can take a signal. Will likely be back to get more.
    Thanks

    Here is my homepage … iptv braga – Dirk

    Reply
  4. https://rt.chat-rulet-18.com/blonde

    Does your site have a contact page? I’m having a tough time locating
    it but, I’d like to send you an email. I’ve got some creative ideas for your
    blog you might be interested in hearing. Either way,
    great blog and I look forward to seeing it grow over
    time.

    Reply
  5. rape sex child

    Thanks for some other informative blog. The place else could I
    get that kind of info written in such an ideal method?
    I’ve a venture that I’m simply now working on, and I have been on the look out for such info.

    Reply
  6. ทางเข้า betflix9s

    โพสต์นี้ อ่านแล้วได้ความรู้เพิ่ม ค่ะ
    ผม เพิ่งเจอข้อมูลเกี่ยวกับ ข้อมูลเพิ่มเติม
    ดูต่อได้ที่ ทางเข้า betflix9s
    ลองแวะไปดู
    มีการยกตัวอย่างที่เข้าใจง่าย
    ขอบคุณที่แชร์ บทความคุณภาพ นี้
    และอยากเห็นบทความดีๆ แบบนี้อีก

    Reply
  7. 하늘페이

    hello!,I love your writing so much! percentage we
    communicate extra approximately your article on AOL?
    I need an expert in this area to resolve my problem.
    Maybe that’s you! Having a look ahead to see you.

    Reply
  8. http://hopmann.nrw

    Wirklich guter Inhalt. Reichlich nützliche Hinweise.

    Danke für die Mühe. Ich werde öfter reinschauen.
    Sehe ich genauso – der Bereich der Wohnungsgestaltung wird
    oft herausfordernd. Endlich mal Klartext.
    Wirklich hilfreich. Ich war schon nach genau so einem
    Beitrag lange gesucht. Super Arbeit!

    My webpage: http://hopmann.nrw

    Reply
  9. see details

    Thanks for one’s marvelous posting! I truly enjoyed reading it, you are a great author.I will always
    bookmark your blog and will come back from now on. I want to encourage yourself
    to continue your great work, have a nice day!

    Reply
  10. details

    Hi there, for all time i used to check web site posts here early in the break of day, for the reason that i like
    to learn more and more.

    Reply
  11. Situsbuktogel

    Link exchange is nothing else but it is just placing the other person’s
    web site link on your page at proper place and other person will also do same for you.

    Reply
  12. beruangjitu

    I would like to thank you for the efforts you’ve put in writing this blog.
    I am hoping to check out the same high-grade content by you in the future as well.

    In fact, your creative writing abilities has encouraged me to get
    my own, personal website now 😉

    Reply
  13. Situs Resmi 1131gg.uk

    Thanks , I have recently been looking for information approximately this topic for a while and yours is
    the greatest I’ve discovered till now. But,
    what concerning the bottom line? Are you positive in regards to the source?

    Reply
  14. platform review

    Hey there! Do you use Twitter? I’d like to follow you if that
    would be okay. I’m undoubtedly enjoying your blog and look forward to
    new updates.

    Reply
  15. 最新 ラブドール

    長年気になっていたテーマで 、今回詳しく解説していただきありがとうございます。実際に自分で試したときは 多かったので、記事を読んでスッキリしました。専門的すぎず一般人にも分かりやすい
    点がとても良いと感じました。 また新しい情報があれば確認しに来ます。

    Reply
  16. Escorts In Nagpur Cash Payment

    Good day very cool web site!! Guy .. Beautiful .. Superb ..
    I’ll bookmark your blog and take the feeds additionally?
    I am glad to seek out a lot of useful info here in the
    submit, we want develop extra techniques in this regard, thank
    you for sharing. . . . . .

    Reply
  17. viagra

    Hi, i read your blog occasionally and i own a similar one and
    i was just curious if you get a lot of spam feedback? If
    so how do you protect against it, any plugin or anything you
    can recommend? I get so much lately it’s driving me crazy so any assistance is very much appreciated.

    Reply
  18. Boris

    It maintains the stability of the pelvic body organs and permits the pelvic organs to have a certain level of activity [52]

    Reply
  19. https://peacemovers.com/author/essiepigot9631/

    With havin so much content and articles do you ever run into any problems
    of plagorism or copyright violation? My website has a lot of
    completely unique content I’ve either written myself or outsourced
    but it appears a lot of it is popping it up all over the internet without my permission. Do you know
    any techniques to help protect against content from
    being stolen? I’d definitely appreciate it.

    Reply
  20. 마나토끼

    Hmm it looks like your blog ate my first comment (it was super long) so I guess I’ll just sum it up what I submitted and
    say, I’m thoroughly enjoying your blog. I as well am
    an aspiring blog writer but I’m still new to everything.

    Do you have any helpful hints for novice blog writers?

    I’d definitely appreciate it.

    Reply
  21. 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
  22. socolive

    Socolive là điểm đến lý tưởng dành cho những người yêu thích cá cược
    bóng đá và thể thao. Với nền tảng hiện đại và
    uy tín hàng đầu, Socolive mang đến trải nghiệm cá cược trực tiếp
    cùng link bóng đá chất lượng, giúp người chơi dễ dàng theo dõi và đặt cược chính xác hơn.

    Reply
  23. beste online casino

    My brother suggested I might like this websiteHe was once totally rightThis post truly made my dayYou can not imagine simply how a lot time I had spent for this information! Thanks!

    Reply
  24. win1131

    Postingan yang sangat informatif! Ulasan ini sangat membantu bagi para pemain yang sedang mencari referensi situs dengan performa terbaik.

    Memang benar, memilih platform dengan **RTP
    Tinggi** seperti **WIN1131** adalah langkah cerdas untuk mendapatkan pengalaman bermain yang maksimal.
    Ditambah lagi dengan dukungan **Livechat 24 Jam** yang stand by, kita jadi merasa lebih aman saat
    bermain. Terima kasih sudah berbagi! Kunjungi WIN1131 Sekarang

    Reply
  25. cnhub.xyz

    Afterr I orriginally comented I seewm tto have clickesd tthe -Notjfy mme wen nnew commenfs
    aree added- checkox annd nnow eafh tme a commnt is aded I recieve fouyr emjails with tthe exat
    same comment. Ther has tto bee a means youu aree abvle tto remove mme from that service?
    Thanks!

    Also vissit myy blog: cnhub.xyz

    Reply
  26. ラブドール

    Do you have a spam issue on this site; I also am a blogger,
    and I was wondering your situation; many of us have created some nice procedures and we are looking to
    trade techniques with other folks, why not shoot me an e-mail
    if interested.

    Reply
  27. wisata alam indonesia

    Masya Allah ulasannya! Indonesia memang memiliki destinasi
    wisata yang sangat memukau. Saya sangat setuju bahwa Pesona Alam Indonesia adalah keindahan yang tak tergantikan, mulai dari gunung hingga pantainya.
    Terima kasih sudah berbagi informasi ini, sangat membantu saya merencanakan liburan berikutnya.
    Mari jelajahi Wisata Alam Indonesia yang lainnya juga!
    Wisata Alam Indonesia

    Reply
  28. خرید بک لینک

    Magnificent goods from you, man. I’ve understand your stuff previous to and you’re just extremely great.
    I really like what you have acquired here, really
    like what you are stating and the way in which you say it.
    You make it entertaining and you still care for to keep
    it smart. I cant wait to read much more from you. This is really a tremendous site.

    my page :: خرید بک لینک

    Reply
  29. homepage

    Heya i’m for the first time here. I found this board
    and I find It really useful & it helped me out much. I hope to give something
    back and aid others like you aided me.

    Reply
  30. Best crypto casinos

    Hi! I could have sworn I’ve been to this blog before but after checking
    through some of the post I realized it’s new to me. Nonetheless, I’m definitely glad I found it and I’ll be bookmarking and
    checking back often!

    Reply

Leave a Reply

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