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

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

  1. Kris

    Sachlicher Artikel. Reichlich praktische Informationen. Vielen Dank für diesen Inhalt.
    Ich speichere mir die Seite ab.
    Volle Zustimmung – das Thema der Einrichtung wird oft schwierig.
    Endlich mal Klartext.
    Wirklich hilfreich. Ich habe schon nach so etwas seit einiger Zeit gesucht.
    Viele Grüße!

    Here is my site Kris

    Reply
  2. Cytotec in Jeddah

    I must thank you for the efforts you have put in penning this website.

    I am hoping to see the same high-grade content by you later on as well.
    In fact, your creative writing abilities has inspired me to get my own website now 😉

    Reply
  3. comment-703912

    I’m curious to find out what blog system you’re using?
    I’m experiencing some small security issues with
    my latest website and I would like to find something more risk-free.
    Do you have any suggestions?

    Reply
  4. bokep indonesia

    Artikel yang sangat informatif dan bermanfaat. Banyak orang di Indonesia mencari informasi terpercaya tentang viagra indonesia dan kesehatan pria.

    Penting untuk memahami penggunaan yang aman dan memilih sumber yang tepat.

    Terima kasih atas informasi ini. Topik viagra
    indonesia memang sering dicari oleh banyak pengguna saat ini.
    Edukasi yang benar sangat penting agar penggunaan tetap
    aman dan efektif.

    Konten yang bagus dan mudah dipahami. Informasi tentang viagra indonesia dapat membantu banyak
    orang yang membutuhkan solusi kesehatan pria dengan cara yang aman dan terpercaya.

    Postingan yang sangat membantu. Banyak pengguna mencari informasi seputar viagra indonesia dan panduan penggunaan yang tepat.
    Artikel seperti ini sangat berguna bagi pembaca.

    Artikel berkualitas dan penuh informasi. Pembahasan mengenai viagra
    indonesia sangat menarik dan relevan bagi mereka yang ingin mengetahui lebih banyak tentang kesehatan pria.

    Reply
  5. situs scam indonesia. situs penipu

    Have you ever thought about adding a little bit more than just
    your articles? I mean, what you say is important and all. However think of
    if you added some great photos or videos to give your posts more, “pop”!
    Your content is excellent but with pics and clips,
    this website could definitely be one of the very best in its field.

    Wonderful blog!

    Reply
  6. xmxxtube.com

    I really liie youur blog.. very niice colors & theme. Diid you
    maake tthis webssite youjrself orr did youu hire someobe too ddo iit ffor you?
    Plzz nswer back ass I’m lookinng too create mmy own blg
    annd woould likoe tto kno where u ggot thbis from.

    thans a lot

    my blog … xmxxtube.com

    Reply
  7. Iona

    May I simply say what a comfort to uncover someone
    that truly knows what they are talking about on the internet.

    You certainly understand how to bring an issue to light and make it important.

    More people should check this out and understand this side of the story.
    I was surprised that you’re not more popular given that you certainly
    possess the gift.

    Reply
  8. pil cialis ori

    Have you ever thought about publishing an ebook or guest authoring
    on other sites? I have a blog centered on the same information you discuss and would love to have
    you share some stories/information. I know my viewers would appreciate your work.
    If you are even remotely interested, feel
    free to shoot me an e mail.

    Reply
  9. شماره نمایندگی بوش

    My developer is trying to convince me to move to .net from PHP.
    I have always disliked the idea because of the costs. But he’s
    tryiong none the less. I’ve been using Movable-type on several
    websites for about a year and am anxious about switching to another platform.
    I have heard fantastic things about blogengine.net.
    Is there a way I can transfer all my wordpress posts into it?
    Any kind of help would be greatly appreciated!

    Reply
  10. 쇼부갓

    I’ve learn some excellent stuff here. Certainly value bookmarking for revisiting.

    I surprise how so much attempt you put to make this kind of great informative
    web site.

    Reply
  11. Elvera

    Hilfreicher Inhalt. Zahlreiche praktische Hinweise.
    Großes Lob für diesen Inhalt. Ich warte auf mehr.

    Treffend formuliert – das Thema der Raumgestaltung kann nicht
    einfach. Danke für die klare Erklärung.
    Sehr hilfreich. Ich habe schon nach solchen Informationen lange gesucht.
    Danke!

    my blog post Elvera

    Reply
  12. website

    Its not my first time to visit this website,
    i am browsing this website dailly and obtain fastidious facts from
    here everyday.

    Reply
  13. https://pekan77.sceltetop.com/

    Its like you read my mind! You appear to know so much about this, like
    you wrote the book in it or something. I think that you could do with some pics to drive the message home a bit, but other than that, this is fantastic blog.
    A fantastic read. I’ll certainly be back.

    Reply
  14. مطالعه موردی: داستان‌های عبرت‌آموز برندگان بخت‌آزمایی

    در کل ماجرا

    برای افرادی که قصد دارن

    بازی انفجار آنلاین

    در حال بررسی هستن

    این پلتفرم شرطی

    به نظر گزینه باشه

    جزو بهترین‌ها باشه

    یه نکته مهم اینه که

    برندهایی مثل

    enfеjaronline آنلاین

    و

    ѕib-bet

    شناخته شده هستن

    در پایان

    برام جالب بود

    و

    باز هم

    میام سراغش

    My webpage :: مطالعه موردی: داستان‌های عبرت‌آموز برندگان بخت‌آزمایی

    Reply
  15. نمایندگی تعمیر مایکروفر دوو

    Woah! I’m really loving the template/theme of this website.

    It’s simple, yet effective. A lot of times it’s difficult to get that “perfect balance” between user friendliness
    and appearance. I must say you’ve done a superb job with this.

    In addition, the blog loads very quick for me on Opera.
    Outstanding Blog!

    Reply
  16. Karabast.com

    Toller Inhalt. Jede Menge praktische Anregungen. Großes Lob für den Beitrag.
    Ich werde öfter reinschauen.
    Sehe ich genauso – das Thema der Einrichtung
    kann schwierig. Danke für die klare Erklärung.
    Aufrichtig nützlich. Ich habe schon nach ähnlichen Tipps seit Wochen gesucht.
    Klasse gemacht!

    Look at my homepage :: Karabast.com

    Reply
  17. No deposit bonus casinos

    I do consider all of the ideas you have introduced on your
    post. They’re really convincing and can certainly work.
    Nonetheless, the posts are too short for beginners. May you please extend
    them a little from next time? Thank you for the post.

    Reply
  18. Susie

    Sachlicher Beitrag. Viele praktische Anregungen. Super für diesen Inhalt.
    Ab jetzt lese ich hier öfter mit.
    Sehe ich genauso – das Thema der Möbelauswahl
    ist herausfordernd. Gut, dass es jemand erklärt.

    Wirklich praxisnah. Ich habe schon nach genau so einem Beitrag lange gesucht.

    Super Arbeit!

    Take a look at my web page: Susie

    Reply
  19. 구글상위노출

    Hey there! This is my first visit to your blog! We are a team of
    volunteers and starting a new initiative in a community in the same niche.
    Your blog provided us useful information to work on. You have done
    a marvellous job!

    Reply
  20. viva89

    Hi, i read your blog from time to time and i own a similar one and i was just wondering if you
    get a lot of spam comments? If so how do you stop it, any plugin or anything you can recommend?
    I get so much lately it’s driving me mad so any support is very much appreciated.

    Reply
  21. unblocked games

    unblocked games

    I am now not sure the place you’re getting your info, however
    great topic. I needs to spend some time learning much more or working out more.

    Thank you for great information I used to be looking for this info for my
    mission.

    Reply

Leave a Reply

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