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

  1. 1xbet_suMi

    Beyler dinleyin Her yer dolandırıcı dolu Hepsinde paramı kaybettim Sonunda düzgün bir yer buldum — 1xbet turkey güncel giriş Her gün bedava bahis ve promolar Neyse, tüm detaylar burada — 1xbet türkiye [url=https://1xbet-fkq.com]1xbet türkiye[/url] En iyisi 1xbet Bunun gibilerin derdine düşenlere gönder

    Reply
  2. Reagan

    Sachlicher Text. Eine Menge konkrete Anregungen. Vielen Dank für die Mühe.

    Ich warte auf mehr.
    Stimme zu – die Frage der Wohnungsgestaltung kann
    anspruchsvoll. Gut, dass es jemand erklärt.
    Aufrichtig praxisnah. Ich habe schon nach genau so einem Beitrag lange gesucht.
    Danke!

    My webpage :: Reagan

    Reply
  3. Rachael

    Hilfreicher Beitrag. Zahlreiche praktische Anregungen. Danke für
    diesen Inhalt. Ich werde öfter reinschauen.
    Stimme zu – die Frage der Möbelauswahl ist herausfordernd.
    Endlich mal Klartext.
    Echt inspirierend. Ich suche schon nach genau so einem Beitrag seit Wochen gesucht.
    Klasse gemacht!

    Check out my website … Rachael

    Reply
  4. td777

    Generally I do not learn post on blogs, however
    I wish to say that this write-up very compelled me to take a look at and do it!

    Your writing style has been surprised me. Thanks, very great post.

    Reply
  5. 1xbet_loSi

    Merhaba arkadaşlar Düzgün bir bahis sitesi bulmak gerçekten çok zor Paramı geri alamadım Bu kesinlikle en iyisi — 1xbet en iyi oranlar İşlemler saniyeler içinde tamamlanıyor Kısacası, tüm bilgiler bu linkte — 1xbet spor bahislerinin adresi [url=https://1xbet-mxv.com]1xbet spor bahislerinin adresi[/url] En iyisi 1xbet İhtiyacı olan herkese gönderin

    Reply
  6. https://wikistax.org/index.Php/kuchyně_na_míru_versus_skříň_na_spaní_aneb_kde_schovat_desátého_hosta

    Bardzo dobry wpis. Sporo przydatnych porad. Super za podzielenie się.

    Czekam na więcej.
    Trafnie napisane – temat doboru mebli potrafi być trudna.
    Przydatne podejście.
    Szczerze inspirujące. Szukałem takich informacji od dawna.
    Dziękuję!

    My site https://wikistax.org/index.Php/kuchyně_na_míru_versus_skříň_na_spaní_aneb_kde_schovat_desátého_hosta

    Reply
  7. Data HK Nagasaon

    What i don’t understood is if truth be told
    how you’re not really a lot more neatly-preferred than you may be right now.

    You’re so intelligent. You know therefore considerably relating to this subject, made me individually consider it from a lot
    of various angles. Its like women and men don’t seem to be
    involved except it’s something to accomplish with Girl gaga!

    Your own stuffs outstanding. At all times handle it up!

    Reply
  8. Physics and Maths tutor differentiation

    By linking mathematics tо innovative projects, OMT awakens ɑn interest in students,
    urging tһem to accept the subject and aim fоr examination proficiency.

    Experience versatile knowing anytime, ɑnywhere thгough OMT’s
    tһorough online e-learning platform, featuring unrestricted access tⲟ video lessons
    аnd interactive quizzes.

    Singapore’ѕ focus on vital analyzing mathematics highlights tһe value of math tuition, ᴡhich assists students establish the analytical abilities required Ьy tһe country’ѕ forward-thinking curriculum.

    primary tuition іs essential for constructing strength ɑgainst PSLE’s tricky concerns, suⅽh as
    thosе on probability and easy stats.

    Senior hiɡh school math tuition іs vital for Ο Levels as іt
    strengthens proficiency of algebraic manipulation,
    а core part that regularly appears in test inquiries.

    Tuition instructs mistake analysis techniques, aiding junior college students аvoid usual challenges in A Level computations
    ɑnd evidence.

    Thе proprietary OMT educational program sticks оut by incorporating MOE syllabus components witһ gamified tests аnd
    challenges to make finding out more delightful.

    OMT’ѕ system urges goal-setting ѕia, tracking landmarks іn the
    direction ᧐f attaining ɡreater qualities.

    Ᏼy incorporating technology, online math tuition involves digital-native Singapore trainees fߋr
    interactive exam revision.

    Μy webpage … Physics and Maths tutor differentiation

    Reply
  9. Paito Warna Sydney Raja Dunia Togel

    Greetings from Los angeles! I’m bored at work
    so I decided to browse your website on my iphone during
    lunch break. I love the information you present here and can’t wait to take a look when I get home.
    I’m surprised at how fast your blog loaded on my phone ..
    I’m not even using WIFI, just 3G .. Anyways, amazing site!

    Reply
  10. Data HK Angka Setan

    Hey there would you mind stating which blog platform you’re working with?
    I’m going to start my own blog soon but I’m having a difficult time choosing between BlogEngine/Wordpress/B2evolution and Drupal.

    The reason I ask is because your design and style seems different then most blogs and I’m looking for something completely unique.
    P.S My apologies for getting off-topic but I had to ask!

    Reply
  11. vavada_bcmr

    Народ кто в теме А поддержка молчит как рыба Нервов потратил — мама не горюй Короче, работает стабильно и честно — вавада с быстрыми выплатами Фриспины и акции каждый день В общем, там все подробности — vavada казино [url=https://partscore.ru]vavada казино[/url] Не ведитесь на лохотроны Перешлите тому кто тоже ищет нормальное казино

    Reply
  12. Will

    Toller Post. Eine Menge hilfreiche Hinweise. Danke fürs Teilen. Ich
    werde öfter reinschauen.
    Treffend formuliert – der Bereich der Einrichtung wird oft schwierig.
    Endlich mal Klartext.
    Echt nützlich. Ich suche schon nach ähnlichen Tipps lange gesucht.
    Viele Grüße!

    Feel free to visit my webpage Will

    Reply
  13. vavada_ciPl

    Ребята кто в теме А поддержка молчит как рыба Денег слил на всяком говне Короче, работает стабильно и честно — вавада казино зеркало Поддержка отвечает сразу В общем, сохраняйте себе — вавада казино онлайн официальный сайт [url=https://polezno-vsem.ru]вавада казино онлайн официальный сайт[/url] Не ведитесь на лохотроны Перешлите тому кто тоже ищет нормальное казино

    Reply
  14. Update Link

    Its such as you read my mind! You appear to understand a lot
    about this, such as you wrote the ebook in it or
    something. I believe that you could do with some percent
    to drive the message home a bit, but other than that,
    that is great blog. An excellent read. I will definitely be back.

    Reply
  15. comment-58437

    This is really interesting, You’re a very skilled blogger.
    I’ve joined your rss feed and look forward to seeking more of your magnificent post.
    Also, I have shared your web site in my social networks!

    Reply
  16. situs porno

    We are a group of volunteers and starting a new scheme in our community.
    Your website provided us with valuable information to work on. You’ve done a formidable job and our whole community will be grateful
    to you.

    Reply
  17. true mate romance

    Link exchange is nothing else except it is
    just placing the other person’s blog link on your page at suitable place and other person will
    also do similar in favor of you.

    Reply
  18. 비아그라 처방

    Woah! I’m really loving the template/theme
    of this blog. It’s simple, yet effective. A lot of times it’s challenging to get that “perfect balance”
    between user friendliness and visual appeal. I must say that
    you’ve done a superb job with this. Additionally, the blog loads extremely fast for me on Internet explorer.
    Exceptional Blog!

    Reply
  19. https://wefreeads.com/einrichtungstrends-die-Mein-kleines-wohnzimmer-gerettet-haben/

    Sachlicher Text. Reichlich praktische Tipps. Grüße für diesen Inhalt.
    Ab jetzt lese ich hier öfter mit.
    Volle Zustimmung – das Thema der Wohnungsgestaltung wird
    oft anspruchsvoll. Danke für die klare Erklärung.

    Sehr nützlich. Ich war schon nach so etwas seit Wochen gesucht.

    Danke!

    Here is my site; https://wefreeads.com/einrichtungstrends-die-Mein-kleines-wohnzimmer-gerettet-haben/

    Reply
  20. Http://wiki.saomaitech.vn/

    Wertvoller Inhalt. Reichlich praktische Hinweise.

    Großes Lob für diesen Inhalt. Ich empfehle die
    Seite gerne weiter.
    Stimme zu – der Bereich des Wohnstils kann herausfordernd.

    Endlich mal Klartext.
    Echt praxisnah. Ich suche schon nach solchen Informationen seit einiger Zeit
    gesucht. Klasse gemacht!

    Also visit my blog post: http://wiki.saomaitech.vn/

    Reply
  21. bokep anak

    whoah this weblog is magnificent i really like reading your posts.
    Keep up the good work! You understand, a lot of individuals are looking round
    for this info, you can aid them greatly.

    Reply
  22. 樱花动漫

    An outstanding share! I have just forwarded this onto a friend
    who was doing a little research on this. And he actually ordered me breakfast simply because I
    stumbled upon it for him… lol. So let me reword this….
    Thank YOU for the meal!! But yeah, thanks for spending some
    time to talk about this subject here on your website.

    Reply
  23. Marcelino

    Wertvoller Post. Eine Menge praktische Inspirationen. Vielen Dank für diesen Inhalt.
    Ich werde öfter reinschauen.
    Du hast recht – die Sache der Einrichtung ist
    nicht einfach. Hilfreicher Ansatz.
    Sehr inspirierend. Ich habe schon nach genau so einem Beitrag lange gesucht.
    Super Arbeit!

    Here is my web blog; Marcelino

    Reply
  24. Sharon

    Wirklich guter Text. Jede Menge konkrete Anregungen.
    Grüße dass du dein Wissen teilst. Ich warte auf mehr.
    Treffend formuliert – die Sache der Einrichtung kann herausfordernd.

    Hilfreicher Ansatz.
    Aufrichtig inspirierend. Ich habe schon nach genau so einem Beitrag lange gesucht.
    Danke!

    Look at my page :: Sharon

    Reply
  25. Wiki.Internzone.Net

    Sehr guter Artikel. Reichlich praktische Hinweise. Großes Lob dass du dein Wissen teilst.
    Ich speichere mir die Seite ab.
    Stimme zu – die Frage der Einrichtung kann anspruchsvoll.
    Gut, dass es jemand erklärt.
    Wirklich inspirierend. Ich habe schon nach ähnlichen Tipps seit Wochen gesucht.
    Klasse gemacht!

    Here is my page – Wiki.Internzone.Net

    Reply
  26. Muriel

    Ciekawy artykuł. Sporo wartościowych wskazówek.
    Pozdrawiam za podzielenie się. Na pewno tu wrócę.
    Dokładnie – sprawa aranżacji potrafi być wymagająca.
    Dobrze, że ktoś to wyjaśnia.
    Bardzo przydatne. Szukałam czegoś takiego właśnie tego.
    Super robota!

    Here is my web-site – Muriel

    Reply
  27. 加密货币

    极简主义者的评价:不废话,不教课,不喊单,不给财富密码,只给链接。Cryptify Hub是一个有边界感的工具网址大全,它知道自己能做什么(指路),也知道自己做不了什么(担保安全)。用它的本分,别指望它的非分。

    Reply
  28. Tony

    Wertvoller Text. Reichlich praktische Anregungen. Grüße für die
    Mühe. Ich empfehle die Seite gerne weiter.
    Sehe ich genauso – der Bereich der Wohnungsgestaltung wird oft anspruchsvoll.
    Hilfreicher Ansatz.
    Echt inspirierend. Ich war schon nach solchen Informationen seit Wochen gesucht.
    Viele Grüße!

    Feel free to visit my web site … Tony

    Reply
  29. Web3工具导航

    使用Cryptify Hub的正确姿势:第一步,加入它的社群(通常是Discord),观察大家在聊什么;第二步,使用它的工具导航站快速查找常用链接;第三步,如果在使用某个工具时遇到问题,可以在社群里提问,看看有没有人遇到过同样的问题。但请记住:社群里的任何答案都不保证正确,涉及资金的操作务必自行核实。民间社群是辅助,不是权威。

    Reply
  30. 加密货币

    该平台不构成任何形式的教育服务、投资建议或技术指导。其唯一价值在于将分散的币圈工具官网入口进行结构化整理,降低用户的查找时间成本。使用时应明确:链接的可用性和安全性可能随时间变化,导航站无法实时监控每个目标网站的状态。

    Reply
  31. LV88

    Piece of writing writing is also a fun, if you be familiar with
    then you can write if not it is complicated to write.

    Reply
  32. Kaizenaire math tuition singapore

    By emphasizing conceptual proficiency, OMT exposes mathematics’ѕ internal elegance, firing up love ɑnd drive for leading examination qualities.

    Ⲥhange mathematics obstaccles іnto victories wіth OMT Math Tuition’ѕ mix of online and on-site alternatives, bаcked by a performance history оf student
    excellence.

    The holistic Singapore Math technique, which develops multilayered analytical capabilities, highlights ԝhy math tuition іs vital for mastering tһe curriculum аnd preparing fօr
    future careers.

    Improving primary education ԝith math tuition prepares students fօr PSLE by cultivating a development fгame
    of mind towaгd challenging topics ⅼike symmetry аnd improvements.

    Holistic development vіa math tuition not ⲟnly increases O Level scores Ьut likewisе cultivates logical thinkiing skills
    beneficial f᧐r ⅼong-lasting learning.

    For thosе goіng after Η3 Mathematics, junior college tuition рrovides sophisticated support ᧐n research-level subjects tߋ master tһiѕ difficult expansion.

    Ꮃһɑt makeѕ OMT stand ߋut is its customized curriculum that straightens
    ѡith MOE wһile including ΑI-driven flexible understanding tߋ suit private demands.

    OMT’s syѕtem urges goal-setting ѕia, tracking landmarks іn the direction օf attaining һigher grades.

    Math tuition սses targeted method ԝith рrevious test documents,
    acquainting trainees ԝith inquiry patterns ѕeen in Singapore’s national assessments.

    Feel free tо visit my web site :: Kaizenaire math tuition singapore

    Reply

Leave a Reply

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