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

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

  1. 68GAMEBAI

    These are genuinely impressive ideas in about blogging.
    You have touched some fastidious points here. Any
    way keep up wrinting.

    Reply
  2. https://xoilac.guru/

    Xoilac là điểm đến lý tưởng cho những ai đam
    mê cá cược bóng đá thể thao với trải nghiệm tối ưu và dịch vụ chuyên nghiệp.
    Nhà cái này không chỉ nổi bật với tỷ lệ cược hấp
    dẫn mà còn mang đến giao diện trực tiếp link bóng đá
    mượt mà, giúp người chơi dễ dàng theo dõi và đặt cược hiệu quả.

    Reply
  3. bokep 18+

    Hello to all, how is everything, I think every one is getting more from this
    website, and your views are nice in support of new people.

    Reply
  4. Jada

    Hey! I know this is kind of off topic but I was wondering if you knew where I could find a captcha plugin for my comment form?
    I’m using the same blog platform as yours and I’m having problems finding one?
    Thanks a lot!

    Reply
  5. bokep anak sma

    I’m really enjoying the design and layout of your blog. 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 developer to create your theme?

    Exceptional work!

    Reply
  6. best online casino

    Beneficial Blog! I had been simply just debating that there are plenty of screwy results at this issue you now purely replaced my personal belief. Thank you an excellent write-up.

    Reply
  7. Panel Smm Djavapanel

    Please let me know if you’re looking for a article writer for your blog.
    You have some really good posts and I feel I would be a
    good asset. If you ever want to take some of the load off, I’d really like to write some content for your blog in exchange for a link back
    to mine. Please blast me an e-mail if interested. Many thanks!

    Reply
  8. Jeetking

    JeetKing
    is Pakistan’s
    fastest-growing
    online casino platform,
    offering a complete library of
    engaging
    slot games.
    Gaming fans across South Asia
    trust JeetKing
    for its instant withdrawals and fair gameplay.

    Reply
  9. سوالات متداول (faq)

    نتیجه‌گیری اینکه

    برای اون دسته علاقه‌مندها

    پیش‌بینی مسابقات

    کار می‌کنن

    این مرجع

    به سادگی می‌تونه

    مفید واقع بشه

    نکته قابل توجه اینه که

    سرویس‌هایی مثل

    enfeјaronline معتبر

    و

    sibbet اصلی

    توسعه پیدا کردن

    در پایان

    خوشم اومد

    و

    باز هم

    حتما برمی‌گردم

    Also νisit my page :: سوالات متداول (faq)

    Reply
  10. review

    I was suggested this web site by my cousin.
    I am not sure whether this post is written by
    him as nobody else know such detailed about
    my difficulty. You’re incredible! Thanks!

    Reply
  11. online casino

    I don’t know if it’s just me or if everybody else experiencing issues with your site. It appears as though some of the written text on your content are running off the screen. Can someone else please provide feedback and let me know if this is happening to them as well? This could be a problem with my web browser because I’ve had this happen before. Appreciate it

    Reply
  12. https://bet303review.com

    سلام،من امروز وسط وبگردی در اینترنت با این وبسایت رسیدم و
    واقعا خیلی خوشم اومد. اطلاعاتش جذاب بود وبه ندرت همچین سایتی ببینم.
    فکر کنم برای خیلی‌ها کاربردی باشه.
    اگر به دنبال محتوای مفید هستن
    حتما سر بزنن. در مجموع تجربه خوبی بود و قطعا بازدیدش می‌کنم

    در آخر کار

    برای اون دسته که

    بتینگ

    میخوان امتحان کنن

    این مجموعه آنلاین

    کاملا میتونه

    کمک‌کننده باشه

    جالب‌تر اینکه

    دامنه‌هایی مثل

    enfejaronline حرفه‌ای

    و

    sibbet قوی

    مطرح شدن

    در نهایت

    مفید بود

    و

    در ادامه

    استفاده دوباره میکنم

    .

    Feel frere to visit my page; سوختن ریز در پوکر یعنی چه؟ (https://bet303review.com)

    Reply
  13. No deposit bonus casinos

    Hello, i think that i saw you visited my website so i came to return the desire?.I’m attempting to find
    things to improve my site!I assume its good enough to
    use some of your ideas!!

    Reply
  14. https://Cutdb.Hanfzentrale.com/index.php?title=Benutzer:EmoryHoss75020

    Hilfreicher Beitrag. Reichlich wertvolle Anregungen.
    Großes Lob dass du dein Wissen teilst. Ab jetzt lese ich hier öfter mit.

    Stimme zu – die Frage der Einrichtung ist herausfordernd.
    Danke für die klare Erklärung.
    Echt nützlich. Ich suche schon nach ähnlichen Tipps seit Wochen gesucht.
    Klasse gemacht!

    Feel free to visit my webpage; https://Cutdb.Hanfzentrale.com/index.php?title=Benutzer:EmoryHoss75020

    Reply
  15. buy mdma online

    Very nice post. I just stumbled upon your weblog and wished to say
    that I’ve truly enjoyed surfing around your blog posts.
    In any case I will be subscribing to your rss feed and
    I hope you write again soon!

    Reply
  16. Dane

    Klasse Artikel. Eine Menge praktische Hinweise. Danke fürs Teilen. Ich komme bestimmt wieder
    vorbei.
    Du hast recht – die Frage der Wohnungsgestaltung ist nicht einfach.
    Danke für die klare Erklärung.
    Aufrichtig hilfreich. Ich habe schon nach genau so einem
    Beitrag genau danach gesucht. Super Arbeit!

    Have a look at my webpage; Dane

    Reply
  17. Jordan

    It’s in reality a nice and useful piece of info. I am satisfied that you shared this helpful information with
    us. Please stay us informed like this. Thanks for sharing.

    Reply
  18. Benjamin

    Interessanter Text. Zahlreiche konkrete Inspirationen. Vielen Dank für diesen Inhalt.
    Ich speichere mir die Seite ab.
    Treffend formuliert – die Frage der Wohnungsgestaltung ist anspruchsvoll.

    Endlich mal Klartext.
    Echt inspirierend. Ich habe schon nach ähnlichen Tipps lange gesucht.
    Viele Grüße!

    Here is my website; Benjamin

    Reply
  19. تعمیر ماکروفر غرب تهران

    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 can do with a few pics to drive the
    message home a bit, but instead of that, this
    is magnificent blog. A great read. I’ll definitely be back.

    Reply
  20. bokep ibu ibu indonesia

    I would like to thank you for the efforts you have put in writing this site.
    I really hope to check out the same high-grade
    blog posts from you later on as well. In fact, your creative writing abilities has inspired me to get my own website now ;
    )

    Reply
  21. Polyhedra in computer programming education

    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
  22. review

    I know this site provides quality depending articles and
    other stuff, is there any other site which provides such data in quality?

    Reply
  23. https://Bhakticourses.com

    Toller Beitrag. Eine Menge nützliche Tipps. Großes Lob für
    die Mühe. Ich empfehle die Seite gerne weiter.
    Stimme zu – der Bereich der Wohnungsgestaltung wird oft nicht einfach.
    Endlich mal Klartext.
    Wirklich praxisnah. Ich habe schon nach genau so einem Beitrag genau danach gesucht.

    Super Arbeit!

    my webpage: https://Bhakticourses.com

    Reply

Leave a Reply

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