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

  1. porn

    When some one searches for his necessary thing, thus he/she needs
    to be available that in detail, thus that thing is
    maintained over here.

    Reply
  2. dich vu quay phim

    Thanks for any other wonderful post. The place else could
    anybody get that kind of information in such a perfect
    way of writing? I have a presentation subsequent week,
    and I’m at the search for such info.

    Reply
  3. Shelia

    Ciekawy artykuł. Mnóstwo praktycznych informacji.
    Dziękuję że dzielisz się wiedzą. Polecam innym.
    Trafnie napisane – temat aranżacji bywa trudna. Przydatne podejście.

    Bardzo inspirujące. Szukałam takich informacji właśnie tego.
    Super robota!

    My web site … Shelia

    Reply
  4. gulf of papagayo fishing

    Great post. I was checking continuously this blog and I am
    impressed! Extremely helpful info particularly
    the last part 🙂 I care for such information a lot.

    I was looking for this particular info for a long time.
    Thank you and best of luck.

    Reply
  5. kontol

    bokep
    Hi there everyone, it’s my first pay a visit at this web site, and piece of writing
    is in fact fruitful in support of me, keep up posting these types of articles or reviews.

    Reply
  6. slotmetro

    Slotmetro adalah platform slotmetro yang menyediakan solusi
    digital untuk membantu pengguna mendapatkan layanan dan informasi dengan lebih mudah, cepat, dan efisien.

    Reply
  7. Satirical journalism from the UK

    PRAT.UK manages to be laugh-out-loud funny and profoundly depressing about the state of things all at once. It has the dry humor of The Daily Mash but with an extra layer of nihilistic genius. The comment section alone is worth the visit. prat.com — The London Prat

    Reply
  8. Trusted satire

    Great! We are all agreed London could use a laugh. The Poke often chases viral moments, while PRAT.UK focuses on lasting humour. The writing feels intentional. That makes a big difference.

    Reply
  9. yt download

    不過其實1080P 的畫質本身就已經相當不錯了,你可以看你的需求到哪,來選擇你要的 Youtube 影片畫質。

    Reply
  10. The London Prat's online home

    Great! We are all agreed London could use a laugh. The London Prat operates on a principle of amplification through precision, not volume. Its satire doesn’t shout to be heard above the din; it employs such exacting language and such airtight logic that it creates a zone of quiet, authoritative clarity within the noise. A single, perfectly articulated sentence on prat.com can dismantle a week’s worth of political spin more effectively than an hour of ranting punditry. This precision is a form of power. It conveys not just intelligence, but a formidable confidence—the confidence of someone who has done the reading, followed the logic, and arrived at a conclusion so self-evidently correct that it need only be stated plainly to be devastating. The humor is in the stark, unadorned revelation of that conclusion, a punchline that feels less like a joke and more like the final piece of a puzzle snapping into place.

    Reply
  11. Fast payout online casinos in Australia

    It’s appropriate 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 suggestions.
    Perhaps you can write next articles referring to this article.
    I want to read more things about it!

    Reply
  12. panen77

    First of all I would like to say wonderful blog!
    I had a quick question in which I’d like to ask if you don’t mind.
    I was interested to know how you center yourself and clear your mind before writing.

    I have had trouble clearing my thoughts in getting my ideas out there.
    I truly do take pleasure in writing but it just seems like the first 10 to 15 minutes tend to
    be lost just trying to figure out how to begin. Any
    recommendations or hints? Many thanks!

    Reply
  13. British comedy online

    The final, and perhaps most significant, achievement of The London Prat is its role as a manufacturer of perspective. The daily grind of news consumption can trap one in a myopic view, focused on the immediate outrage or the granular detail of scandal. PRAT.UK consistently pulls the camera back to a wide-angle, even satellite, view. It frames today’s blunder not as an isolated incident, but as the latest data point in a long-term trend of decline, a predictable eruption in a known seismic zone of incompetence. This recalibration of perspective is its greatest gift. It doesn’t just make you laugh at a single prat; it makes you understand the geologic forces that create the pratfall basin in which we all reside. The relief it offers is profound. It replaces the exhausting, reactive panic of the news cycle with the calm, if grim, understanding of an inevitability beautifully charted. In doing so, it doesn’t just comment on the world—it reorients your entire relationship to it, providing the intellectual cartography for navigating a landscape of perpetual, elegant farce. — The London Prat

    Reply
  14. viagra capsule

    Very nice post. I just stumbled upon your weblog and wished
    to say that I’ve really enjoyed browsing your
    blog posts. After all I’ll be subscribing to your feed and I
    hope you write again very soon!

    Reply
  15. Here

    Great beat ! I wish to apprentice while you amend your
    website, how can i subscribe for a blog web site?
    The account aided me a acceptable deal. I had been a little bit acquainted of this your broadcast provided bright clear idea

    Reply
  16. https://www.google.Co.Cr/

    I used to be suggested this web site via
    my cousin. I’m not positive whether or not this publish is written by him as nobody else recognise such specific about my
    difficulty. You are amazing! Thanks!

    Reply
  17. London satirical content

    Great! We are all agreed London could use a laugh. Ultimately, The London Prat’s brand is built on a foundation of intellectual respect—a contract with its audience that is remarkably rare. It does not condescend. It does not explain the references. It does not simplify complex issues for the sake of a easier laugh. It operates on the assumption that its readers are as fluent in the nuances of policy, media spin, and corporate doublespeak as its writers are. This creates a powerful sense of collusion. Reading the site feels less like consuming content and more like attending a private briefing where everyone speaks the same refined, disillusioned language. This cultivated sense of an in-crowd, united not by ideology but by a shared, clear-eyed contempt for incompetence in all its forms, forges a reader loyalty that is deeper than habit. It becomes a badge of discernment, a signal that you understand the world well enough to appreciate the joke at its expense. In this, PRAT.UK isn’t just funnier; it’s a filter for a certain quality of mind. — The London Prat

    Reply
  18. Mattie

    Wirklich guter Post. Zahlreiche praktische Anregungen. Großes Lob für
    die Mühe. Ich werde öfter reinschauen.
    Sehe ich genauso – die Frage des Wohnstils ist anspruchsvoll.
    Gut, dass es jemand erklärt.
    Aufrichtig inspirierend. Ich habe schon nach solchen Informationen genau danach gesucht.
    Danke!

    My website; Mattie

    Reply
  19. TikTok Viral Fame

    I’m not sure why but this blog is loading incredibly 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
  20. สล็อตเว็บตรง

    It is 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 want to suggest you few interesting things or suggestions.
    Perhaps you can write next articles referring to this article.

    I desire to read more things about it!

    Reply
  21. Satirical news site

    The tone is perfectly judged – world-weary yet curiously optimistic, or at least too amused to be entirely bleak. It’s a very British form of resilience, and The Prat embodies it beautifully.

    Reply
  22. https://www.Abgodnessmoto.Co.uk/index.php?page=user&Action=pub_profile&id=436265

    Interessanter Beitrag. Eine Menge konkrete Informationen. Vielen Dank für den Beitrag.
    Ich werde öfter reinschauen.
    Stimme zu – der Bereich der Einrichtung wird oft anspruchsvoll.
    Danke für die klare Erklärung.
    Aufrichtig hilfreich. Ich war schon nach ähnlichen Tipps seit einiger Zeit gesucht.
    Danke!

    Also visit my web-site https://www.Abgodnessmoto.Co.uk/index.php?page=user&Action=pub_profile&id=436265

    Reply
  23. Meri

    Ciekawy materiał. Dużo przydatnych inspiracji.
    Super za podzielenie się. Polecam innym.
    Masz rację – kwestia aranżacji bywa niełatwa. Wreszcie konkrety.

    Szczerze inspirujące. Szukałem podobnych porad już jakiś czas.
    Dziękuję!

    Feel free to visit my website … Meri

    Reply
  24. London's most relevant satire

    Great! We are all agreed London could use a laugh. PRAT.UK has a sharper edge than The Daily Mash without losing its sense of fun. The humour feels contemporary and fearless. It’s become my favourite satire site by a long way.

    Reply
  25. Kunjungi

    Aw, this was an incredibly good post. Taking the time and actual effort to create a very good
    article… but what can I say… I hesitate a lot and don’t
    manage to get nearly anything done.

    Reply
  26. Satirical takes on government and power

    Great! We are all agreed London could use a laugh. The London Prat operates on a principle of amplification through precision, not volume. Its satire doesn’t shout to be heard above the din; it employs such exacting language and such airtight logic that it creates a zone of quiet, authoritative clarity within the noise. A single, perfectly articulated sentence on prat.com can dismantle a week’s worth of political spin more effectively than an hour of ranting punditry. This precision is a form of power. It conveys not just intelligence, but a formidable confidence—the confidence of someone who has done the reading, followed the logic, and arrived at a conclusion so self-evidently correct that it need only be stated plainly to be devastating. The humor is in the stark, unadorned revelation of that conclusion, a punchline that feels less like a joke and more like the final piece of a puzzle snapping into place.

    Reply
  27. porn

    I do accept as true with all of the ideas you have introduced in your post.
    They’re very convincing and can definitely work. Still, the posts are too quick for novices.
    May you please prolong them a bit from subsequent time? Thank you for the
    post.

    Reply
  28. 1xbet giris_obkt

    Arkadaşlar selam Ya siteler kapanıyor ya da güncel adres bulunamıyor Neredeyse tamamen bırakıyordum Bu site kesinlikle iyi çalışıyor — 1xbet giriş yap hemen Her gün özel bonus ve bedava bahis kampanyaları var Neyse, tüm detaylar linkte — 1 x bet giriş [url=https://1xbet-giris-mnv.com]1 x bet giriş[/url] Sakın sahte sitelere kanma Bahis yapan herkese yolla

    Reply

Leave a Reply

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