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,428 thoughts on “Use a simple script to achieve powder pile | Maya nParticle简单脚本实现粒子堆叠

  1. Https://Openmachinery.Net/Index.Php/Skandinavischer_Einrichtungsstil:_GemüTlichkeit_FüR_Kleine_Wohnungen

    Sehr guter Inhalt. Viele hilfreiche Informationen. Großes Lob fürs
    Teilen. Ich warte auf mehr.
    Sehe ich genauso – der Bereich der Wohnungsgestaltung kann anspruchsvoll.
    Gut, dass es jemand erklärt.
    Sehr hilfreich. Ich habe schon nach solchen Informationen lange gesucht.

    Klasse gemacht!

    Here is my website … https://Openmachinery.Net/Index.Php/Skandinavischer_Einrichtungsstil:_GemüTlichkeit_FüR_Kleine_Wohnungen

    Reply
  2. 시알리스 구매사이트

    It’s the best time to make some plans for the
    future and it’s time to be happy. I have read this post and if I could I
    wish to suggest you few interesting things or tips.
    Perhaps you could write next articles referring to this article.
    I desire to read even more things about it!

    Reply
  3. Deanne

    Świetny artykuł. Mnóstwo konkretnych porad. Pozdrawiam za podzielenie się.

    Czekam na więcej.
    Dokładnie – kwestia aranżacji bywa niełatwa. Dobrze, że ktoś
    to wyjaśnia.
    Naprawdę przydatne. Szukałam podobnych porad już jakiś czas.
    Dziękuję!

    Here is my blog post; Deanne

    Reply
  4. https://pakistan-cricket-team-players.com/

    I just finished reading your latest post and I felt the need to show my
    appreciation. Your engaging breakdown of the team makes this content
    stand out from the rest.

    The most valuable part is that you can feel the passion in your
    writing. You gave me new insights to think about.

    I’ll definitely be following your content! Your blog instantly became one of
    my favorites.

    Reply
  5. best online casino

    Pretty nice post. I just stumbled upon your weblog and wanted to say that I’ve really enjoyed surfing around your blog posts. After all I’ll be subscribing in your feed and I am hoping you write again very soon!

    Reply
  6. Kimber

    Wartościowy artykuł. Dużo przydatnych wskazówek.
    Pozdrawiam że dzielisz się wiedzą. Będę zaglądać częściej.

    Trafnie napisane – temat aranżacji bywa wymagająca.

    Przydatne podejście.
    Szczerze pomocne. Szukałem czegoś takiego właśnie tego.
    Pozdrawiam!

    my web blog: Kimber

    Reply
  7. https://alertplumber.com/

    I’ve been surfing online more than 2 hours today, yet I never
    found any interesting article like yours.
    It’s pretty worth enough for me. Personally,
    if all website owners and bloggers made good content as you did, the web will be much more useful than ever before.

    Reply
  8. Francisca

    Rzeczowy artykuł. Dużo wartościowych informacji. Dziękuję za podzielenie
    się. Czekam na więcej.
    Trafnie napisane – kwestia urządzania wnętrz jest wymagająca.

    Wreszcie konkrety.
    Naprawdę inspirujące. Szukałam takich informacji już jakiś czas.
    Dziękuję!

    my webpage :: Francisca

    Reply
  9. highest ROI property in Dubai

    Dubai is song of the domain’s beat real manor investment destinations, sacrifice dues advantages, strong rental yields, and премиум lifestyle opportunities.

    From sybaritism villas to high-rise apartments, buying means in Dubai provides unequalled budding as a
    remedy for both profits and long-term major growth.

    Reply
  10. Hildegarde

    Hello my family member! I want to say that this post is amazing, great written and include approximately all important
    infos. I would like to look more posts like this .

    Also visit my web site :: 成人影片, Hildegarde,

    Reply
  11. 亿兆注册

    I know this if off topic but I’m looking into starting my own weblog and was wondering what all is required to
    get setup? I’m assuming having a blog like yours would cost a
    pretty penny? I’m not very internet smart so I’m not 100%
    certain. Any recommendations or advice would be greatly appreciated.
    Appreciate it

    Reply
  12. play888new.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
  13. Arcadetimecapsule.com

    Interessanter Beitrag. Jede Menge nützliche Informationen. Danke für diesen Inhalt.
    Ich speichere mir die Seite ab.
    Treffend formuliert – das Thema der Wohnungsgestaltung wird oft anspruchsvoll.
    Hilfreicher Ansatz.
    Sehr hilfreich. Ich suche schon nach ähnlichen Tipps seit Wochen gesucht.

    Super Arbeit!

    My web page … Arcadetimecapsule.com

    Reply
  14. کلاس مجازی

    راستش من این کامنت رو بیشتر از زاویه تجربه شخصی
    می‌نویسم و نمی‌خوام چیزی رو قطعی معرفی کنم.
    وقت بخیر، معمولاً فقط وقتی چیزی برام جالب باشه نظر می‌دم.
    مدتی قبل وقتی دنبال مقایسه چند
    سایت بودم اینجا برام جالبشد.
    در نگاه اول حس کردم ساختارش بد نیست.
    راستش برای من مهمه که نباید فقط به ظاهر سایت اعتماد کرد.
    یکی از دوستام به اسم محسن قبلاً درباره بازی انفجار زیاد سوال می‌پرسید.
    به همین خاطر چند بخش رو با حوصله‌تر
    خوندم. برداشت من این بود که چند بخشش برای مقایسه مفید بود.
    بااین حال همیشه بهتره چند گزینه کنار هم مقایسه بشن.
    برای آدم‌هایی که تازه با این فضا
    آشنا شدن می‌خوان درباره
    بازی انفجار بیشتر بدونن، بد نیست این صفحه رو هم ببینن.
    وقتی این حوزه رو نگاه می‌کنی نمونه‌هایی مثل enfejarоnline.net همراه با برند sibbet نشون میدن این حوزه چقدر گسترده شده.

    یکی از بچه‌ها که اسمش سامان بود، می‌گفت مشکل
    خیلی از سایت‌ها اینه که فقط شعار می‌دن ولی
    توضیح درست نمی‌دن؛ برای همین من هم بیشتر به
    متن‌ها دقت کردم. در مجموع حداقل برای آشنایی اولیه می‌تونه مفید باشه.
    فکر می‌کنم منطقی‌تره قبل از هر اقدامی شرایط و جزئیات رو
    بررسی کنه. اگر بخوام ساده بگم، نه می‌شه با یک نگاه تأییدش کرد نه ردش؛ بهتره چند بخشش رو دید،
    شرایط رو خوند و بعد نظر داد.

    Feel free to surf to mmy web site; کلاس مجازی

    Reply
  15. compensation

    Hello there! Would you mind if I share your blog with my facebook group?
    There’s a lot of people that I think would really enjoy your content.
    Please let me know. Thank you

    Reply
  16. Thao

    Wertvoller Post. Zahlreiche wertvolle Inspirationen. Großes Lob
    fürs Teilen. Ich empfehle die Seite gerne weiter.

    Sehe ich genauso – die Sache der Wohnungsgestaltung kann
    herausfordernd. Endlich mal Klartext.
    Wirklich hilfreich. Ich suche schon nach so etwas seit einiger Zeit gesucht.
    Klasse gemacht!

    Have a look at my web page: Thao

    Reply
  17. اخبار استارتاپ

    به صورت جمع‌بندی

    برای کاربرایی که در جستجو هستن

    شرط آنلاین

    در این زمینه مشغولن

    این آدرس

    می‌تونه یکی از گزینه‌ها باشه

    مفید واقع بشه

    جالبه که

    سرویس‌هایی مثل

    еnfejaronline خوب

    و

    sibbet

    باعث رشد این فضا شدن

    به طور کلی

    جذاب بود

    و

    احتمالاً

    میام سراغش

    My web blog … اخبار استارتاپ

    Reply
  18. tante girang

    I absolutely love your blog and find a lot of your post’s to be exactly
    what I’m looking for. Does one offer guest
    writers to write content for you personally? I wouldn’t mind creating a
    post or elaborating on many of the subjects you write in relation to here.
    Again, awesome web log!

    Reply
  19. https://arizo-Kino.ru

    Interessanter Inhalt. Reichlich nützliche Informationen. Grüße fürs
    Teilen. Ich speichere mir die Seite ab.
    Sehe ich genauso – die Sache der Einrichtung wird oft schwierig.
    Endlich mal Klartext.
    Sehr inspirierend. Ich suche schon nach ähnlichen Tipps lange gesucht.
    Viele Grüße!

    Review my web-site – https://arizo-Kino.ru

    Reply
  20. http://Www.P2SKY.Com

    Ciekawy materiał. Wiele konkretnych informacji. Dzięki za podzielenie
    się. Zapisuję do ulubionych.
    Zgadzam się – sprawa wystroju jest wymagająca.
    Przydatne podejście.
    Bardzo przydatne. Szukałem czegoś takiego właśnie tego.
    Pozdrawiam!

    My web-site; http://Www.P2SKY.Com

    Reply
  21. tkslot

    I just like the helpful info you supply for your articles.
    I will bookmark your weblog and check once more right here frequently.
    I am somewhat certain I’ll be told plenty of new stuff right here!
    Good luck for the next!

    Reply
  22. Doctiplus online doctors

    I’m really impressed together with your writing talents as neatly as with the structure in your weblog.

    Is this a paid theme or did you customize it your self? Anyway stay up the nice quality writing, it is rare to see a great blog like this one these
    days..

    Reply
  23. Jetta

    It’s in fact very complex in this active life to listen news on Television, thus
    I simply use the web for that reason, and obtain the latest news.

    Reply
  24. Leanne

    Wirklich guter Inhalt. Jede Menge wertvolle Inspirationen. Grüße dass du dein Wissen teilst.

    Ich speichere mir die Seite ab.
    Stimme zu – die Frage der Raumgestaltung ist
    anspruchsvoll. Hilfreicher Ansatz.
    Sehr praxisnah. Ich war schon nach genau so einem Beitrag seit Wochen gesucht.
    Danke!

    Feel free to visit my webpage – Leanne

    Reply
  25. kra25 cc

    Hello to all, as I am actually eager of reading this website’s post to be
    updated daily. It contains fastidious stuff.

    Reply
  26. yaarwin

    Hey there outstanding website! Does running a blog similar to this require a
    great deal of work? I’ve no expertise in coding but
    I was hoping to start my own blog soon. Anyway, if you have any suggestions or tips for new blog owners please share.
    I know this is off topic nevertheless I simply had to ask.
    Thanks!

    Reply
  27. timo agro

    Gıda ürünleri temini işletmeler için sadece fiyatla
    değerlendirilecek bir konu değil. Teslimat düzeni de en az fiyat kadar önemli.
    Bu açıdan Timo Agro gibi kurumsal çalışan firmaların tercih edilmesi işletmeler için avantaj sağlayabilir.

    Reply
  28. ee88

    Hi there, just became aware of your blog through
    Google, and found that it’s truly informative.

    I am gonna watch out for brussels. I’ll appreciate if you
    continue this in future. Numerous people will be benefited from your writing.
    Cheers!

    Reply
  29. Dubai property for sale

    Dubai is one of the world’s outstrip real caste investment destinations, gift dues advantages,
    energetic rental yields, and premium lifestyle opportunities.
    From self-indulgence villas to high-rise apartments,
    buying acreage in Dubai provides nonpareil potential looking for both receipts
    and long-term money growth.

    Reply
  30. fb88 link

    I don’t know if it’s just me or if everybody else experiencing issues with your site. It appears as though some of the written text on your content are running off the screen. Can someone else please provide feedback and let me know if this is happening to them as well? This could be a problem with my web browser because I’ve had this happen before. Appreciate it

    Reply
  31. online casino nz

    Most often since i look for a blog Document realize that the vast majority of blog pages happen to be amateurish. Not so,We can honestly claim for which you writen is definitely great and then your webpage rock solid.

    Reply

Leave a Reply

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