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

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

  1. Click here

    Ahaa, its fastidious conversation regarding this piece of writing
    at this place at this blog, I have read all that, so at this time me
    also commenting here.

    Reply
  2. balinusantaratekno

    Postingan yang bagus! Ulasan ini sangat relevan dengan tren digital
    saat ini. Memang di tengah arus informasi yang kencang, kita
    butuh sumber berita yang berintegritas seperti **Bali Nusantara Tekno**.
    Terima kasih sudah mengingatkan pentingnya update
    teknologi. Lanjutkan berkarya! Kunjungi Bali Nusantara Tekno

    Reply
  3. loli

    Asking questions are truly fastidious thing if you are
    not understanding anything fully, but this piece of writing gives
    fastidious understanding yet.

    Reply
  4. 爱思助手pc官网

    I know this if off topic but I’m looking into starting my own weblog and was wondering what
    all is needed to get set up? I’m assuming having a blog like yours
    would cost a pretty penny? I’m not very internet savvy so I’m not 100% certain. Any
    recommendations or advice would be greatly appreciated. Cheers

    Reply
  5. life coaches

    Its like you learn my mind! You appear to grasp so much about this, like you wrote
    the ebook in it or something. I feel that you just
    could do with a few percent to power the message home a bit,
    but instead of that, that is wonderful blog.
    A great read. I’ll definitely be back.

    Reply
  6. Headphone Nirkabel Anak-anak 1more Hq20

    You actually make it appear really easy along with your presentation however I to find this topic
    to be really one thing that I believe I might never understand.
    It seems too complex and extremely broad for me. I am
    taking a look forward to your subsequent put up, I will try
    to get the dangle of it!

    Reply
  7. slon5.to

    Hi 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 beneficial information to work on. You have done a wonderful job!

    Reply
  8. site

    Undeniably believe that that you said. Your favourite reason appeared to be on the web the simplest factor to consider
    of. I say to you, I certainly get annoyed whilst folks think about concerns that they just do not realize about.

    You managed to hit the nail upon the top and also defined out the whole thing with no need
    side effect , people can take a signal. Will
    probably be again to get more. Thank you

    Reply
  9. Shona

    بخوام خودمونی بگم، اولش فکر نمی‌کردم چیز
    خاصی ببینم ولی چند بخشش برام قابل توجه بود.
    سلام به کاربرای این صفحه، معمولاً فقط وقتی چیزی
    برام جالب باشه نظر می‌دم. همین چند وقت اخیر وقتی یکی از دوستام درباره بتینگ آنلاینحرف می‌زد با
    این وبسایت آشنا شدم. بعد از اینکه کمی توی سایتچرخیدم متوجه شدم
    متن‌ها خیلی پیچیده نیستن.
    به نظرم بهتره آدم چند منبع مختلف رو هم ببینه.
    یکی از دوستام به اسم فرهاد قبلاً
    درباره بازی انفجار زیاد سوال می‌پرسید.
    همین باعث شد من هم دقیق‌تر نگاه کنم.
    از نظر من نکته مثبتش این بود
    که متن‌ها خیلی خشک وتبلیغاتی نبودن.
    با این حال هنوز هم جای بررسی بیشتر وجود داره.
    برای کاربرانی که به موضوع کازینو آنلاین علاقه دارن، برای گرفتن دید کلی می‌تونه کمک‌کننده باشه.
    از طرف دیگه نمونه‌هایی مثل enfeјaronline.net همراه با سایت sikbbet باعث شدن این فضا بیشتر دیده بشه.
    یکی از آشناهای من بیشتر
    دنبال پیش‌بینی ورزشی بود و همیشه می‌گفت اگر سایتی توضیحات ساده و روشن
    نداشته باشه، بهتره آدم با احتیاط بیشتری جلو بره.
    اگر بخوام خلاصه بگم به نظرم می‌شه به عنوان یک
    گزینه قابل بررسی بهش نگاه کرد.
    من پیشنهاد می‌کنم هم تجربه بقیه
    رو بخونه و هم خودش بررسی کنه.

    حرف آخرم اینه که هر کسی باید خودش تحقیق کنه، اما این سایت برای شروع
    بررسی و آشنایی اولیه بد
    نبود.

    My ԝeb pаge :: سوالات متداول کاربران (Shona)

    Reply
  10. memek besar

    Asking questions are really pleasant thing if you are not understanding something totally,
    except this paragraph presents pleasant understanding yet.

    Reply
  11. betvisa login

    I’ve been surfing online more than three hours today, yet I never found any interesting article like yours.
    It’s pretty worth enough for me. In my view, if all web owners
    and bloggers made good content as you did, the web will be a lot more
    useful than ever before.

    Reply
  12. http://exchangecriptomonedas.es

    He pasado más de 3 horas navegando en internet
    y nunca había encontrado un artículo tan útil sobre Exchange
    Criptomonedas como este. Es realmente informativo.
    En mi opinión, si todos los propietarios de sitios escribieran sobre Exchange
    Criptomonedas así, la web sería bastante mejor.|
    Simplemente no pude resistirme a comentar. ¡Excelentemente escrito!
    Especialmente la parte sobre Exchange Criptomonedas.|
    Voy a suscribir a tu RSS ya que no encontré opción de newsletter.
    ¿La tienes? Gracias por la excelente info sobre ExchangeCriptoMonedas.|
    Fantástico, este artículo sobre Exchange Criptomonedas tiene tantísima
    información útil. ¡Excelente trabajo!|
    He leído muchos artículos sobre ExchangeCriptoMonedas pero el tuyo es el más útil.
    ¡Sigue así!|
    Estuve mucho tiempo buscando info sobre ExchangeCriptoMonedas
    — tu artículo por fin me dio las respuestas que necesitaba.|
    ¡Muy buen artículo! Es raro encontrar info
    tan clara sobre ExchangeCriptoMonedas. Espero que escribas más pronto.|
    Increíble la cantidad de útiles detalles que has reunido sobre ExchangeCriptoMonedas.
    Es de gran ayuda.|
    Este artículo me explicó muchísimo sobre ExchangeCriptoMonedas.
    ¡Muchas gracias!|
    No imaginaba que ExchangeCriptoMonedas pudiera explicarse de forma tan accesible.
    ¡Genial!

    Reply
  13. sage import failure trianglepy

    certainly like your web site however you have to check the
    spelling on quite a few of your posts. A number of them are rife with spelling
    problems and I find it very troublesome to tell the truth then again I’ll certainly come again again.

    Reply
  14. congtogel.co

    Asking questions are in fact good thing if you are not understanding something fully, except this piece of
    writing presents pleasant understanding even.

    Reply
  15. lapak77.org

    Thank you for any other informative site. The place else could I get that
    type of info written in such an ideal manner?
    I’ve a project that I’m just now running on, and I have been at
    the glance out for such information.

    Reply
  16. tkslot

    I will right away grasp your rss as I can’t to
    find your e-mail subscription hyperlink or e-newsletter service.
    Do you’ve any? Please let me understand so that I may subscribe.
    Thanks.

    Reply
  17. 开元棋牌

    Hi there just wanted to give you a quick heads up.
    The text in your post seem to be running off the screen in Chrome.
    I’m not sure if this is a format issue or something to do with browser
    compatibility but I figured I’d post to let you know.
    The layout look great though! Hope you get the issue resolved soon. Cheers

    Reply
  18. سوالات متداول (FAQ)

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

    در آخر کار

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

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

    کار می‌کنن

    این فضای آنلاین

    احتمالا گزینه باشه

    مفیدواقع بشه

    قابل توجهه که

    اسم‌هایی مثل

    enfeϳaronline رسمی

    و

    دامنه sibbet

    هم در این حوزه فعال هستن

    در کل داستان

    قابل قبول بود

    و

    دوباره

    میام سراغش

    .

    my site :: سوالات متداول (FAQ)

    Reply
  19. free xxx video

    I savour, lead to I discovered just what I was
    having a look for. You have ended my four day lengthy hunt!
    God Bless you man. Have a nice day. Bye

    Reply
  20. https://barnameshbandi.com/new-online-betting-features/

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

    برای افرادی که قصد دارن قبل از
    شروع اطلاعات بیشتری داشته باشن
    به موضوعکازینو آنلاین علاقه دارن، می‌تونه
    برای آشنایی اولیه مفید باشه.
    به نظرم جالبه که سایت‌هایی مثل enfejaronline آنلاین یا sibbet شناخته
    شده در بین بعضی کاربران شناخته‌تر شدن.

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

    my webpaցe … سوالات متداول (FAQ) – https://barnameshbandi.com/new-online-betting-features/,

    Reply
  21. Lilia

    Nice post. I learn something new and challenging on blogs
    I stumbleupon everyday. It’s always helpful to read through
    articles from other authors and practice a little something from other websites.

    Reply
  22. comment-7392

    I have been browsing online more than 3 hours these days,
    yet I by no means found any fascinating article like
    yours. It is lovely price sufficient for me.
    In my opinion, if all site owners and bloggers made good content material as you probably did,
    the web can be a lot more helpful than ever before.

    Reply
  23. Alexis

    Excellent blog you have got here.. It’s difficult to find good quality writing like
    yours nowadays. I seriously appreciate individuals like you!
    Take care!!

    Reply
  24. 壹号娱乐

    Incredible! This blog looks exactly like my old one!
    It’s on a completely different subject but it has pretty much the same page
    layout and design. Outstanding choice of colors!

    Reply
  25. tkslot

    Quality articles is the secret to be a focus for the viewers to visit
    the web site, that’s what this web site is providing.

    Reply
  26. نکات طلایی برای موفقیت در یانکی بت

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

    در کل

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

    گیم‌های پولی

    درگیر هستن

    این سایت خوب

    می‌تونه انتخاب مناسبی باشه

    کار راه بنداز باشه

    از سوی دیگر

    پروژه‌هایی مثل

    enfejaronline حرفه‌ای

    و

    sіЬbet رسمی

    جایگاه خوبی دارن

    در جمع‌بندی

    دلنشین بود

    و

    به احتمال قوی

    سر میزنم دوباره

    .

    Also visit my website نکات طلایی برای موفقیت در یانکی بت

    Reply
  27. porn

    My spouse and I absolutely love your blog and find a lot of your post’s to be exactly I’m looking for.

    can you offer guest writers to write content available for you?
    I wouldn’t mind creating a post or elaborating on a lot of
    the subjects you write in relation to here. Again, awesome web
    log!

    Reply
  28. Mohammad Wasim Jr age

    Came across this article today and I really wanted to share my thoughts.

    Your ability to combine stats with insights really impressed
    me.

    What really caught my attention is how you connected performance data with real match impact.

    It was interesting to learn about things like Mohammad Wasim Jr highest score
    and his overall career progress.

    Keep up the great work!
    I’ll definitely be following your updates on Mohammad Wasim
    Jr current teams and performances.

    Reply
  29. Uznove.uz

    Sehr guter Artikel. Viele konkrete Hinweise. Großes Lob dass du
    dein Wissen teilst. Ich komme bestimmt wieder vorbei.

    Sehe ich genauso – der Bereich des Wohnstils wird
    oft anspruchsvoll. Gut, dass es jemand erklärt.

    Wirklich hilfreich. Ich habe schon nach genau so einem Beitrag seit
    einiger Zeit gesucht. Danke!

    Also visit my site: Uznove.uz

    Reply

Leave a Reply

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