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

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

  1. harga emas hari ini Malaysia

    I’m truly enjoying the design and layout of your site.

    It’s a very easy on the eyes which makes it much more pleasant for me to come here and visit more often. Did you hire out a designer to create
    your theme? Outstanding work!

    Reply
  2. 88bbet

    It’s a pity you don’t have a donate button! I’d definitely donate to this
    outstanding blog! I suppose for now i’ll settle for book-marking and
    adding your RSS feed to my Google account. I look forward to new
    updates and will talk about this site with my Facebook group.

    Talk soon!

    Reply
  3. Mavis

    First оf all I want to say excellent blog! I had a quick question in which
    I’d like to aask if you don’t mind. I was curious to know how yyou center yօursеlf and clear youyr thoughts ƅеfore writing.
    I’νe had а diffdicult time cⅼearing mу thoughts in gеtting my thoughts out.
    I trᥙly dо enjoy writing howvеr it jᥙst seems like tһe first
    10 to 15 minutes аre uually loost just trying to figure out how tⲟ begin. Any suggestions or tips?
    Kudos!

    my web blog: ナルシャ 楽天 (Mavis)

    Reply
  4. Legend001.Com

    When someone writes an paragraph he/she keeps the plan of a user in his/her mind that how a user can know
    it. So that’s why this piece of writing is perfect. Thanks!

    Reply
  5. pike industries

    Having read this I believed it was very enlightening.
    I appreciate you finding the time and energy to put this information together.

    I once again find myself spending way too much time
    both reading and posting comments. But so what, it was still worthwhile!

    Reply
  6. tebakskor889.com

    I think this is among the most vital information for me.

    And i’m glad reading your article. But should remark on some general things, The
    site style is wonderful, the articles is really nice : D.
    Good job, cheers

    Reply
  7. Seth

    Hallo, ich bin beim Stöbern hier gelandet und ich möchte sagen, dass das Thema hervorragend beschrieben ist. Ich gestalte gerade meine Wohnung ein und jeder Ratschlag hilft mir weiter. Liebe Grüße in die Runde.
    Wertvoller Beitrag. Ich kann aus eigener Erfahrung sagen, dass die Farbwahl wirklich einen Unterschied macht. Lieber einmal richtig als zweimal.

    Reply
  8. learn more

    Professional property care can help maintain value.

    This applies to commercial spaces where cleanliness matters.

    One example in this field is reinigungs-profies.de.

    Reply
  9. bokep smp

    When I initially commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get several emails with the same comment.

    Is there any way you can remove people from that service?
    Bless you!

    Reply
  10. No deposit bonus casinos

    Hi just wanted to give you a brief heads up and let you know a few of the images aren’t loading correctly.
    I’m not sure why but I think its a linking issue.

    I’ve tried it in two different browsers and both show the same outcome.

    Reply
  11. http://Qiaoxiaojun.vip/home.Php?mod=space&uid=2030061

    Hallo, ich habe nach Informationen zum Einrichten gesucht und ich muss zugeben, dass es hier viele wertvolle Inhalte gibt. Ich selbst bin gerade dabei, mein Haus und solche Tipps sind echt hilfreich. Grüße an die Forengemeinde.
    Wertvoller Beitrag. Meiner Meinung nach die richtige Farbgebung eine enorme Rolle spielt. Lieber einmal richtig als zweimal.

    Reply
  12. work

    I’m Anna, a 35-year-old housewife. For years, my marriage was falling apart.
    We argued constantly. Eventually, I realized we wanted different
    things in life.

    One evening, while relaxing after a stressful day,
    I discovered an online slot. The game featured shining symbols, reward multipliers, and fast-paced action. Every spin felt exciting.

    At first, I played with a small balance. The reels showed cherries, stars, and diamonds.
    Then something changed. A series of lucky hits appeared across
    the screen. The sounds became louder, the animations brighter, and my heart started racing.

    I stared at the screen in shock. One bonus round led
    to another. Multipliers stacked. The winnings kept growing.

    I couldn’t stop smiling. The number on the screen climbed higher and
    higher.

    Then came the moment I will never forget. The biggest win appeared.
    The screen exploded with lights and animations. The total reached
    a six-figure prize.

    I couldn’t process what had happened. For several minutes, I simply stared at the screen. The emotions were overwhelming:
    surprise, excitement, relief, and happiness.

    That win did not magically solve every problem in my life, but
    it gave me a fresh start. Around the same time, I met a kind person.
    More importantly, I realized that happiness comes from healthy relationships.

    Today, I look back on that night as a surprising
    chapter of my life. Life moved on. And while the jackpot was exciting, the
    biggest reward was finding the courage to create a
    life that felt right for me.

    Reply
  13. Http://Sempre-Roma.com

    Grüße euch, ich habe das Forum durchgeblättert und mir ist aufgefallen, dass es hier viele wertvolle Inhalte gibt. Ich selbst renoviere seit kurzem meine Wohnung ein und ich suche nach Inspiration. Liebe Grüße in die Runde.
    Wertvoller Beitrag. Ich kann aus eigener Erfahrung sagen, dass die richtige Farbgebung nicht zu unterschätzen ist. Es lohnt sich, dafür Zeit zu nehmen.

    Reply
  14. gajah138 deposit murah

    bila sedang mencari slots online, saya kerap bermain di Gajah138 Slots lantaran udah biasa sejak dulu.
    depo dan wd cepat, tanpa adanya prasyarat apapun itu, langsung coba saja
    bermain di gajah138 slots

    Reply
  15. Best crypto casinos

    Thank you a bunch for sharing this with all of us you really know what
    you are speaking approximately! Bookmarked. Kindly additionally talk over with my web site =).

    We can have a link trade arrangement among us

    Reply
  16. http://E-Hp.info

    Bardzo dobry artykuł. Mnóstwo wartościowych wskazówek. Super za podzielenie się.

    Polecam innym.
    Trafnie napisane – kwestia wystroju bywa wymagająca.
    Przydatne podejście.
    Szczerze przydatne. Szukałam czegoś takiego już jakiś czas.
    Dziękuję!

    Stop by my web page http://E-Hp.info

    Reply
  17. Stylistykawnetrz.pl

    Cześć, przeglądałem forum i stwierdzam, że dużo się dowiedziałem. Sama ostatnio zmieniam wystrój i takie porady bardzo się przydają. Pozdrawiam serdecznie.
    Ciekawa dyskusja. Dorzucę od siebie, że dobór mebli naprawdę robi różnicę. Polecam się nie spieszyć.

    Reply
  18. online betting

    This blog post is excellent, probably because of how well the subject was developed. I like some of the comments too though I could prefer we all stay on the subject in order add value to the subject!

    Reply
  19. 프리카지노

    I do not even know how I ended up here, but I thought this post was good.
    I don’t know who you are but definitely you’re going to a famous blogger if
    you are not already 😉 Cheers!

    Reply
  20. เพิ่ม Like ทวิตเตอร์

    Great goods from you, man. I’ve keep in mind your stuff prior to and you are just extremely magnificent.
    I really like what you’ve acquired right here, really like what you’re saying
    and the best way during which you are saying it. You make it entertaining and you continue to take care of to keep
    it sensible. I can’t wait to learn much more from you.
    This is really a great web site.

    Reply
  21. http://T.044300.net

    Grüße euch, ich bin zufällig auf dieses Thema gestoßen und ich stelle fest, dass man hier echt was mitnimmt. Ich selbst bin gerade dabei, mein Haus und solche Tipps sind echt hilfreich. Grüße an die Forengemeinde.
    Spannender Thread. Meiner Meinung nach die Farbwahl nicht zu unterschätzen ist. Es lohnt sich, dafür Zeit zu nehmen.

    Reply
  22. Tatiana

    Grüße euch, ich bin hier durch Zufall gelandet und ich stelle fest, dass es hier viele wertvolle Inhalte gibt. Ich selbst bin gerade dabei, die Einrichtung neu zu und jeder Hinweis ist Gold wert. Liebe Grüße in die Runde.
    Wertvoller Beitrag. Aus meiner Erfahrung die Raumgestaltung nicht zu unterschätzen ist. Lieber einmal richtig als zweimal.

    Here is my webpage; http://mustafasentuerk.com/index.php?title=Mein_Relaxbereich_zu_Hause:_Vom_chaotischen_Wohnzimmer_zur_gem%C3%BCtlichen_Wohlf%C3%BChloase

    Reply
  23. fapaine.com

    Hey! I know thi iis kinmd of ooff topic butt I wass woondering
    iif yoou knew wwhere I coukd gget a captdha pluin foor mmy cokment form?
    I’m usiung tthe same blog pltform as youurs aand I’m having
    problms finding one? Thhanks a lot! ofvd9wuaptr9xqk9ufsh

    Reply
  24. https://Codeforweb.org/

    Hi, ich bin beim Stöbern hier gelandet und mir ist aufgefallen, dass das Thema hervorragend beschrieben ist. Ich selbst gestalte gerade mein Haus und solche Tipps sind echt hilfreich. Grüße an die Forengemeinde.
    Wertvoller Beitrag. Ich kann aus eigener Erfahrung sagen, dass die Auswahl der Möbel wirklich einen Unterschied macht. Gut Ding will Weile haben.

    Have a look at my blog post :: https://Codeforweb.org/mediawiki_tst/index.php?title=Nachhaltiges_Wohnen

    Reply
  25. best online casino nz

    While this issue can vexed most people, my thought is that there has to be a middle or common ground that we all can find. I do value that you’ve added pertinent and sound commentary here though. Thank you!

    Reply
  26. blog

    Resulta crucial distribuir ese fondo en porciones más chicas. Si contás con $10,000 ARS para la semana, no los uses todos en una sola noche. Dividí en sesiones de $1,500-$2,000 para maximizar la diversión.

    Reply
  27. Greensboro Area Office Cleaners

    Hello just wanted to give you a quick heads up. The text in your post seem to be running off the screen in Safari.
    I’m not sure if this is a format issue or something to do with browser compatibility but I figured I’d post to let you
    know. The design and style look great though! Hope you get the problem resolved soon.
    Kudos

    Reply
  28. mellstroy bonus

    Hi there, this weekend is fastidious designed for me, since this occasion i am reading this great informative
    piece of writing here at my residence.

    Reply
  29. bokepindo.win

    Alll asiian femalpe prn starsBlack lesbian lijcking pussyHoot wtt andd juikcy cuntsFreee frde king movi
    piic sexx seex sitye topKylie’s tickle orgasmPuussy
    pendantAdult sex movesEbbony teen whoresTgpp flaat
    chestedBurer laja porn starSexyy bbw’sProfessional foam lztex
    prostheticEliabeth wohg nude imageFrree sex posittions and techniqueFakke
    sezy linddsey lohanFully clothed menn pissingYooung
    patiute pornGresat in nazked outdoorsCoode gedass manta pornPeniis during erectionColdd girl iin bikiniSexuu stripSeex shop statisticsThiik pussysTifa fucksLady soniia anwl clipsSerch forr hentaiRita footjobEroric sorceressFist of thee north star characterUtub aklon i wanbna ffuck youGaay
    and leabian adoptionBoutique dde sex a montrealNude teen girls sexAmmy llee nudfe annd
    evanescenceFreee cumsho mpegs cliups blowjobsGaay hornney muscle menFine oold
    pussyApril michelle biwlby nudeDog djcks picYahoo teen chat shut
    down

    my web-site; bokepindo.win

    Reply
  30. brodlin

    Just desire to say your article is as astounding.

    The clarity in your put up is just nice and that i could think you are knowledgeable in this subject.
    Fine together with your permission allow me to clutch your feed to stay up to date with coming near
    near post. Thanks 1,000,000 and please keep up the gratifying work.

    Reply
  31. 044300.net

    Hi, ich habe das Forum durchgeblättert und ich muss zugeben, dass das Thema hervorragend beschrieben ist. Ich gestalte gerade meine Wohnung ein und solche Tipps sind echt hilfreich. Grüße an die Forengemeinde.
    Wertvoller Beitrag. Ich kann aus eigener Erfahrung sagen, dass die Raumgestaltung nicht zu unterschätzen ist. Gut Ding will Weile haben.

    Reply
  32. ปั้มติดตาม

    Thanks for one’s marvelous posting! I quite
    enjoyed reading it, you are a great author.I will remember to bookmark your blog and will come back very soon.
    I want to encourage you continue your great writing, have a nice afternoon!

    Reply
  33. phishingg

    Hey there, You’ve done an incredible job. I’ll certainly digg it and personally suggest to my friends.
    I am sure they’ll be benefited from this site.

    Reply

Leave a Reply

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