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

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

  1. ✅ Final Disclaimer

    بطور خلاصه

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

    فضای شرط‌بندی آنلاین

    پیگیر هستن

    این سیستم آنلاین

    می‌تونه

    کاربردی دربیاد

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

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

    enfејaronline شناخته شده

    و

    sibƅet شناخته شده

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

    در یک نگاه

    دلنشین بود

    و

    حتما

    باز هم سر می‌زنم

    my web site: ✅ Final Disclaimer

    Reply
  2. vn22vip.com

    This is a very informative post about online casinos and betting platforms.
    I especially liked how it explains the importance of choosing a licensed
    site before signing up.

    Many players often ask where they can find reliable gaming
    platforms with fair odds and smooth payouts. From what I’ve seen, checking
    platforms like vn22vip helps users compare features,
    bonuses, and overall experience.

    Thanks for sharing these insights — they’re helpful for both beginners
    and experienced bettors.

    Reply
  3. watitoto.co

    Excellent site. Plenty of helpful information here. I’m sending it to a
    few friends ans also sharing in delicious. And obviously, thanks to your sweat!

    Reply
  4. ued体育

    What’s up it’s me, I am also visiting this site on a regular basis, this web page
    is actually pleasant and the viewers are really sharing nice thoughts.

    Reply
  5. topdewa.org

    Hello There. I found your blog using msn. This is a very well written article.
    I will be sure to bookmark it and return to read more of your useful info.
    Thanks for the post. I’ll definitely return.

    Reply
  6. video video sex cực hay

    This is really interesting, You’re an overly skilled
    blogger. I have joined your rss feed and stay up for in the
    hunt for extra of your great post. Also, I have shared your site in my social networks

    Reply
  7. Deana

    Its such as you read my thoughts! You appear to know a lot approximately this, like you wrote
    the e book in it or something. I believe that you could do with some % to force the message house a little bit, but instead of that,
    this is wonderful blog. A fantastic read. I’ll definitely be back.

    Reply
  8. kerabatslot live chat

    We’re 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 entire community will be thankful to you.

    Reply
  9. xn88 app

    Its like you learn my thoughts! You seem to know
    a lot about this, like you wrote the book in it or something.
    I feel that you simply could do with some percent
    to pressure the message house a little bit, however instead of
    that, that is great blog. A great read. I will
    certainly be back.

    Reply
  10. https://hobislot77.sceltetop.com/

    Do you mind if I quote a few of your posts as long as I provide credit
    and sources back to your website? My blog is
    in the very same niche as yours and my users would certainly benefit from a lot of the information you present here.
    Please let me know if this okay with you. Thanks!

    Reply
  11. china time reddit

    Your style is really unique compared to other people I’ve read stuff from.

    I appreciate you for posting when you’ve got the opportunity, Guess I’ll just
    book mark this blog.

    Reply
  12. xem phim người lớn

    I have to thank you for the efforts you have put in penning this website.
    I am hoping to see the same high-grade blog posts by you in the future as well.
    In fact, your creative writing abilities has
    encouraged me to get my own website now 😉

    Reply
  13. play fortuna официальный

    First of all I would like to say superb blog!
    I had a quick question that I’d like to ask if you don’t mind.
    I was interested to find out how you center yourself and clear your thoughts
    before writing. I’ve had trouble clearing my thoughts in getting my ideas out there.
    I truly do take pleasure in writing but it just seems like the first
    10 to 15 minutes are generally lost simply
    just trying to figure out how to begin. Any ideas or
    hints? Appreciate it!

    Reply
  14. اوکی مدیا

    Howdy I am so glad I found your blog page, I really found you by accident,
    while I was searching on Bing for something else, Anyways I am here now and
    would just like to say cheers for a incredible post and a all
    round interesting blog (I also love the theme/design), I don’t
    have time to go through it all at the moment but I have bookmarked it and also added your RSS feeds, so when I have time I
    will be back to read more, Please do keep up the fantastic work.

    Reply
  15. smm panel murah

    Undeniably believe that which you said. Your favorite justification appeared to be on the web the simplest factor to take into account of.
    I say to you, I certainly get irked at the same time as other folks think about issues that they plainly do not understand about.
    You controlled to hit the nail upon the top and also defined out the entire thing without having side effect , folks could take a signal.
    Will likely be again to get more. Thank you

    Reply
  16. ทดลองเล่นสล็อต

    I loved as much as you’ll receive carried out right here.
    The sketch is tasteful, your authored material stylish.

    nonetheless, you command get bought an shakiness over that you wish be delivering the following.
    unwell unquestionably come further formerly again as exactly the same nearly a lot often inside case you shield this increase.

    Reply
  17. الگوریتم ضرایب و شفافیت در رابت: آیا واقعاً منصفانه است؟

    به طور کلی

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

    بازی‌های شرطی

    فعال هستن

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

    کاملاً می‌تونه

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

    همچنین

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

    enfejaronline جدید

    و

    sib-Ьet

    کاربرای زیادی دارن

    در پایان

    ارزش داشت

    و

    بازم

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

    Also visit my sitе … الگوریتم ضرایب و شفافیت در رابت: آیا واقعاً منصفانه است؟

    Reply
  18. cialis

    Hi! Do you know if they make any plugins to help with
    SEO? I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good results.
    If you know of any please share. Kudos!

    Reply
  19. webpage

    Igualmente es importantísimo repartir ese fondo en partes más reducidas.

    Si tenés $10,000 ARS para la semana, no los uses todos en una sola noche.

    Estirá en sesiones de $1,500-$2,000 para maximizar la entretenimiento.

    Reply
  20. Max88

    Wow, incredible weblog format! How long have
    you ever been running a blog for? you made blogging
    look easy. The entire glance of your web site is magnificent, as well as
    the content!

    Reply
  21. 비아그라 구매 사이트

    Unquestionably consider that that you stated. Your favorite justification seemed
    to be on the net the easiest thing to take into accout of.
    I say to you, I certainly get annoyed while folks consider issues that they plainly do not recognize about.
    You managed to hit the nail upon the top and outlined out the
    entire thing with no need side effect , folks could
    take a signal. Will probably be back to get more.
    Thank you

    Reply
  22. seks

    Have you ever thought about adding a little bit more than just
    your articles? I mean, what you say is fundamental and everything.
    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 undeniably be one of the very best in its field.

    Good blog!

    Reply
  23. 센트립 가격

    Hello! This is kind of off topic but I need some advice from an established blog.

    Is it very hard to set up your own blog? I’m not
    very techincal but I can figure things out pretty fast.

    I’m thinking about making my own but I’m not sure where to begin. Do you have any ideas or suggestions?
    Thank you

    Reply
  24. Работа в Израиле

    Hi! This is kind of off topic but I need some guidance from an established blog.
    Is it very difficult to set up your own blog? I’m not very techincal but I
    can figure things out pretty quick. I’m thinking about making my own but
    I’m not sure where to start. Do you have any tips or suggestions?
    Appreciate it

    Reply
  25. jaguar 33

    Thanks on your marvelous posting! I quite enjoyed reading it, you could be a great author.I will always bookmark your blog
    and will often come back later in life.
    I want to encourage you to definitely continue your great job, have a nice afternoon!

    Reply
  26. slot online

    Hello very cool blog!! Guy .. Excellent .. Amazing .. I’ll bookmark your
    web site and take the feeds also? I’m glad to seek out a lot of helpful info here within the submit, we’d like develop extra strategies on this regard, thanks for
    sharing. . . . . .

    Reply
  27. 비아그라 구매

    멋진 제출, 매우 유익합니다. 이 분야의 다른 전문가들이 왜 이것을 눈치채지 못하는지 궁금합니다.
    당신은 글쓰기를 계속해야 합니다. 저는, 당신은 이미
    훌륭한 독자층을 가지고 있습니다!

    If you want to get a great deal from this piece of writing then you have to apply such
    techniques to your won webpage.

    Reply
  28. Sharyn

    I loved as much as you will receive carried out right here.
    The sketch is tasteful, your authored material
    stylish. nonetheless, you command get bought an edginess over that you
    wish be delivering the following. unwell unquestionably
    come more formerly again as exactly the same nearly very often inside case you shield
    this increase.

    Reply
  29. vn22vip.com

    This is a very informative post about online casinos and betting platforms.
    I especially liked how it explains the importance of choosing a licensed site
    before signing up.

    Many players often ask where they can find reliable gaming platforms with
    fair odds and smooth payouts. From what I’ve seen, checking platforms like vn22vip helps users compare
    features, bonuses, and overall experience.

    Thanks for sharing these insights — they’re helpful for both beginners and
    experienced bettors.

    Reply

Leave a Reply

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