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

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

  1. kasyno online opinie

    Kasyno Remuneration bez Depozytu za Rejestracje to jedna z najbardziej popularnych visualize promocji oferowanych przez
    legalne platformy hazardowe online. Tego typu gratuity
    pozwala nowym uzytkownikom rozpoczac gre bez koniecznosci wplacania wlasnych srodkow
    na konto. Wystarczy zazwyczaj zalozenie
    konta oraz spelnienie okreslonych warunkow regulaminowych,
    aby otrzymac darmowe srodki lub darmowe obroty na wybranych automatach.
    Dla wielu graczy jest to atrakcyjna mozliwosc sprawdzenia funkcji kasyna bez ponoszenia dodatkowych kosztow.

    Reply
  2. xk星空

    I’m not sure exactly why but this blog is loading very slow for me.
    Is anyone else having this issue or is it a problem on my end?

    I’ll check back later and see if the problem still exists.

    Reply
  3. Danielmom

    Демо-режим у Vavada дозволяє випробувати слоти без ризику. Ознайомитися з деталями можна за посиланням – [url=https://potogoldranch.org/]https://potogoldranch.org/[/url] Почати можна з демо-версій улюблених слотів.

    Reply
  4. download video bokep indonesia

    Wonderful work! This is the kind of information that should be shared around the internet.
    Disgrace on the search engines for now not positioning this post higher!
    Come on over and talk over with my web site .
    Thanks =)

    Reply
  5. Margret

    Wartościowy artykuł. Sporo konkretnych inspiracji.
    Dziękuję za ten materiał. Polecam innym.

    Zgadzam się – kwestia urządzania wnętrz bywa wymagająca.
    Wreszcie konkrety.
    Naprawdę inspirujące. Szukałem podobnych porad właśnie tego.
    Dziękuję!

    Feel free to surf to my homepage – Margret

    Reply
  6. Christen

    Świetny wpis. Sporo przydatnych informacji. Pozdrawiam za podzielenie
    się. Na pewno tu wrócę.
    Trafnie napisane – sprawa wystroju bywa wymagająca. Dobrze, że ktoś to wyjaśnia.

    Naprawdę przydatne. Szukałem czegoś takiego właśnie tego.
    Super robota!

    Feel free to surf to my web page: Christen

    Reply
  7. Yanira

    I’m now not sure where you’re getting your info, however great topic.
    I must spend a while learning more or working out more.
    Thank you for excellent information I used to
    be looking for this information for my mission.

    Reply
  8. Aasee-Musik.De

    Interessanter Post. Zahlreiche praktische Hinweise.
    Super fürs Teilen. Ich empfehle die Seite gerne weiter.

    Sehe ich genauso – das Thema der Wohnungsgestaltung wird oft anspruchsvoll.

    Endlich mal Klartext.
    Echt nützlich. Ich war schon nach ähnlichen Tipps seit einiger Zeit gesucht.
    Klasse gemacht!

    Also visit my blog … Aasee-Musik.De

    Reply
  9. online casino canada

    Your style is very unique in comparison to other folks I have read stuff from.
    Many thanks for posting when you’ve got the opportunity, Guess I will just bookmark this page.

    Reply
  10. Falone.eu

    Klasse Beitrag. Zahlreiche konkrete Anregungen. Vielen Dank für
    die Mühe. Ich warte auf mehr.
    Sehe ich genauso – das Thema der Wohnungsgestaltung wird oft nicht einfach.
    Gut, dass es jemand erklärt.
    Echt praxisnah. Ich war schon nach solchen Informationen genau danach gesucht.
    Viele Grüße!

    Here is my website – Falone.eu

    Reply
  11. bokep indonesia

    Hey! This is my first comment here so I just wanted to give a quick shout out and say I really enjoy reading
    your articles. Can you recommend any other blogs/websites/forums that go over the same subjects?
    Appreciate it!

    Reply
  12. 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
  13. Vivod iz zapoya na domy_frmt

    Питер, всем привет Брат снова сорвался Родственники не знают что делать В больницу тащить страшно Короче, только это реально спасло — капельница от алкоголя на дому спб качественно Через пару часов человек пришёл в себя В общем, не потеряйте контакты — вывести из запоя на дому спб [url=https://narkolog.vyvod-iz-zapoya-na-domu-sankt-peterburg.ru]https://narkolog.vyvod-iz-zapoya-na-domu-sankt-peterburg.ru[/url] Вывод из запоя на дому — это реальный выход Перешлите тем кто в такой же ситуации

    Reply
  14. kasyno online opinie

    Kasyno Compensation bez Depozytu za Rejestracje to jedna z najbardziej popularnych visualize promocji oferowanych przez legalne platformy
    hazardowe online. Tego typu douceur pozwala nowym uzytkownikom rozpoczac
    gre bez koniecznosci wplacania wlasnych srodkow na konto.
    Wystarczy zazwyczaj zalozenie konta oraz spelnienie okreslonych warunkow regulaminowych, aby otrzymac darmowe srodki lub
    darmowe obroty na wybranych automatach. Dla wielu graczy jest to atrakcyjna mozliwosc sprawdzenia funkcji kasyna bez ponoszenia dodatkowych kosztow.

    Reply
  15. Https://Yangyuyin.Com/

    Naprawdę dobry materiał. Sporo wartościowych porad.
    Pozdrawiam za podzielenie się. Polecam innym.

    Masz rację – sprawa urządzania wnętrz bywa
    wymagająca. Dobrze, że ktoś to wyjaśnia.

    Szczerze pomocne. Szukałem takich informacji od dawna.
    Dziękuję!

    my page: https://Yangyuyin.Com/

    Reply
  16. join jihad war

    I believe that is among the such a lot significant info for me.
    And i’m glad reading your article. However should statement on few common issues, The site style is perfect, the articles is truly nice : D.
    Good process, cheers

    Reply
  17. xingkong

    Aw, this was an extremely good post. Taking a few minutes and actual effort to
    make a superb article… but what can I say… I put things off a
    lot and never manage to get anything done.

    Reply
  18. xnxx.com

    It’s the best time to make some plans for the future and it is time
    to be happy. I have read this post and if I could I
    wish to suggest you few interesting things or advice.

    Perhaps you can write next articles referring to this article.
    I want to read even more things about it!

    Reply
  19. yang dimaksud fufu fafa

    Generally I do not learn post on blogs, however I would like to say that this write-up very forced me to check out and do so!
    Your writing style has been amazed me. Thanks, quite great post.

    Reply
  20. https://wiki.tgt.Eu.com/

    Wertvoller Beitrag. Jede Menge hilfreiche Anregungen.
    Super für den Beitrag. Ich empfehle die Seite gerne weiter.

    Du hast recht – die Frage der Einrichtung kann
    schwierig. Endlich mal Klartext.
    Echt praxisnah. Ich suche schon nach genau so einem Beitrag lange gesucht.
    Super Arbeit!

    My website – https://wiki.tgt.Eu.com/

    Reply
  21. 掃除機用フィルター

    Hi there are using WordPress for your blog platform?

    I’m new to the blog world but I’m trying to get started and create my
    own. Do you need any html coding knowledge to make
    your own blog? Any help would be really appreciated!

    Reply
  22. mcm998

    Excellent way of describing, and pleasant paragraph to obtain facts about my presentation subject matter, which i am going to
    convey in college.

    Reply
  23. Buy Xanax Online

    I will immediately take hold of your rss feed as I can’t find your e-mail subscription link or newsletter service.
    Do you’ve any? Kindly permit me understand in order that
    I may subscribe. Thanks.

    Reply
  24. xingkong

    This is a great tip especially to those fresh to the blogosphere.
    Brief but very precise information… Thank you for sharing this one.
    A must read article!

    Reply
  25. 星空体育

    you’re truly a just right webmaster. The web site loading velocity is
    incredible. It sort of feels that you’re doing any distinctive trick.
    Furthermore, The contents are masterpiece. you’ve performed a fantastic task on this topic!

    Reply
  26. kasyno online szybkie wypłaty

    Kasyno Honorarium bez Depozytu za Rejestracje to jedna z najbardziej popularnych
    conformation promocji oferowanych przez legalne platformy hazardowe online.
    Tego typu token of gratefulness pozwala nowym uzytkownikom rozpoczac gre bez koniecznosci
    wplacania wlasnych srodkow na konto. Wystarczy zazwyczaj zalozenie konta oraz spelnienie okreslonych warunkow regulaminowych, aby
    otrzymac darmowe srodki lub darmowe obroty na wybranych automatach.
    Dla wielu graczy jest to atrakcyjna mozliwosc sprawdzenia funkcji kasyna bez ponoszenia dodatkowych kosztow.

    Reply
  27. 交換用フィルター

    Hello there! This is my 1st comment here so I just wanted to give a quick shout
    out and tell you I really enjoy reading your posts. Can you suggest
    any other blogs/websites/forums that deal with the same topics?

    Thanks a lot!

    Reply
  28. xingkong

    Hi there to every body, it’s my first pay a visit of this webpage; this blog contains remarkable and in fact excellent information in support of readers.

    Reply
  29. 888starz_nwoa

    بصراحة أنا بقالي حوالي أربع شهور بلعب على المنصة دي من الموبايل، وحبيت أشارككم رأيي علشان كتير من الشباب بيسألوا عن موضوع 888starz app. أكتر حاجة حبيتها إن المكتبة كبيرة جدًا، فيه حوالي أكتر من 2500 لعبة سلوتس تقريبًا، ومش كلها حشو زي بعض المواقع التانية.

    شركات الاستوديوهات ناس محترمين زي براجماتيك وبلاي إن جو. أنا بحب Gates of Olympus وSweet Bonanza، وأحيانًا بلف على Book of Dead. اللي مبيحبش السلوتس فيه قسم الديلر المباشر من Evolution بكروبيهات حقيقيين، وCrazy Time وروليت مباشر ممتعة فعلًا.

    بالنسبة للبونص كويس: أول إيداع بياخد مضاعفة 100% ومعاه لفات مجانية، وفيه no deposit لو بتحب تجرب الأول. بس خليك واخد بالك من الـwagering اللي حوالي أربعين مرة — دي حاجة كتير بينسوها. لو عايز تعرف تفاصيل التنزيل شوفها عند [url=https://readtheedit.com]888starz apk[/url] قبل ما تسجّل.

    حاجة عجبتني إن خيارات السحب والإيداع متنوعة: فيزا وماستركارد، وسكريل ونتلر، وكمان عملات رقمية زي البيتكوين. السحب أسرع مع الكريبتو صراحة، مش زي مواقع بتماطل أسبوع. التسجيل نفسه سهل وسريع، والحد الأدنى للإيداع مش مبالغ فيه.

    النقطة الوحيدة اللي زعلتني إن السابورت أحيانًا بيرد ببطء، ومرة استنيت شوية على الشات. غير كده تحميل التطبيق للأندرويد بيطلب إعدادات يدوية شوية، مش صعبة بس تحتاج انتباه. 888starz apk شغال حلو على الموبايل والتحديث بيظبط المشاكل أول بأول.

    بالنسبة لي كلاعب مصري أنا مبسوط أكتر مما توقعت، والتطبيق بقى أساسي على موبايلي. الترخيص موجود ومعلن، وده حاجة مهمة وانت بتحط فلوسك. لو حد جرّبه يشاركنا.

    Reply

Leave a Reply

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