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

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

  1. 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
  2. slot777

    Attractive section of content. I just stumbled upon your website and
    in accession capital to assert that I acquire actually enjoyed account your blog posts.
    Any way I will be subscribing to your augment and even I achievement you access
    consistently quickly.

    Reply
  3. best online casinos

    Pretty component to content. I just stumbled upon your
    website and in accession capital to say that I acquire actually enjoyed account
    your blog posts. Anyway I’ll be subscribing in your feeds and even I fulfillment you access
    constantly rapidly.

    Reply
  4. viagra juice meaning

    For behind the wealthy and charming façade, lay
    a predatory rapist described in court as ‘every woman’s nightmare’ and ‘a wolf in sheep’s clothing’ who was prepared to take
    every step to silence his victims’ screams.

    Reply
  5. استراتژی‌های پیشرفته در تخته نرد آنلاین شرطی

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

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

    یکی از دوستای نزدیکم چند بار درباره سایت‌های شرطی صحبت کرده بود.
    همین موضوع باعث شد فقط سطحی رد
    نشم. از نظر من نکته مثبتش این بود که برای کسی که
    تازه با این فضا آشنا می‌شه قابل فهم بود.
    البته این به معنی تأیید کامل نیست.

    برای کسایی که می‌خوان قبل از تصمیم‌گیری دید
    بهتری داشته باشن، ارزش یک نگاه دقیق‌تر رو داره.

    در کنار این موضوع دامنه‌هایی مثل سایت enfejaronlіne در کنار برند sibbet نمونه‌هایی هستن که باعث می‌شن آدم بیشتر دنبال بررسی و
    مقایسه بره. چند وقت پیش با علیدرباره بازی انفجار
    حرف می‌زدیم و اون بیشتر دنبال این بود که
    بفهمه کدوم سایت‌ها توضیحات شفاف‌تری دارن.
    در مجموع برای شروع آشنایی بد نبود.
    از نظر من کسی که وارد این فضا
    می‌شه باید با دید باز و منطقی جلو بره.
    جمع‌بندی من اینه که تجربه بدی نبود و
    حداقل برای آشنایی اولیه ارزش وقت گذاشتن داشت، مخصوصاً اگر کسی بخواد قبل از تصمیم‌گیری دید بهتری پیدا کنه.

    My webpage استراتژی‌های پیشرفته در تخته نرد آنلاین شرطی

    Reply
  6. Rubah4d

    Hi there I am so delighted I found your website, I
    really found you by accident, while I was browsing on Askjeeve for something else,
    Anyways I am here now and would just like to say thanks a lot for a marvelous
    post and a all round exciting blog (I also love the theme/design), I don’t have time to read through it
    all at the minute but I have saved it and also added your RSS feeds,
    so when I have time I will be back to read a great deal more, Please do keep up
    the superb work.

    Reply
  7. excavation companies dallas

    naturally like your web-site however you need to check the spelling on quite
    a few of your posts. Several of them are rife with spelling issues and I find it very bothersome to tell the truth nevertheless I will surely come again again.

    Reply
  8. best online casinos

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

    Reply
  9. http://rouletteparsi.Info/

    در کل

    برای کاربرانی که دنبال تجربه
    هستن

    بازی انفجار

    دنبالشن

    این پلتفرم

    می‌تونه تبدیل بشه

    مناسب باشه

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

    سایت‌هایی مثل

    еnfejaronline.net

    و

    sibbet شناخته شده

    مطرحشدن

    به طور کلی

    مفید بود

    و

    باز هم

    مراجعه می‌کنم

    Lookk at my webpage … کاوش در کازینوی آنلاین و زنده کرد بت (http://rouletteparsi.Info/)

    Reply
  10. https://www.happyhomespg.in/author/wilfredo13s549/

    I was curious if you ever considered changing the layout of your website?
    Its very well written; I love what youve got to say.
    But maybe you could a little more in the way of content so people could connect with it better.
    Youve got an awful lot of text for only having 1 or two pictures.
    Maybe you could space it out better?

    Reply
  11. read more

    I think the admin of this website is actually working hard for his web site, because here
    every data is quality based material.

    Reply
  12. https://vape4sale.de

    Sweet blog! I found it while surfing around on Yahoo News.
    Do you have any tips on how to get listed in Yahoo News?
    I’ve been trying for a while but I never seem to get there!
    Appreciate it

    Reply
  13. 부산호빠

    Unquestionably imagine that that you stated. Your favourite reason appeared to be on the internet the simplest thing to be aware of.
    I say to you, I definitely get annoyed whilst other folks consider worries that they just
    don’t recognise about. You controlled to hit the nail upon the top and also defined out the whole thing without
    having side-effects , other people can take a signal.
    Will probably be again to get more. Thank you

    Reply
  14. burada

    IPhone kullanıcıları iPhone telefonlara Facebooktan video
    indirme işleminde zaman zaman problem yaşamaktadır.

    Reply
  15. best online casino nz

    Thank you pertaining to sharing the following great subject matter on your website. I ran into it on google. I am going to check to come back after you publish additional aricles.

    Reply
  16. najlepsze kasyna online

    I do not even know how I ended up here, but I thought this post was good. I do not know who you are but certainly you are going to a famous blogger if you are not already 😉 Cheers!

    Reply
  17. rape sex child

    Hello! I could have sworn I’ve visited this blog before but
    after looking at some of the posts I realized it’s new to me.
    Anyhow, I’m certainly happy I stumbled upon it and I’ll be book-marking it and checking back regularly!

    Reply
  18. Candy

    Hilfreicher Post. Jede Menge konkrete Anregungen. Großes Lob für den Beitrag.
    Ich speichere mir die Seite ab.
    Stimme zu – der Bereich der Einrichtung wird oft schwierig.
    Endlich mal Klartext.
    Aufrichtig inspirierend. Ich war schon nach so etwas seit Wochen gesucht.
    Viele Grüße!

    my blog post … Candy

    Reply
  19. website

    you are in point of fact a good webmaster.
    The website loading speed is incredible. It seems that you are doing any unique
    trick. Moreover, The contents are masterpiece.
    you’ve performed a fantastic job in this subject!

    Reply
  20. best online casino new zealand

    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
  21. najlepsze kasyna online

    I know this is not exactly on topic, but i have a blog using the blogengine platform as well and i’m having issues with my comments displaying. is there a setting i am forgetting? maybe you could help me out? thank you.

    Reply
  22. https://mobilebettingparsi.com/pooyan-mokhtari-arrest

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

    برای دوست‌داران

    بتینگ

    دنبال تجربه هستن

    این پلتفرم

    می‌تونه یکی از گزینه‌ها باشه

    مناسب باشه

    در ضمن

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

    enfeϳaronline آنلاین

    و

    sibbet جدید

    شناخته شدن در این حوزه

    در نهایت

    قابل قبول بود

    و

    قطعا

    مراجعه مجدد دارم

    Also viusіt my page کتک خوردن پویان مختاری
    در زندان (https://mobilebettingparsi.com/pooyan-mokhtari-arrest)

    Reply
  23. https://Unneaverse.com

    Hilfreicher Beitrag. Eine Menge praktische Inspirationen. Super
    fürs Teilen. Ich warte auf mehr.
    Volle Zustimmung – die Frage der Raumgestaltung kann schwierig.
    Hilfreicher Ansatz.
    Wirklich praxisnah. Ich habe schon nach genau so einem Beitrag
    genau danach gesucht. Danke!

    Stop by my blog post; https://Unneaverse.com

    Reply
  24. bokep

    We stumbled over here from a different page and thought I may as well check things out.
    I like what I see so now i’m following you. Look
    forward to exploring your web page repeatedly.

    Reply
  25. Shelly

    Toller Text. Jede Menge praktische Anregungen. Vielen Dank für den Beitrag.
    Ich werde öfter reinschauen.
    Genau – die Frage der Einrichtung wird oft herausfordernd.
    Endlich mal Klartext.
    Echt praxisnah. Ich suche schon nach ähnlichen Tipps lange gesucht.
    Klasse gemacht!

    Feel free to surf to my web site: Shelly

    Reply
  26. web site

    What’s Going down i’m new to this, I stumbled upon this I have found It absolutely
    helpful and it has aided me out loads. I’m hoping to give a contribution & aid different customers like its aided me.
    Great job.

    Reply
  27. information

    I’ve been exploring for a bit for any high quality articles or weblog posts on this kind of area .
    Exploring in Yahoo I ultimately stumbled upon this website.

    Reading this info So i am happy to exhibit that I have an incredibly good uncanny feeling I
    found out just what I needed. I so much surely will make
    sure to don?t fail to remember this site and give it a glance
    on a constant basis.

    Reply
  28. кракен ссылку где

    Howdy! I know this is kinda off topic however I’d figured I’d
    ask. Would you be interested in trading links or maybe guest authoring a blog article or vice-versa?

    My blog discusses a lot of the same topics as yours and I think we could greatly benefit from each other.
    If you are interested feel free to send me an email.
    I look forward to hearing from you! Terrific blog by the way!

    Reply

Leave a Reply

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