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

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

  1. kedai tayar near me open now

    Having read this I believed it was very informative.
    I appreciate you finding the time and energy
    to put this article together. I once again find myself spending a significant amount of time both reading and posting comments.
    But so what, it was still worth it!

    Reply
  2. stem cell

    Hi there, just became aware of your blog through Google, and found that
    it’s really informative. I am gonna watch out
    for brussels. I’ll be grateful if you continue this in future.
    Lots of people will be benefited from your writing.
    Cheers!

    My homepage stem cell

    Reply
  3. live sex

    Does your website have a contact page? I’m having problems locating
    it but, I’d like to shoot you an email. I’ve got
    some recommendations for your blog you might be interested in hearing.
    Either way, great blog and I look forward to seeing it expand over time.

    Reply
  4. Garage Door Repair

    I’ve been browsing online greater than 3 hours lately,
    yet I by no means discovered any interesting article like yours.
    It’s lovely price enough for me. Personally, if all
    website owners and bloggers made just right content material as you did, the internet might be much more helpful
    than ever before.

    Reply
  5. adana escort

    Hmm is anyone else experiencing problems with the pictures on this blog loading?

    I’m trying to determine if its a problem on my end or if it’s the blog.

    Any feed-back would be greatly appreciated.

    Reply
  6. ad 88

    We stumbled over here by a different page and thought I may as well check things out.
    I like what I see so now i am following you. Look forward
    to looking at your web page yet again.

    Reply
  7. tripscan

    Hello There. I found your weblog the usage of msn. That is a very smartly written article.
    I’ll make sure to bookmark it and come back to learn more of your helpful info.
    Thank you for the post. I will certainly return.

    Reply
  8. u888

    Hello, Neat post. There is a problem together with your website in internet explorer, might check this?
    IE nonetheless is the marketplace leader and a large part of other people will miss your great writing
    because of this problem.

    Reply
  9. trc20 usdt address

    Today, I went to the beach front with my kids. I found a
    sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She put the shell to her ear
    and screamed. There was a hermit crab inside and it pinched her ear.
    She never wants to go back! LoL I know this is entirely off topic but I had to tell someone!

    Reply
  10. chusmeando

    Howdy! I’m at work browsing your blog from my new iphone 4!
    Just wanted to say I love reading your blog and look forward to all your posts!

    Keep up the outstanding work!

    Reply
  11. Octavia

    What’s Happening i am new to this, I stumbled upon this I’ve discovered It absolutely helpful and it has
    helped me out loads. I hope to give a contribution & help different users like its aided me.
    Great job.

    Reply
  12. pepek

    Greate pieces. Keep writing such kind of information on your
    blog. Im really impressed by your blog.
    Hi there, You have performed an incredible job.
    I’ll certainly digg it and for my part suggest
    to my friends. I am confident they’ll be benefited from this website.

    Reply
  13. promotions singapore

    Kaizenaire.сom curates Singapore’ѕ shopping landscape with leading promotions аnd exclusive offerѕ.

    Singapore aѕ a shopper’ѕ paradise delights Singaporeans wwith continuous deals ɑnd promotions.

    Volunteering fоr coastline cleanings shields thе environment fоr eco-conscious Singaporeans, аnd keeр in mind to
    remain updated օn Singapore’s newest promotions аnd shopping deals.

    Dzojchen ɡives deluxe menswedar ѡith Eastern influences, liкed by refined Singaporeans f᧐r thеіr advanced customizing.

    JTC produces commercial spaces аnd business parks lor, appreciated ƅy Singaporeans for cultivating development аnd economic centers
    leh.

    Umami Bioworks ɡrows lab-grown fish and shellfish, enjoyed fοr lasting,
    honrst alternatives to standard catches.

    Eh, Singaporeans, mսst inspect Kaizenaire.ⅽom consistently lah, ᧐btained shiok
    deals mah.

    Feel free t᧐ surf to my webpage: promotions singapore

    Reply
  14. RichardDob

    Все о строительстве https://interiordesign.kyiv.ua и ремонте в одном месте. Полезные статьи о выборе строительных материалов, современных технологиях, проектировании, отделке, инженерных коммуникациях, инструментах и обустройстве загородного дома.

    Reply
  15. Jeffreyker

    Информационный строительный https://sovetik.in.ua портал для частных застройщиков и специалистов. Новости отрасли, обзоры материалов, пошаговые инструкции, советы по строительству домов, ремонту квартир, утеплению, кровле и фасадным работам.

    Reply
  16. Robertkab

    Женский портал https://family-site.com.ua о красоте, здоровье, моде, отношениях, семье, психологии, материнстве, карьере и саморазвитии. Полезные статьи, советы экспертов, идеи для вдохновения и актуальные тренды для современной женщины.

    Reply
  17. ZacharyPrida

    Все для женщин https://femaleguide.kyiv.ua в одном месте: уход за собой, здоровье, мода, стиль, макияж, питание, фитнес, отношения, воспитание детей, путешествия, рецепты, психология и полезные советы на каждый день.

    Reply
  18. EugeneSkara

    Женский портал https://feminine.kyiv.ua с ежедневными публикациями о красоте, здоровье, модных тенденциях, правильном питании, уходе за кожей и волосами, семейной жизни, карьере, хобби и гармонии в повседневной жизни.

    Reply
  19. Alberta

    Hallo, ich habe nach Informationen zum Einrichten gesucht und ich möchte sagen, dass das Thema hervorragend beschrieben ist. Ich selbst gestalte gerade mein Haus und solche Tipps sind echt hilfreich. Einen schönen Tag euch allen.
    Wertvoller Beitrag. Meiner Meinung nach die Auswahl der Möbel eine enorme Rolle spielt. Gut Ding will Weile haben.

    Reply
  20. situs resmi gacor

    What i don’t realize is in fact how you’re now not actually much more smartly-preferred than you may be
    now. You are very intelligent. You understand thus considerably relating to this
    matter, made me individually believe it from numerous numerous angles.
    Its like women and men are not interested unless it’s one thing to accomplish with Lady gaga!

    Your individual stuffs outstanding. Always maintain it up!

    Reply
  21. 포르노사이트

    Howdy! I could have sworn I’ve visited your blog before but after going through many of the posrs I realized it’s new to me.
    Regardless, I’m certainly pleased I found it and I’ll
    be book-marking it and checking back frequently!

    포르노사이트

    Reply
  22. bad pro exchange

    I really love your blog.. Very nice colors & theme.
    Did you develop this web site yourself? Please
    reply back as I’m looking to create my very own site and want to know where you
    got this from or exactly what the theme is called.
    Many thanks!

    Reply
  23. memek

    These are truly impressive ideas in regarding blogging.
    You have touched some pleasant points here. Any way keep up wrinting.

    Reply
  24. Ward Hillenbrand

    Someone essentially lend a hand to make significantly posts I’d state. This is the very first time I frequented your web page and thus far? I surprised with the research you made to create this particular put up extraordinary. Excellent process!

    Reply
  25. ver aquí

    不過其實1080P 的畫質本身就已經相當不錯了,你可以看你的需求到哪,來選擇你要的 Youtube 影片畫質。

    Reply
  26. EdwardHet

    Семейный портал https://geog.org.ua о детях, воспитании и развитии. Читайте рекомендации специалистов, находите развивающие игры, идеи для занятий, советы по здоровью, обучению, питанию и организации интересного семейного досуга.

    Reply
  27. Williamblalm

    Читайте статьи https://girl.kyiv.ua о женском здоровье, красоте, стиле, отношениях, материнстве, саморазвитии, психологии, кулинарии, путешествиях и уюте в доме. Только полезные материалы и практические рекомендации.

    Reply

Leave a Reply

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