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

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

  1. Brazilian wealth building

    Thanks for your personal marvelous posting! I quite enjoyed reading it, you might be a great author.
    I will ensure that I bookmark your blog and will often come back sometime soon. I want to encourage you to ultimately continue your great
    work, have a nice day!

    Reply
  2. beruangjitu

    Aw, this was an extremely nice post. Finding the time and actual effort to make a great article… but what can I say… I
    put things off a whole lot and never manage to get anything
    done.

    Reply
  3. zelensky22

    Greate post. Keep writing such kind of info on your blog. Im really impressed by your site.

    Hi there, You have done a fantastic job. I’ll certainly
    digg it and personally suggest to my friends. I’m confident they will be benefited from this
    web site.

    My web-site … zelensky22

    Reply
  4. Ricky casino

    Thank you for some other informative site.
    Where else could I am getting that type of information written in such
    an ideal method? I have a undertaking that I am just now operating on,
    and I have been on the look out for such info.

    Reply
  5. zelensky11

    Thanks for finally writing about > Use a simple script to achieve powder pile | Maya nParticle简单脚本实现粒子堆叠 | Asher.GG zelensky11

    Reply
  6. 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 trusted 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
  7. Kraken ссылка tor Кракен надежная для входа

    Почему пользователи выбирают площадку
    KRAKEN?
    Маркетплейс KRAKEN заслужил доверие многочисленной аудитории благодаря сочетанию
    ключевых факторов. Во-первых, это широкий
    и разнообразный ассортимент, представленный сотнями
    продавцов. Во-вторых, интуитивно понятный интерфейс KRAKEN, который упрощает навигацию, поиск товаров и управление
    заказами даже для новых пользователей.
    В-третьих, продуманная система безопасных транзакций, включающая механизмы разрешения споров (диспутов) и возможность
    использования условного депонирования, что минимизирует риски для обеих сторон сделки.

    На KRAKEN функциональность сочетается с внимательным отношением к безопасности клиентов, что делает процесс покупок более предсказуемым, защищенным и, как следствие, популярным среди пользователей, ценящих анонимность и надежность.

    Reply
  8. dulur tekno

    Postingan yang sangat bagus! Informasi ini sangat membantu bagi saya yang
    sedang mencari referensi tentang perkembangan gadget. Memang tidak
    salah kalau kita harus sering membaca dari berbagai sumber tepercaya seperti **Dulur Tekno** untuk menambah wawasan digital.
    Terima kasih sudah berbagi! Kunjungi Dulur Tekno

    Reply
  9. Lucia

    Undeniably believe that which you stated. Your favorite reason seemed to be on the
    internet the easiest thing to be aware of. I say to you,
    I definitely get irked while people think about worries that they plainly do
    not know about. You managed to hit the nail upon the top and also defined out the whole thing without having side effect , people could take a signal.
    Will likely be back to get more. Thanks

    Reply
  10. Thao

    Hilfreicher Artikel. Reichlich hilfreiche Inspirationen. Großes Lob fürs Teilen. Ab jetzt lese ich hier öfter mit.

    Volle Zustimmung – die Sache der Wohnungsgestaltung wird oft herausfordernd.
    Gut, dass es jemand erklärt.
    Sehr inspirierend. Ich war schon nach solchen Informationen genau danach gesucht.
    Klasse gemacht!

    my homepage – Thao

    Reply
  11. gái xinh sex

    I was curious if you ever considered changing the structure of your blog?
    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 one or
    2 images. Maybe you could space it out better?

    Reply
  12. 비닉스 가격

    Hello, Neat post. There’s an issue with your website in internet explorer, could
    test this? IE nonetheless is the marketplace leader and a huge component of people will
    omit your excellent writing due to this problem.

    Reply
  13. comment-585458

    Howdy I am so happy I found your weblog, I really found you by error, while I was browsing on Aol for something
    else, Anyways I am here now and would just like to say many thanks for a incredible post and a all round enjoyable blog (I also love the theme/design),
    I don’t have time to go through it all at the minute
    but I have book-marked it and also included your RSS feeds,
    so when I have time I will be back to read more, Please
    do keep up the awesome job.

    Reply
  14. buzdolabı tamiri

    Wonderful goods from you, man. I’ve understand your
    stuff previous to and you are just too wonderful. I really like what you have acquired here, certainly like what you’re stating
    and the way in which you say it. You make it entertaining
    and you still care for to keep it sensible. I can’t wait to read far more from you.
    This is actually a great web site.

    Reply
  15. 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 trusted 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
  16. UG88 Thailand | คาสิโนออนไลน์ระดับพรีเมียมและทางเลือกเดิมพันที่ดีที่สุด

    ยกระดับประสบการณ์การเดิมพันที่ UG88 Thailand พบกับคาสิโนออนไลน์ที่น่าเชื่อถือที่สุด พร้อมระบบฝาก-ถอนออโต้ที่รวดเร็วและราคาต่อรองที่ดีที่สุดในไทย

    Reply
  17. 2lw.天堂.life

    Wirklich guter Artikel. Reichlich konkrete Inspirationen.
    Grüße für die Mühe. Ich warte auf mehr.
    Volle Zustimmung – die Frage des Wohnstils wird oft nicht einfach.
    Gut, dass es jemand erklärt.
    Sehr nützlich. Ich habe schon nach ähnlichen Tipps seit Wochen gesucht.
    Viele Grüße!

    Visit my site … 2lw.天堂.life

    Reply
  18. viagra indonesia

    Artikel yang sangat menarik dan informatif. Banyak pengguna di Indonesia mencari informasi terpercaya tentang
    viagra indonesia dan kesehatan pria. Konten seperti ini
    sangat membantu pembaca memahami penggunaan yang aman dan efektif.

    Terima kasih atas artikel yang bermanfaat ini. Topik viagra indonesia memang banyak dicari saat
    ini, terutama bagi mereka yang ingin mendapatkan informasi kesehatan pria
    secara aman dan tepat.

    Konten yang bagus dan mudah dipahami. Informasi mengenai viagra indonesia sangat relevan dan membantu banyak orang mendapatkan edukasi yang
    benar tentang kesehatan pria.

    Reply
  19. viagra indonesia

    Hi there, I do believe your website could be having browser compatibility problems.
    Whenever I take a look at your web site in Safari, it looks
    fine however when opening in Internet Explorer, it has
    some overlapping issues. I simply wanted to give you a quick heads up!
    Apart from that, great blog!

    Reply
  20. 18+ chatruletka

    Greetings! This is my first visit to your blog!

    We are a collection of volunteers and starting
    a new initiative in a community in the same niche. Your blog provided us
    useful information to work on. You have done a wonderful job!

    Reply
  21. 비아그라 구매

    You have made some good points there. I looked on the internet for additional information about the issue and found
    most people will go along with your views on this site.

    Reply
  22. 링크모음

    My family members always say that I am killing my time here at net,
    except I know I am getting knowledge all the time by reading thes fastidious posts.

    Reply
  23. buy

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

    Reply
  24. 비아그라 구매

    Heya excellent blog! Does running a blog like this require a lot of work?
    I’ve no expertise in programming however I had been hoping to start my own blog soon. Anyway, should you
    have any suggestions or techniques for new blog owners please share.
    I understand this is off subject but I simply wanted to ask.
    Thanks!

    Reply
  25. cheap

    You can certainly see your skills in the article
    you write. The arena hopes for even more passionate writers like you who are not afraid to mention how they believe.
    All the time follow your heart.

    Reply
  26. SITUS SCAM

    What’s up, this weekend is pleasant in favor of me, as this occasion i am
    reading this great informative post here at my house.

    Reply
  27. Doctiplus online doctors

    Great beat ! I would like to apprentice while you amend your site, how can i subscribe for a blog site?
    The account helped me a acceptable deal. I had been a little bit acquainted of this your broadcast offered bright clear concept

    Reply
  28. Doctiplus online doctors

    I have been browsing online more than three hours today,
    yet I never found any interesting article like yours.
    It’s pretty worth enough for me. In my view, if all webmasters and bloggers made good content as
    you did, the web will be much more useful than ever
    before.

    Reply
  29. Earn money by playing games

    Hi, I do think this is a great site. I stumbledupon it 😉 I am going to revisit yet again since I book-marked it.

    Money and freedom is the best way to change, may you be
    rich and continue to help other people.

    Reply
  30. 다시보기 사이트

    Howdy! I understand this is somewhat off-topic but
    I had to ask. Does managing a well-established blog such as yours
    take a massive amount work? I’m brand new to operating a blog however I do write in my diary every day.

    I’d like to start a blog so I can easily share my experience and feelings online.
    Please let me know if you have any kind of ideas or tips for new aspiring blog owners.

    Thankyou!

    Reply
  31. bandar 89

    Do you have a spam issue on this site; I also am
    a blogger, and I was curious about your situation; we have developed
    some nice procedures and we are looking to swap methods with others, be
    sure to shoot me an e-mail if interested.

    Reply
  32. USA Canada Mexico 2026

    Step right in to your this main headquarters for the
    2026 Football World Cup. Such event, which will be held across three nations, will
    bring together the greatest footballers across the globe as
    they battle for grabbing the supreme cup of international football.
    From the starting signal all the way to the final whistle — enjoy the best odds for
    each game, every group winner, along with any possible titleholder.

    USA Canada Mexico 2026

    Reply

Leave a Reply

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