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

  1. 乐鱼官网

    Howdy! This post couldn’t be written any better! Reading this post reminds me of my previous room mate!
    He always kept chatting about this. I will forward this write-up to him.
    Pretty sure he will have a good read. Thanks for sharing!

    Reply
  2. Tam

    Hilfreicher Text. Viele wertvolle Informationen. Super dass du
    dein Wissen teilst. Ich empfehle die Seite gerne weiter.
    Stimme zu – die Frage der Raumgestaltung ist nicht einfach.
    Danke für die klare Erklärung.
    Sehr inspirierend. Ich war schon nach ähnlichen Tipps seit
    Wochen gesucht. Danke!

    Feel free to visit my website; Tam

    Reply
  3. www.theepochtimes.com

    Just want to say your article is as surprising. The
    clearness in your post is just nice and i could assume you’re an expert
    on this subject. Fine with your permission let me to grab
    your feed to keep updated with forthcoming post. Thanks a million and please continue the rewarding work.

    Reply
  4. Bruno

    Toller Inhalt. Viele nützliche Tipps. Danke für diesen Inhalt.
    Ich speichere mir die Seite ab.
    Stimme zu – das Thema der Einrichtung ist nicht einfach.
    Danke für die klare Erklärung.
    Echt praxisnah. Ich habe schon nach solchen Informationen seit Wochen gesucht.
    Super Arbeit!

    My web-site :: Bruno

    Reply
  5. Dmitry Volkov entrepreneur

    Hmm is anyone else experiencing problems with the pictures on this blog loading?
    I’m trying to figure out if its a problem on my end or if it’s the blog.
    Any feed-back would be greatly appreciated.

    Reply
  6. เพิ่ม Like ติ๊กต๊อก

    Undeniably believe that which you stated. Your
    favorite reason appeared to be on the net the simplest thing to be aware of.
    I say to you, I definitely get annoyed while people consider worries that they plainly do not know about.
    You managed to hit the nail upon the top and defined out the whole thing without having side effect , people can take a signal.
    Will likely be back to get more. Thanks

    Reply
  7. 欧宝app

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

    Reply
  8. online 138

    Wonderful blog! I found it while searching on Yahoo News. Do you have any suggestions on how to
    get listed in Yahoo News? I’ve been trying for a while but I never
    seem to get there! Thanks

    Reply
  9. Stacey

    Bardzo dobry artykuł. Dużo praktycznych wskazówek. Super że
    dzielisz się wiedzą. Czekam na więcej.
    Zgadzam się – sprawa wystroju jest niełatwa. Wreszcie konkrety.

    Bardzo pomocne. Szukałam czegoś takiego już jakiś czas.
    Dziękuję!

    Visit my blog … Stacey

    Reply
  10. Korey

    Bardzo dobry materiał. Sporo konkretnych informacji.
    Dziękuję za podzielenie się. Zapisuję do ulubionych.

    Trafnie napisane – temat doboru mebli potrafi być niełatwa.
    Dobrze, że ktoś to wyjaśnia.
    Bardzo inspirujące. Szukałam podobnych porad już
    jakiś czas. Dziękuję!

    Feel free to surf to my blog – Korey

    Reply
  11. domy na sprzedaz koszalin

    I blog quite often and I really thank you for your content.

    Your article has truly peaked my interest. I am going to book mark
    your blog and keep checking for new information about once a week.
    I opted in for your Feed too.

    Reply
  12. call girl in Aerocity

    You actually make it appear so easy together with your presentation but I in finding
    this matter to be actually something that I
    feel I might by no means understand. It sort of feels too complex and very huge for me.
    I’m taking a look ahead for your subsequent submit, I will
    try to get the hang of it!

    Reply
  13. Leonore

    Bardzo dobry materiał. Mnóstwo praktycznych porad.
    Dziękuję za ten materiał. Polecam innym.
    Dokładnie – kwestia aranżacji potrafi być trudna. Przydatne podejście.

    Naprawdę przydatne. Szukałem takich informacji właśnie tego.
    Super robota!

    Feel free to visit my page – Leonore

    Reply
  14. Scot

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

    Reply
  15. Wilhelmina

    Witajcie, trafiłem tu przypadkiem i stwierdzam, że dużo się dowiedziałem. Sama od jakiegoś czasu urządzam mieszkanie i szukam inspiracji. Dzięki i pozdrawiam.
    Dobry temat. Dorzucę od siebie, że wybór kolorystyki ma ogromne znaczenie. Lepiej raz a dobrze.

    Reply
  16. Charity

    Joint on-lіne difficulties аt OMT build teamwork in mathematics, promoting love аnd cumulative motivation foг
    tests.

    Dive into seⅼf-paced mathematics proficiency ᴡith OMT’ѕ 12-month e-learning courses, total ԝith pactice worksheets аnd taped sessions for extensive modification.

    Τhe holistic Singapore Math approach, ԝhich
    develops multilayered рroblem-solving capabilities,
    underscores ᴡhy math tuition іs essential for mastering tһe
    curriculum ɑnd getting ready for future professions.

    primary school school math tuition boosts rational reasoning,
    crucial fоr analyzing PSLE concerns involving sequences аnd logical deductions.

    Tuition aids secondary students develop test methods, ѕuch as time allocation for both O Level
    math papers, leading to far Ьetter ⲟverall performance.

    Math tuition аt the junior college degree stresses conceptual clarity
    ⲟver memorizing memorization, essential fоr taҝing on application-based А
    Level concerns.

    OMT distinguishes ᴡith a proprietary curriculum tһat supports MOE web
    ϲontent Ьy mеans of multimedia integrations, ѕuch as video explanations ⲟf
    key theorems.

    Assimilation ԝith school гesearch leh, making tuition a smooth extension f᧐r quality improvement.

    Witһ global competition climbing, math tuition positions Singapore pupils ɑs tоρ entertainers іn global mathematics analyses.

    My website … ѕec2 maths tuition (Charity)

    Reply
  17. no kyc casinos

    Good post. I learn something new and challenging on blogs I stumbleupon on a
    daily basis. It’s always interesting to read through articles from other
    writers and use something from other sites.

    Check out my site; no kyc casinos

    Reply
  18. https://pakistan-cricket-team-players.com/

    I came across this article earlier today and I
    felt it was important to share my thoughts. The clarity in your explanation of complex cricket topics really impressed me.

    The most valuable part is that you don’t ignore important details like stats and player form.
    You gave me new insights to think about.

    I’ll definitely follow your future posts! I’ve already
    shared this with a few friends who follow cricket
    closely.

    Reply
  19. click

    Thanks for finally writing about > Use a simple script to achieve powder pile | Maya nParticle简单脚本实现粒子堆叠 | Asher.GG < Loved it!

    Reply
  20. http://wudao28.com/home.php?mod=space&uid=2522953

    Hallo, ich habe das Forum durchgeblättert und ich möchte sagen, dass das Thema hervorragend beschrieben ist. Ich selbst bin gerade dabei, meine Wohnung ein und jeder Hinweis ist Gold wert. Danke und viele Grüße.
    Spannender Thread. Ich kann aus eigener Erfahrung sagen, dass die richtige Farbgebung eine enorme Rolle spielt. Es lohnt sich, dafür Zeit zu nehmen.

    Reply
  21. Gulioiringa.Com

    Klasse Inhalt. Eine Menge wertvolle Anregungen. Danke fürs Teilen. Ich warte auf mehr.

    Du hast recht – die Sache der Raumgestaltung kann nicht einfach.
    Danke für die klare Erklärung.
    Sehr praxisnah. Ich habe schon nach genau so einem Beitrag seit einiger Zeit gesucht.
    Danke!

    My website; Gulioiringa.Com

    Reply
  22. Jamal

    Hallo, ich bin beim Stöbern hier gelandet und ich möchte sagen, dass das Thema hervorragend beschrieben ist. Ich selbst renoviere seit kurzem mein Zuhause neu zu gestalten und solche Tipps sind echt hilfreich. Grüße an die Forengemeinde.
    Gutes Thema. Ich kann aus eigener Erfahrung sagen, dass die Auswahl der Möbel wirklich einen Unterschied macht. Lieber einmal richtig als zweimal.

    Also visit my homepage :: https://Www.Ebersbach.org/index.php?title=Jugendzimmer_einrichten_%E2%80%93_Wenn_der_Platz_zum_Leben_erwacht

    Reply
  23. строительство кирпичных домов

    строительство ленточного фундамента – свайно-ленточный для слабых грунтов.
    расчет по геологии. гарантия 10 лет
    на бетон. акция: лента + стены из блоков
    = скидка 15%
    монтаж вентиляции Дмитров – для частных домов и квартир.
    вентиляторы Soler&Palau. установка за 1 день.
    акция «дом + вентиляция» – 10%
    строительство кирпичных домов
    – с облицовкой клинкером.
    армирование сеткой через 4 ряда.
    цена от 70 000 ₽/м². покажем объекты в поселках «Яхрома парк», «Медвежьи озера»

    Reply
  24. Makanan

    An intriguing discussion is definitely worth comment.
    I believe that you ought to publish more about this subject, it may not be a taboo matter but usually people do not speak
    about these issues. To the next! All the best!!

    Reply
  25. Https://Wiki.rettungsdienstblog.eu/

    Cześć, natknąłem się na ten temat i stwierdzam, że jest tu sporo wartościowych treści. Sama ostatnio urządzam mieszkanie i takie porady bardzo się przydają. Pozdrawiam serdecznie.
    Wartościowy wątek. Moim zdaniem dobór mebli to podstawa. Polecam się nie spieszyć.

    Look into my homepage :: https://Wiki.rettungsdienstblog.eu/index.php?title=Styl_modern_classic_%E2%80%93_jak_go_urz%C4%85dzi%C4%87_w_polskim_mieszkaniu%3F

    Reply
  26. slon7 cc

    Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates.

    I’ve been looking for a plug-in like this for
    quite some time and was hoping maybe you would have some
    experience with something like this. Please let me know if
    you run into anything. I truly enjoy reading your blog and I look
    forward to your new updates.

    Reply
  27. homepage

    I believe that is among the such a lot significant info for me.
    And i’m satisfied studying your article. However should observation on few normal things,
    The web site style is perfect, the articles is in reality
    nice : D. Good activity, cheers

    Reply
  28. Merri

    Naprawdę dobry wpis. Sporo wartościowych porad.
    Pozdrawiam że dzielisz się wiedzą. Polecam innym.
    Trafnie napisane – sprawa wystroju potrafi być wymagająca.
    Dobrze, że ktoś to wyjaśnia.
    Szczerze pomocne. Szukałem czegoś takiego od dawna.

    Pozdrawiam!

    My blog post; Merri

    Reply
  29. thưởng thức sex học sinh miễn phí

    It’s a pity you don’t have a donate button! I’d most certainly 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 blog with my
    Facebook group. Chat soon!

    Reply
  30. Https://Localhomeservicesblog.Co.Uk/

    Guten Tag, ich bin hier durch Zufall gelandet und ich muss zugeben, dass es hier viele wertvolle Inhalte gibt. Ich selbst richte seit einiger Zeit mein Zuhause neu zu gestalten und jeder Ratschlag hilft mir weiter. Danke und viele Grüße.
    Gutes Thema. Aus meiner Erfahrung die Farbwahl eine enorme Rolle spielt. Gut Ding will Weile haben.

    Feel free to visit my blog – https://Localhomeservicesblog.Co.uk/wiki/index.php?title=Die_perfekte_Farbpalette_f%C3%BCr_die_Wohnung:_So_finden_Sie_Ihre_Wohlf%C3%BChlfarben

    Reply

Leave a Reply

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