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

  1. jaguar33

    Write more, thats all I have to say. Literally, it seems as though
    you relied on the video to make your point.
    You obviously know what youre talking about, why throw away your intelligence on just posting videos to your weblog when you could be giving us something informative to
    read?

    Reply
  2. Warblog.Hys.Cz

    Wertvoller Post. Eine Menge wertvolle Inspirationen.
    Großes Lob für diesen Inhalt. Ich empfehle die Seite gerne
    weiter.
    Genau – der Bereich der Möbelauswahl ist nicht einfach.
    Danke für die klare Erklärung.
    Echt inspirierend. Ich war schon nach ähnlichen Tipps seit einiger
    Zeit gesucht. Viele Grüße!

    Here is my site … Warblog.Hys.Cz

    Reply
  3. map bahria town

    What’s Going down i am new to this, I stumbled upon this
    I have found It absolutely useful and it has helped me out loads.

    I hope to contribute & help different customers like its aided me.
    Good job.

    Reply
  4. Billy

    Bardzo dobry materiał. Wiele praktycznych wskazówek.
    Pozdrawiam że dzielisz się wiedzą. Będę
    zaglądać częściej.
    Masz rację – sprawa urządzania wnętrz bywa niełatwa.

    Dobrze, że ktoś to wyjaśnia.
    Naprawdę pomocne. Szukałem podobnych porad właśnie tego.
    Pozdrawiam!

    Look into my page Billy

    Reply
  5. https://Simtrepainty.cz/index.php?title=Farbpalette_für_die_Wohnung:_So_findest_Du_deinen_perfekten_Ton

    Wirklich guter Inhalt. Reichlich hilfreiche Inspirationen.
    Grüße für diesen Inhalt. Ich empfehle die Seite gerne weiter.

    Genau – die Frage der Einrichtung ist herausfordernd. Hilfreicher Ansatz.

    Aufrichtig inspirierend. Ich habe schon nach solchen Informationen seit
    einiger Zeit gesucht. Klasse gemacht!

    Here is my web blog – https://Simtrepainty.cz/index.php?title=Farbpalette_für_die_Wohnung:_So_findest_Du_deinen_perfekten_Ton

    Reply
  6. Tyrell Stepler

    Unquestionably consider that that you said. Your favourite reason seemed to be at the net the simplest factor to have in mind of. I say to you, I definitely get irked whilst other people think about worries that they just don’t know about. You managed to hit the nail upon the highest as neatly as defined out the whole thing without having side effect , other people can take a signal. Will probably be back to get more. Thank you

    Reply
  7. Garage Door Repair

    Howdy! I could have sworn I’ve been to this web site before but
    after looking at a few of the articles I realized it’s new to me.
    Anyhow, I’m definitely happy I discovered
    it and I’ll be bookmarking it and checking back regularly!

    Reply
  8. MichaelAmown

    Нужен аккмулятор? интернет магазин аккмуляторов по выгодной цене с подбором под ваш автомобиль. В наличии аккумуляторы популярных брендов, услуги установки, диагностика аккумулятора, прием старой АКБ и оперативная доставка по Санкт-Петербургу.

    Reply
  9. Shari

    Womken bouhd and gaged bdsmFener bassman aamp vintageGayy best frrnds
    first timeHott aian latexWatt mazkes a pednis attractiveVintage pinkSexx whi dogsIsabgelle aadjani pussyMeloropse flxx analFundactory adult
    toysBatt iin cuntSeexy ukraine girdls foor marrigeFuckk liil llyric yalll yolaBoa
    vs pythn nude video sceneNakked aand funny viddeo streamFucdking tanMitfh hewser gay3d ellf ccum moviesMilff nude videosNudde inn swaeden videoFrree nufe galary russiaDaughtrr eroticFrree blck douuble penetratioon movieHow too jerk offf betterBurrbank aduylt basketball lezgue scheduleReewbok viuntage highWiree oof spankWdding cke seex annd thee cityTight fotting bikiniCheap asikan parasolFuckig the gearshiftTotally spis cartoos nudeNew zealznd twinksPleasure islandd limitedWoken stories sexujal fictionLattin porbstar siphia casteloBiig dicdk pics amateurCinderela pofn ashley wellesCarey edwards pornMilf tames siccilian donkeyFreee onlinhe hentai ssex moviesSopha luren nudeTeen aameture
    pkrn vidsVitage haandjob partiesDoggs tbat lck bullfrogsAdult cluub magazinbe bck issue pdfMobie bllonde fucdk videosFroced sex objectsYngg fetishFreee ckck sucking annd swallowing
    videoManauddou pictrures nakoed onn thhe internetHomme
    mawde ammeatur ssex videosYourfvilehost fourl ten lesbiansTittjob sexx clpsRubbing pantyhoseGenesral hospital actrewss nudeMedicakd ckde ssex offenxer
    treatmentFrree supper hung shemaleWhatt maake breeast growJapsns hottest teensTaan nudesWeebcast coick contyrol mistressesFacisl fasciculationJeesica swqeet interacial sexNaturally saggyy titt pornPuss blunt objectBiig brestsd sexBrsast implan jerseyy neww surgeonAmateur latiinas
    forumDifks spoetingNipple pullling pornBoondage shift
    tLesbijan toilewt sloave videosSmell yoo diock mp3Alli larger
    desiger imposter nude uncensoredBlogg ffor analStacy fergujson aduult filmPisssing in thei pantsHomad ssalt lickSiszter inn
    law slutWomenn iin poorn mebs shirtVahinal dryness during
    ssex inn ffor young womenFreee sexx pics milkf redHoow tto enlarege your breastsAnimated diney porn coic sstrips ofvd9wuaptuzrtuordmt

    Reply
  10. bokep lesbi indonesia

    Hello! I’ve been following your blog for a long time now and finally got the courage to go ahead and give you a shout out from Porter Texas!
    Just wanted to mention keep up the good job!

    Reply
  11. sex

    I think what you published made a bunch of sense.
    However, what about this? suppose you wrote a catchier title?
    I am not suggesting your content isn’t good, however
    what if you added a headline to maybe get folk’s attention? I
    mean Use a simple script to achieve powder pile | Maya nParticle简单脚本实现粒子堆叠 | Asher.GG is kinda plain. You ought to glance at Yahoo’s home page and watch how they create news titles to grab people to open the
    links. You might try adding a video or a related picture or two
    to get readers excited about everything’ve written. Just my opinion, it might make
    your blog a little livelier.

    Reply
  12. Hosea

    Rzeczowy tekst. Dużo wartościowych wskazówek. Pozdrawiam za ten materiał.
    Będę zaglądać częściej.
    Masz rację – sprawa wystroju potrafi być wymagająca.

    Przydatne podejście.
    Szczerze inspirujące. Szukałem czegoś takiego już jakiś czas.
    Pozdrawiam!

    My blog post – Hosea

    Reply
  13. memek besar

    Do you mind if I quote a few of your posts as long as I provide credit and sources back to your blog?
    My website is in the very same niche as yours and my users would really benefit from some of the information you provide
    here. Please let me know if this okay with you.
    Thank you!

    Reply
  14. badpro

    Admiring the dedication you put into your site and detailed information you provide.
    It’s awesome to come across a blog every once in a while that
    isn’t the same outdated rehashed information. Fantastic read!
    I’ve saved your site and I’m including your RSS feeds to my Google account.

    Reply
  15. https://azbongda.com/

    Interessanter Post. Reichlich hilfreiche Anregungen. Großes Lob
    für diesen Inhalt. Ab jetzt lese ich hier öfter mit.

    Sehe ich genauso – das Thema des Wohnstils wird oft schwierig.
    Endlich mal Klartext.
    Wirklich nützlich. Ich habe schon nach so etwas seit einiger Zeit gesucht.

    Viele Grüße!

    Also visit my web page: https://azbongda.com/

    Reply
  16. Philomena

    Hi, ich bin zufällig auf dieses Thema gestoßen und mir ist aufgefallen, dass es hier viele wertvolle Inhalte gibt. Ich bin gerade dabei, mein Zuhause neu zu gestalten und solche Tipps sind echt hilfreich. Viele Grüße.
    Interessante Diskussion. Ich kann aus eigener Erfahrung sagen, dass die Raumgestaltung eine enorme Rolle spielt. Gut Ding will Weile haben.

    Reply
  17. wicket71 slot

    Thanks for the auspicious writeup. It actually
    was a entertainment account it. Glance advanced to more added agreeable from you!
    However, how could we communicate?

    Reply
  18. NST PROPERTY DEVELOPERS

    You really make it seem so easy with your presentation but I find this
    matter to be actually something which I think I would never understand.
    It seems too complicated and extremely broad for me. I’m looking forward for your next post, I’ll
    try to get the hang of it!

    Reply
  19. MALWARE

    Heya! I’m at work browsing your blog from my new apple
    iphone! Just wanted to say I love reading through your blog and look forward to all your
    posts! Carry on the great work!

    Reply
  20. Joel

    Dzień dobry, natknąłem się na ten temat i chcę powiedzieć, że jest tu sporo wartościowych treści. Sama ostatnio remontuję dom i szukam inspiracji. Miłego dnia wszystkim.
    Wartościowy wątek. Moim zdaniem aranżacja wnętrza naprawdę robi różnicę. Warto poświęcić temu czas.

    Here is my webpage https://Wiki.Somosphm.net/index.php/Jak_urz%C4%85dzi%C4%87_ma%C5%82e_mieszkanie,_%C5%BCeby_nie_zwariowa%C4%87_od_ci%C4%85g%C5%82ego_sprz%C4%85tania_i_braku_miejsca

    Reply
  21. harga emas terkini

    What you published was very reasonable. However, consider this, what if you were to create a awesome title?
    I ain’t saying your content is not good, but suppose
    you added a title that makes people want more? I mean Use a simple script to achieve
    powder pile | Maya nParticle简单脚本实现粒子堆叠 | Asher.GG is kinda vanilla.
    You could look at Yahoo’s home page and see how they
    create post titles to get viewers to click. You might try adding a video
    or a related picture or two to get readers excited about what you’ve got to
    say. In my opinion, it would make your website a little
    livelier.

    Reply
  22. игровые читы

    Доброго времени суток, народ! Меня зовут Катя,
    вещаю из Праги.

    Последние несколько лет я трачу свободное время на катки.

    И вот случилась проблема – я никак
    не могла апнуть высокий ранг.

    Недавно я наткнулась на очень мощный материал про современные читы.

    В статье были реальные технические
    факты о том, как работают внешние ESP радары, которые читают пакеты и вообще не вмешиваются в память самой
    игры. В тексте приводилась детальная статистика, доказывающих, что сейчас
    с софтом играет огромное
    количество хай-ранг стримеров.

    Короче, я решила рискнуть и приобрела приватку.
    Так как я играю в разные жанры, я оплатила бандл сразу для парочки любимых проектов.

    Мой выбор пал на комбо для Dota 2 и
    Apex Legends.

    Результат просто бомба – буквально за пару недель я вышла в топ лидерборда.

    Мой скилл визуально взлетел до небес.

    Что самое главное – никаких банов,
    потому что софт реально качественный.

    Если кто-то тоже устал сливать – очень рекомендую!

    Reply

Leave a Reply

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