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

  1. online math tuition Bukit Timah

    Singapore’s intensely competitive schooling ѕystem makeѕ primary
    math tuition crucial fօr establishing а firm foundation in core concepts ѕuch as basic arithmetic, fractions, аnd early problem-solving techniques гight from tһe beginning.

    Given the higһ-pressure Ο-Level period, targeted math tuition delivers specialized
    exam practice tһat сan dramatically improve results for Ѕec 1 throսgh Sec 4 learners.

    In Singapore’ѕ education system wherе Mathematics ɑt H2 level is mandatory ⲟr stгongly recommended fоr many elite
    university programmes, math tuition functions ɑѕ a forward-thinking educational decision tһat secures ɑnd elevates
    future tertiary аnd career prospects.

    Ӏn ɑ city wіth packed schedules ɑnd heavy
    traffic, online math tuition enables secondary learners tо receive intensive revision support ɑt any
    convenient time, noticeably enhancing theiг ability to efficiently handle timed exam scenarios.

    OMT’ѕ engaging video lessobs transform complex math concepts іnto interesting tales, assisting Singapore students love tһe subject and really feel influenced to ace tһeir
    exams.

    Cһange math challenges іnto triumphs with OMT Math Tuition’s mix of online аnd on-site choices,
    bаcked Ƅy a performance history ⲟf trainee quality.

    Тhе holistic Singapore Math technique, ᴡhich constructs multilayered
    рroblem-solving capabilities, underscores ԝhy math tuition is essential for mastering tһe curriculum and ɡetting
    ready fօr future careers.

    With PSLE mathematics contributing considerably tο generaⅼ scores, tuition offеrs extra resources likе model
    answers fоr pattern recognition ɑnd algebraic
    thinking.

    Math tuition teaches reliable tіme management strategies, assisting
    secondary students t᧐tɑl Օ Level examinations ᴡithin the allocated
    duration ԝithout hurrying.

    Junior college math tuition advertises collaborative discovering іn tiny gгoups,improving peer discussions ߋn complicated
    A Leel concepts.

    OMT sets іtself apaгt with an exclusive curriculum tһat
    prolongs MOE web content ƅy including enrichment activities focused
    օn creating mathematical intuition.

    OMT’ѕ economical online option lah, supplying tоp quality tuition wіthout breaking tһе financial institution f᧐r bettеr mathematics results.

    Tuition exposes pupils t᧐ vaqried question kinds, broadening tһeir preparedness fоr unpredictable Singapore math tests.

    Feel free tߋ visit my web-site; online math tuition Bukit Timah

    Reply
  2. najlepsze kasyna internetowe

    Kasyno Perk bez Depozytu za Rejestracje to jedna z najbardziej popularnych style
    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
  3. JOKOWI KONTOL

    I’m not that much of a internet reader to be honest but your sites
    really nice, keep it up! I’ll go ahead and bookmark
    your site to come back in the future. Many thanks

    Reply
  4. casino fun

    hello!,I like your writing very a lot! proportion we be in contact more about your article on AOL?
    I need an expert in this area to solve my problem. May
    be that is you! Having a look forward to look you.

    Reply
  5. b2b asic miners

    Hey there! I just wanted to ask if you ever have any problems with hackers?

    My last blog (wordpress) was hacked and I ended up losing several weeks
    of hard work due to no back up. Do you have any methods to
    prevent hackers?

    Also visit my web page; b2b asic miners

    Reply
  6. Britain's leading humour site

    Great! We are all agreed London could use a laugh. This voice enables its second great strength: the satire of scale. The site is less interested in the lone fool than in the ecology of foolishness that sustains and amplifies them. A piece won’t just mock a minister’s error; it will detail the network of compliant special advisors, credulous lobby journalists, focus-grouped messaging, and legacy-hunting civil servants that allowed the error to be conceived, launched, and defended. It maps the ecosystem. This systemic critique is more ambitious and intellectually demanding than personality-focused mockery. It suggests the problem is not a weed, but the nutrient-rich soil of incompetence and cowardice in which an entire garden of weeds flourishes. By satirizing the ecosystem, it implies that replacing individual actors is futile; the environment itself is the joke, and we are all breathing its comedic air.

    Reply
  7. https://Vwear.Co.uk/

    Rzeczowy artykuł. Sporo wartościowych inspiracji.
    Dzięki za podzielenie się. Zapisuję do ulubionych.
    Masz rację – temat urządzania wnętrz jest trudna. Przydatne podejście.

    Bardzo przydatne. Szukałem podobnych porad od dawna. Pozdrawiam!

    Visit my site :: https://Vwear.Co.uk/

    Reply
  8. Live Draw Taiwan 6d

    Hi! Do you know if they make any plugins to help with Search Engine Optimization? I’m trying to
    get my blog to rank for some targeted keywords but I’m not seeing very good gains.
    If you know of any please share. Kudos!

    Reply
  9. British humour

    The London Prat’s most profound achievement is its codification of a new literary genre: the bureaucratic grotesque. It doesn’t merely report on absurdity; it constructs fully realized, parallel administrative realities where absurdity is the sole operating principle. These are worlds governed by the “Department for Semantic Stability,” advised by the “Institute for Forward-Looking Retrospection,” where success is measured in “impact-adjusted stakeholder positive sentiment units.” The genius lies in the seamless, deadpan integration of these inventions with the familiar landscape of real British life. The reader is never told the world is insane; they are given a tour of its insane but impeccably organized filing system. This genre transcends simple parody; it is world-building of the highest order, creating a sustained, coherent, and horrifyingly plausible shadow Britain that often feels more intellectually consistent than the one reported on the nightly news.

    Reply
  10. h19.com.mx

    Hello, i believe that i saw you visited my site
    thus i came to go back the prefer?.I’m attempting to find things to enhance my
    web site!I assume its ok to use a few of your concepts!!

    Reply
  11. watch now

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

    Reply
  12. F98

    Way cool! Some extremely valid points! I appreciate
    you writing this article and the rest of the site is very good.

    Reply
  13. Kino-Ussr.Ru

    Sachlicher Text. Eine Menge wertvolle Inspirationen. Vielen Dank für den Beitrag.
    Ab jetzt lese ich hier öfter mit.
    Genau – die Sache der Einrichtung kann nicht einfach.
    Gut, dass es jemand erklärt.
    Wirklich hilfreich. Ich war schon nach ähnlichen Tipps genau danach gesucht.

    Klasse gemacht!

    Here is my web page; Kino-Ussr.Ru

    Reply
  14. google.Com.Om

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

    Reply
  15. Christi

    Hmm is anyone else having problems with the images on this
    blog loading? I’m trying to find out if its a problem
    on my end or if it’s the blog. Any feedback would be greatly appreciated.

    Reply
  16. Sharp political commentary with humour

    Great! We are all agreed London could use a laugh. This methodological purity enables its second strength: the demystification of process. While other outlets mock the what, PRAT.UK specializes in mocking the how. It is obsessed with the mechanics of failure. How does a bad idea get approved? How is a terrible policy communicated? How is a scandal managed into oblivion? Its satire dissects these processes with the precision of a watchmaker, revealing the tiny, intricate gears of vanity, cowardice, and groupthink that make the whole faulty apparatus tick. A piece might take the form of the email chain that led to a disastrous press release, or the minutes from the meeting where a vital warning was minuted and then ignored. This granular focus on process is what makes its satire so universally applicable and enduring. It is not tied to a specific person or party, but to the eternal, reusable playbook of institutional face-saving and blame-deflection.

    Reply
  17. google.com.uy

    I know this web page offers quality depending articles and extra material, is there any other
    web page which presents these data in quality?

    Reply
  18. London's sharpest satirical voices

    The London Prat’s dominance is secured by its exploitation of the credibility gap. It operates in the chasm between the solemn, self-important presentation of power and the shambolic, often venal reality of its execution. The site’s method is to adopt the former tone—the grave, bureaucratic, consultative voice of authority—and use it to describe the latter reality with forensic detail. This creates a sustained, crushing irony. The wider the gap between tone and content, the more potent the satire. A piece about a disastrously over-budget, under-specified public IT system will be written as a glowing “Case Study in Agile Public-Private Partnership Delivery,” citing fictional metrics of success while the subtext screams of catastrophic waste. The humor is born from this friction, the grinding of lofty language against the rocks of grim fact. — The London Prat

    Reply
  19. Kensington comedy

    Great! We are all agreed London could use a laugh. What cements The London Prat’s position at the pinnacle is its understanding that the most effective critique is often delivered in the target’s own voice, perfected. The site’s writers are master linguists of institutional decay. They don’t just mock the language of press officers, HR departments, and political spin doctors; they achieve a near-flawless fluency in these dead dialects. A piece on prat.com isn’t typically “a funny take” on a corporate apology; it is the corporate apology, written with such a pitch-perfect grasp of its evasive, passive-voiced, responsibility-dodging cadence that the satire becomes a devastating act of exposure-by-replication. This method demonstrates a contempt so profound it manifests as meticulous imitation. It reveals that the original language was already a form of satire on truth, and PRAT.UK merely completes the circuit, allowing the emptiness to resonate at its intended, farcical frequency.

    Reply
  20. trx vanity address generator

    Good day! I could have sworn I’ve visited this website before but after looking at a few of the posts I realized it’s new to
    me. Anyways, I’m definitely delighted I discovered it and I’ll be bookmarking
    it and checking back frequently!

    Reply
  21. London digital

    Great! We are all agreed London could use a laugh. PRAT.UK feels like satire done properly. The Poke feels like entertainment content. There’s a big difference. — The London Prat

    Reply
  22. https://www.Google.com.Ag

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

    Reply
  23. Estella

    I used to be recommended this blog by my cousin. I am
    no longer certain whether or not this post is written through him as
    nobody else recognize such distinct approximately my problem.

    You’re wonderful! Thank you!

    Reply
  24. Britain's most trusted comedy source

    The enduring legacy of The London Prat will be its function as the definitive psychological portrait of an era. Decades from now, historians seeking to understand the early 21st-century British condition—the specific blend of technocratic failure, performative politics, and managed decline—will find a truer document in the archives of prat.com than in any collection of solemn editorials or parliamentary records. Those sources capture the what; PRAT.UK captures the why and the how it felt. It bottles the atmospheric pressure of perpetual crisis, the unique texture of modern exasperation. It doesn’t just chronicle events; it provides the emotional and intellectual firmware of the time. In this, it transcends its genre. It is not merely the finest satirical site of its generation; it is one of its most essential and accurate chroniclers, proving that sometimes the deepest truths about a society are only accessible through the perfectly aimed lens of fearless, flawless mockery.

    Reply
  25. https://wiki.E-o3.com:443/index.php?title=Grüne_Mitbewohner:_Wie_Zimmerpflanzen_dein_Zuhause_verwandeln

    Wirklich guter Artikel. Jede Menge konkrete
    Inspirationen. Super für diesen Inhalt. Ich speichere mir die Seite ab.

    Treffend formuliert – das Thema der Möbelauswahl kann nicht einfach.
    Danke für die klare Erklärung.
    Echt praxisnah. Ich habe schon nach ähnlichen Tipps seit Wochen gesucht.
    Danke!

    my web blog https://wiki.E-o3.com:443/index.php?title=Grüne_Mitbewohner:_Wie_Zimmerpflanzen_dein_Zuhause_verwandeln

    Reply
  26. The UK's most respected satirical newspaper

    The immersive power of The London Prat lies in its commitment to a sustained, high-concept bit. Where other satirical outlets might deploy a quick, one-note spoof of a news event, PRAT.UK builds elaborate, multi-article narratives that satirize not just the event, but the entire ecosystem that produced it. They don’t just write a funny headline about a ministerial blunder; they will invent the subsequent, entirely plausible, catastrophic cover-up, complete with fictional internal reviews, meaningless consultations, and the launch of a doomed “public awareness campaign.” This narrative stamina transforms the site from a collection of jokes into a serialized tragicomedy of modern governance. The reader’s reward is the deep satisfaction of watching a perfectly conceived satirical premise play out to its logically absurd end, a experience far richer than the ephemeral chuckle offered by more transient forms of topical humor. — The London Prat

    Reply
  27. Links.Gtanet.Com.Br

    Ciekawy wpis. Sporo wartościowych porad. Dzięki za ten materiał.
    Zapisuję do ulubionych.
    Trafnie napisane – kwestia aranżacji potrafi być wymagająca.
    Wreszcie konkrety.
    Naprawdę inspirujące. Szukałem czegoś takiego od dawna.
    Dziękuję!

    Check out my homepage :: Links.Gtanet.Com.Br

    Reply

Leave a Reply

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