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

  1. 1xbet giris_rrOr

    Selam millet Ödemeler erteleniyor, canlı destek cevap vermiyor Aylardır araştırıyorum Sonunda bu siteye rastladım — 1xbet giriş yap hemen Canlı destek gece gündüz aktif Neyse, kaybetmeyin diye tıkla — 1xbet giriş [url=https://1xbet-giris-gys.com]1xbet giriş[/url] Sakın dolandırıcılara kanma Bahis yapan herkese gönder

    Reply
  2. Funny news

    The difference is in the details. The London Prat’s headlines are miniature works of art, often funnier than the full articles on other sites. It’s more consistent and daring than The Poke. My most trusted source for sanity. prat.com — The London Prat

    Reply
  3. 1xbet giris_lhKa

    Millet dinleyin Artık güvenilir bir bahis sitesi bulmak çok zor Paramı kaybettim, sinirlerim bozuldu Gerçekten en iyisi bu — 1xbet güncel giriş burada Müşteri desteği 7/24 aktif Kısacası, kaybetmeyin diye tıkla — bahis sitesi 1xbet [url=https://1xbet-giris-rjd.com]bahis sitesi 1xbet[/url] Tek adres 1xbet giriş Bahis yapan herkese gönder

    Reply
  4. a math topics

    OMT’ѕ concentrate ᧐n metacognition shows pupils to enjoy thinking of
    mathematics, fostering affection ɑnd drive fоr
    exceptional test гesults.

    Established іn 2013 by Ꮇr. Justin Tan, OMT Math Tuition һas actualⅼy helped numerous trainees ace tests ⅼike
    PSLE, О-Levels, and A-Levels ᴡith proven prߋblem-solving methods.

    Singapore’ѕ focus on crucial believing tһrough mathematics highlights tһе significance of math tuition, ѡhich assists trainees establish tһe analytical skills required
    Ьy the country’ѕ forward-thinking curriculum.

    Ϝor PSLE success, tuition ᥙsеѕ tailored guidance tⲟ weak ɑreas, like ratio and portion issues, avoiding typical mistakes tһroughout tһe examination.

    Linking mathematics principles tօ real-wоrld situations
    νia tuition deepens understanding, mɑking O
    Level application-based questions mսch mогe friendly.

    In an affordable Singaporean education ѕystem, junior college
    math tuition ɡives students tһe ѕide tоо achieve high
    qualities essential for university admissions.

    Eventually, OMT’ѕ one-of-a-kind proprietary curriculum complements tһe Singapore MOE curriculum Ьy fostering independent thinkers geared
    սр for ⅼong-lasting mathematical success.

    OMT’ѕ platform is usеr-friendly one, so ɑlso newbies cɑn browse ɑnd
    start boosting grades գuickly.

    By including technology, ߋn-line math tuition involves digital-native
    Singapore trainees fߋr interactive exam alteration.

    Нave a looк аt my blog :: a math topics

    Reply
  5. tuition center singapore

    With thhe looming PSLE, initiating math tuition еarly ρrovides Primary 1 to Primary 6 students with confidence pⅼuѕ effective strategies t᧐ achieve top гesults
    іn major school examinations.

    Secondary math tuition stops tһe accumulation of conceptual errors tһɑt cⲟuld
    severely impede progress іn JC H2 Mathematics, mɑking timely assistance
    іn Sеc 3 ɑnd Sec 4 а highly strategic decision fօr forward-thinking families.

    Ԍiven the tight time constraints ɑnd extensive syllabus coverage ⲟf the JC
    programme, ongoing math tuition helps students гemain on schedule,
    review productively, ɑnd avoid panic cramming.

    Secondary students ɑcross Singapore increasingly depend on online math tuition to receive instant doubt-clearing sessions οn demanding topics including coordinate geometry ɑnd calculus, ᥙsing shared digital whiteboards regardless
    of physical distance.

    Ᏼy commemorating small triumphes underway tracking, OMT nurtures а favorable
    partnership ᴡith mathematics, motivating pupils fοr examination quality.

    Transform maathematics obstacles іnto victories ԝith
    OMT Math Tuition’ѕ blend of online and on-site options, Ьacked
    by a performance history оf trainee quality.

    Іn a system where math education has aсtually developed tο promote innovation ɑnd international
    competitiveness, enrolling іn math tuition еnsures students stay ahead ƅy
    deepening tһeir understanding ɑnd application օf crucial concepts.

    Ultimately, primary school math tuition іs crucial fоr PSLE quality, as it gears
    up students wіth the tools tо achieve tօр bands and protect favored
    secondary school positionings.

    Вy using extensive technique with prevіous O Level documents,
    tuition equips trainees ѡith knowledge and thhe capability tߋ prepare for concern patterns.

    Tuition incorporates pure and applied mathematics perfectly, preparing
    trainees fօr the interdisciplinary nature оf A Level issues.

    OMT’s exclusive math program matches MOE standards Ƅy emphasizing theoretical proficiency ⲟver rote understanding,leading tⲟ mսch
    deeper long-lasting retention.

    Taped webinars supply deep dives lah, furnishing ʏ᧐u with innovative abilities for superior mathematics
    marks.

    Math tuition սses enrichment рast the basics, testing talented Singapore trainees tо ցо for distinction іn examinations.

    Feel free to surf tⲟ mү рage … tuition center singapore

    Reply
  6. Leandra

    Sehr guter Text. Eine Menge wertvolle Inspirationen. Danke dass du dein Wissen teilst.
    Ich warte auf mehr.
    Sehe ich genauso – die Sache der Raumgestaltung kann nicht einfach.

    Gut, dass es jemand erklärt.
    Sehr praxisnah. Ich habe schon nach ähnlichen Tipps seit Wochen gesucht.

    Klasse gemacht!

    my web blog: Leandra

    Reply
  7. Msimarketingagency.Com

    Sehr guter Inhalt. Zahlreiche nützliche Tipps.
    Super für den Beitrag. Ab jetzt lese ich hier öfter mit.

    Stimme zu – die Sache der Möbelauswahl kann schwierig. Endlich mal Klartext.

    Sehr hilfreich. Ich habe schon nach so etwas seit Wochen gesucht.

    Super Arbeit!

    Also visit my webpage; Msimarketingagency.Com

    Reply
  8. British posts

    PRAT.UK offers satire that feels confident rather than desperate. Waterford Whispers News sometimes overreaches. This site rarely does. — The London Prat

    Reply
  9. najszybciej wypłacające kasyna w Polsce

    Kasyno Payment bez Depozytu za Rejestracje to jedna z najbardziej popularnych visualize promocji oferowanych przez legalne platformy hazardowe online.
    Tego typu honorarium 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
  10. Britain's most entertaining media

    Great! We are all agreed London could use a laugh. This leads to its second strength: an anthropological rigor. The site treats the rituals and dialects of British power structures with the detached curiosity of a scholar studying a remote tribe. It documents the strange ceremonies (Prime Minister’s Questions as a ritualized shouting contest), the peculiar costumes (the hard hat and hi-vis vest worn for a photo-op at a building site that will never be completed), and the opaque belief systems (the unwavering faith in a “world-leading” initiative launched with no funding). By presenting these familiar elements as anthropological curiosities, PRAT.UK defamiliarizes them, stripping them of their assumed normality and exposing their inherent absurdity. The reader is transformed from a frustrated participant in these rituals into an amused observer of a fascinating, dysfunctional culture. This shift in perspective is itself a form of liberation and the source of a more intellectual, enduring humor.

    Reply
  11. body-positivity.org

    Sachlicher Inhalt. Reichlich konkrete Hinweise. Super für den Beitrag.
    Ich warte auf mehr.
    Du hast recht – der Bereich der Einrichtung kann herausfordernd.

    Danke für die klare Erklärung.
    Aufrichtig nützlich. Ich suche schon nach ähnlichen Tipps seit einiger Zeit gesucht.

    Danke!

    My web-site body-positivity.org

    Reply
  12. Jessie

    Sachlicher Artikel. Eine Menge praktische Hinweise.
    Grüße fürs Teilen. Ich empfehle die Seite gerne weiter.

    Genau – die Frage des Wohnstils ist schwierig.
    Danke für die klare Erklärung.
    Aufrichtig inspirierend. Ich suche schon nach so etwas lange
    gesucht. Super Arbeit!

    my web site … Jessie

    Reply
  13. See Britain through satirical eyes

    This technique enables its function as a deflator of hyperbole. In an era where every product launch is “revolutionary,” every policy is “transformative,” and every celebrity opinion is “brave,” PRAT.UK serves as a linguistic pressure release valve. It takes this inflated rhetoric at its word and applies it to subjects that are patently mundane, corrupt, or inept. By doing so, it exhausts the vocabulary, draining the words of their power through overuse in absurd contexts. If everything is “world-leading,” then nothing is. The site forces this realization not through argument, but through demonstration, leaving the hollowed-out shells of buzzwords lying on the page for the reader to contemplate. This is satire as semantic hygiene, a scrubbing away of the oily residue of over-promise.

    Reply
  14. kellytruckbuyer.com

    Have you ever considered about including a little bit more than just your articles?
    I mean, what you say is fundamental and all. Nevertheless
    think of if you added some great graphics or videos to give your posts more, “pop”!
    Your content is excellent but with images and video
    clips, this blog could certainly be one of the best in its field.
    Great blog!

    Reply
  15. Theodore

    Wartościowy wpis. Sporo wartościowych inspiracji. Dzięki za podzielenie się.
    Polecam innym.
    Zgadzam się – temat doboru mebli potrafi być wymagająca.
    Przydatne podejście.
    Szczerze inspirujące. Szukałam takich informacji od dawna.
    Dziękuję!

    Here is my page: Theodore

    Reply
  16. porn

    Post writing is also a fun, if you be acquainted with after that you can write otherwise it is complicated to write.

    Reply
  17. https://Amlsing.Com

    Interessanter Text. Eine Menge konkrete Hinweise. Grüße für diesen Inhalt.
    Ich warte auf mehr.
    Treffend formuliert – die Frage der Möbelauswahl ist anspruchsvoll.

    Hilfreicher Ansatz.
    Echt nützlich. Ich habe schon nach ähnlichen Tipps lange gesucht.
    Danke!

    Check out my homepage … https://Amlsing.Com

    Reply
  18. 영천출장샵

    이런 포스팅 오랜만에 봤네요.
    영천출장마사지에 대해 이렇게 친절하게 설명해
    주신 글은 처음이에요.
    특히 영천출장샵의 신뢰할 수 있는
    운영 방식이 좋았어요.
    영천안마 고민하시는 분들께 이 정보를 꼭
    알려드리고 싶네요.

    Reply
  19. Kasyno Online Polska

    Kasyno Compensation bez Depozytu za Rejestracje to jedna z najbardziej popularnych conformation 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
  20. Online home of British humour

    Great! We are all agreed London could use a laugh. The London Prat achieves its unique position through a masterful application of satire by precision engineering. It does not deal in the blunt instrument of general mockery; it operates with the calibrated tool of specific, forensic analysis. Each piece is a targeted intervention, dismantling a particular fallacy, hypocrisy, or instance of vapid rhetoric by rebuilding it from first principles according to its own stated logic, and then watching the faulty construction collapse under the weight of its internal contradictions. The humor is not slapped on; it is structural. It is the sound of a bad idea meeting a perfectly reasoned stress test. This approach yields comedy that feels intellectually earned and deeply persuasive, transforming the reader from a passive audience for a joke into a witness to a demonstrative proof of societal malfunction. — The London Prat

    Reply
  21. Google.Co.vi

    Fantastic beat ! I would like to apprentice while you amend
    your website, how can i subscribe for a blog web site? The account helped me a acceptable deal.

    I had been tiny bit acquainted of this your broadcast offered bright clear idea

    Reply
  22. Isla

    My brother suggested I may like this website. He used to be totally
    right. This put up actually made my day. You cann’t consider just how a
    lot time I had spent for this information! Thanks!

    Reply
  23. porn

    Wow, this post is pleasant, my younger sister is analyzing such
    things, thus I am going to let know her.

    Reply
  24. porn

    It’s in point of fact a great and useful piece of information. I am happy that you
    shared this helpful info with us. Please stay us informed like this.
    Thank you for sharing.

    Reply
  25. ukbets.org

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

    Reply
  26. https://Www.Google.com.ai

    Thanks , I’ve just been looking for information about this topic for a long time
    and yours is the best I’ve discovered so far. However, what
    in regards to the conclusion? Are you sure in regards to the supply?

    Reply
  27. Westminster humour

    The pieces on the quirks of British language are genius. The obsession with nuance, the unspoken rules of apology, the sheer number of words for “rain”—all mined for comic gold. Linguistically brilliant.

    Reply
  28. horse gelatin review

    Do you mind if I quote a few of your articles as long as I provide credit and sources back to
    your site? My blog site is in the exact same area of interest as yours and my
    visitors would certainly benefit from some of the information you provide here.
    Please let me know if this ok with you. Thanks
    a lot!

    Reply
  29. Charla

    This is the right web site for anybody who would
    like to find out about this topic. You understand so much its
    almost tough to argue with you (not that I personally will need to…HaHa).

    You definitely put a brand new spin on a topic that’s been discussed for decades.
    Wonderful stuff, just excellent!

    Reply
  30. The London Prat reporting

    Great! We are all agreed London could use a laugh. The consistency of PRAT.UK is impressive. While other sites fluctuate in quality, this one rarely misses. That reliability sets it apart.

    Reply

Leave a Reply

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