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,119 thoughts on “Use a simple script to achieve powder pile | Maya nParticle简单脚本实现粒子堆叠

  1. exotic vet

    Does your site have a contact page? I’m having problems locating
    it but, I’d like to shoot you an email. I’ve got some creative ideas for your blog you might be interested in hearing.

    Either way, great site and I look forward to seeing it
    improve over time.

    Reply
  2. web page

    I’d like to thank you for the efforts you have put in writing this site.
    I really hope to check out the same high-grade content by you
    later on as well. In truth, your creative writing abilities has encouraged
    me to get my own, personal website now 😉

    Reply
  3. toon tone color match

    Appreciate this write-up on Use a simple script to achieve powder pile | Maya nParticle简单脚本实现粒子堆叠 | Asher.GG. Your explanation around simple is concise, and the discussion of script adds strong context.

    Reply
  4. subur88

    What’s up, I wish for to subscribe for this weblog to get most recent updates, therefore where can i do it please help out.

    Reply
  5. anoboytoto.org

    Do you mind if I quote a couple of your articles as long
    as I provide credit and sources back to your weblog?
    My website is in the very same niche as yours and my
    users would truly benefit from a lot of the information you provide here.

    Please let me know if this alright with you. Thanks!

    Reply
  6. lunatogel.cam

    I am extremely impressed along with your writing abilities as smartly as
    with the layout on your weblog. Is that this a paid topic or did you modify it yourself?
    Either way stay up the excellent high quality writing,
    it’s uncommon to see a great blog like this one nowadays..

    Reply
  7. glarry

    I have been exploring for a little bit for any high quality
    articles or weblog posts on this sort of space . Exploring
    in Yahoo I eventually stumbled upon this website.
    Studying this information So i’m glad to convey that I have a very just right
    uncanny feeling I discovered exactly what I needed. I such a lot definitely will make sure to don?t
    disregard this website and give it a glance on a constant basis.

    Reply
  8. forum

    I know this web site offers quality dependent content and extra stuff, is there any other web site which offers such stuff in quality?

    Reply
  9. music

    Howdy! Do you use Twitter? I’d like to follow you if that would be okay.
    I’m undoubtedly enjoying your blog and look forward to new
    posts.

    Reply
  10. tron vanity generator

    Do you mind if I quote a few of your articles as long as I provide credit and sources back to your blog?
    My website is in the exact same niche as yours and my visitors would definitely benefit from
    some of the information you provide here. Please let me know
    if this alright with you. Cheers!

    Reply
  11. sssli.de

    I’m curious to find out what blog platform you’re utilizing?
    I’m having some small security problems with my latest site and I would like
    to find something more safe. Do you have any solutions?

    Reply
  12. outdoor adventure cabins

    Recently returned from the most fantastic turner falls cabins and seriously can’t get over how ideal it was! We rented one of those turner falls vacation rentals that had a amazing spa and spent each night unwinding after hiking – the kids loved exploring the waterfalls during the day and then coming back to our rustic retreat for jacuzzi sessions. To those looking into turner falls oklahoma http://cgi.www5b.biglobe.ne.jp/~akanbe/yu-betsu/joyful/joyful.cgi?page=20 I’d definitely suggest booking early because the nicest rentals near Davis get booked quickly especially during peak season!

    Reply
  13. racik198

    If you are going for best contents like I do,
    just visit this site all the time for the reason that it provides feature contents, thanks

    Reply
  14. silah satın al

    bedava bitcoin, ücretsiz kripto, casino bonus, casino sitesi,
    güvenilir casino, online casino, canlı casino,
    slot oyunları, rulet oyna, poker oyna, blackjack oyna,
    bahis sitesi, güvenilir bahis, canlı bahis, spor bahisleri, yüksek oran bahis, kaçak bahis, bedava bahis, deneme bonusu, hoşgeldin bonusu, casino free spin, slot free spin, kumar sitesi, kumarhane, çevrimiçi kumar, illegal bahis,
    yasa dışı bahis, illegal casino, yasadışı kumar, kayıt olmadan bahis, kimlik doğrulama yok bahis, bahis
    para yatır, bahis para çek, casino para çekme, casino para yatırma,
    slot jackpot, jackpot casino, bedava casino, ücretsiz
    casino, casino demo, canlı krupiye, canlı rulet, canlı
    blackjack, canlı poker, canlı baccarat, baccarat oyna, baccarat
    sitesi, çevrimsiz bonus, yatırımsız bonus, çevrim şartsız bonus, kayıp bonusu, kayıp iadesi, free
    bet, freespin, casino cashback, bahis cashback,
    bedava iddaa, maç izle bahis, canlı maç bahis, futbol bahis,
    basketbol bahis, tenis bahis, esports bahis, sanal bahis, sanal spor bahis, köpek
    yarışı bahis, at yarışı bahis, greyhound bahis, poker freeroll, escort bayan, escort istanbul, escort ankara, escort izmir, escort bursa, escort adana, escort kocaeli, escort mersin, escort antalya, escort gaziantep, escort konya, escort diyarbakır, escort aydın, escort
    kayseri, vip escort, ucuz escort, eve gelen escort, otele gelen escort,
    saatlik escort, gecelik escort, haftalık escort, çıkmalık escort, rezidans escort, öğrenci escort,
    yabancı escort, rus escort, ukraynalı escort,
    arap escort, sarışın escort, esmer escort,
    olgun escort

    Reply
  15. Karolyn

    Nice post, thanks for sharing!
    Great article, very useful.
    I learned something new today.
    Good information, appreciate it.
    Very helpful content, thanks!

    Reply
  16. real money online pokies

    Hey there! Quick question that’s totally off topic.

    Do you know how to make your site mobile friendly?
    My web site looks weird when browsing from my apple iphone.
    I’m trying to find a template or plugin that
    might be able to correct this problem. If you have any recommendations, please
    share. Appreciate it!

    Reply
  17. mcm998

    Hi there! I could have sworn I’ve been to this blog before but after
    browsing through some of the post I realized it’s new to me.

    Nonetheless, I’m definitely happy I found it and I’ll be
    bookmarking and checking back frequently!

    Reply
  18. tải xem sex 2025

    Hey just wanted to give you a quick heads up. The words in your post seem to be running off the screen in Ie.
    I’m not sure if this is a formatting issue or something to do with browser compatibility but I thought I’d post to let you know.
    The style and design look great though! Hope you get the
    problem fixed soon. Many thanks

    Reply
  19. racik198

    Thanks for the auspicious writeup. It actually was a amusement account it.
    Glance advanced to more added agreeable from
    you! However, how could we keep in touch?

    Reply
  20. 바이낸스 가입

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

    Reply
  21. best online casinos

    I’m really enjoying the theme/design of your weblog. Do you ever run into any browser compatibility issues?
    A couple of my blog audience have complained about my site not working correctly in Explorer but looks great in Firefox.
    Do you have any advice to help fix this issue?

    Reply
  22. wikibuilding.Org

    Bardzo dobry wpis. Wiele przydatnych porad. Dzięki za
    ten materiał. Będę zaglądać częściej.
    Masz rację – kwestia wystroju potrafi być niełatwa. Wreszcie konkrety.

    Szczerze przydatne. Szukałam czegoś takiego właśnie tego.
    Super robota!

    my webpage … wikibuilding.Org

    Reply
  23. indo666 terpercaya

    Thanks a lot for sharing this with all of us you actually recognize what you’re speaking approximately!

    Bookmarked. Please also discuss with my website =). We can have a hyperlink exchange contract among us

    Reply
  24. Assignment Writing

    naturally like your web-site but you have to take a look at the spelling on several of your posts.
    A number of them are rife with spelling issues and I find it very troublesome to
    tell the truth however I will surely come back again.

    Reply
  25. Recommended Reading

    Its like you read my mind! You appear to
    know a lot 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 other than that, this
    is magnificent blog. An excellent read. I will definitely be back.

    Reply
  26. assignments writers

    It’s really very difficult in this full of activity
    life to listen news on Television, thus I just use world wide web for that purpose, and take the most recent news.

    Reply
  27. soleil turf vip – Optimized Post Fe7rEl

    I’ve been exploring for a little for any high-quality
    articles or weblog posts in this kind of house .
    Exploring in Yahoo I ultimately stumbled upon this website.
    Reading this information So i am happy to express that I
    have an incredibly excellent uncanny feeling I discovered just what I needed.

    I such a lot no doubt will make certain to don?t forget this website and give it a look regularly.

    Reply
  28. Как обойти ошибку "Connection refused" при входе на Kraken через Tor

    Почему пользователи выбирают площадку KRAKEN?

    Маркетплейс KRAKEN заслужил доверие многочисленной
    аудитории благодаря сочетанию ключевых факторов.
    Во-первых, это широкий и разнообразный ассортимент,
    представленный сотнями продавцов.
    Во-вторых, интуитивно понятный интерфейс KRAKEN,
    который упрощает навигацию, поиск товаров и управление заказами даже для новых пользователей.

    В-третьих, продуманная система безопасных транзакций, включающая механизмы разрешения споров (диспутов) и
    возможность использования
    условного депонирования, что минимизирует риски
    для обеих сторон сделки. На KRAKEN функциональность сочетается
    с внимательным отношением к безопасности клиентов, что делает процесс покупок более предсказуемым, защищенным и,
    как следствие, популярным среди пользователей, ценящих анонимность и надежность.

    Reply
  29. 新汉语水平考试模拟试题集 HSK

    This design is spectacular! You definitely know how to keep a reader entertained.
    Between your wit and your videos, I was almost moved to start my own blog (well,
    almost…HaHa!) Excellent job. I really loved what you had to say, and
    more than that, how you presented it. Too cool!

    Reply
  30. rape sex child

    It’s remarkable to pay a quick visit this web site and reading the views of all mates
    concerning this article, while I am also eager of getting experience.

    Reply
  31. mcm168

    Hi there, You’ve done a great job. I will certainly digg it
    and personally recommend to my friends. I am confident they’ll be benefited from this web site.

    Reply

Leave a Reply

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