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

  1. annas archive

    It’s truly very complicated in this active life to listen news on TV, therefore
    I just use web for that purpose, and take the most recent information.

    Reply
  2. kpktoto.co

    Wow, amazing blog layout! How long have you been blogging
    for? you make blogging look easy. The overall look of your
    site is excellent, let alone the content!

    Reply
  3. heylink with rusia777

    Today, I went to the beach with my children. 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 placed 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 completely off topic but I had to tell someone!

    Reply
  4. sex

    Because the admin of this website is working, no question very rapidly it will be famous, due to
    its feature contents.

    Reply
  5. web page

    Its not my first time to pay a quick visit this site, i
    am browsing this site dailly and take fastidious facts from
    here everyday.

    Reply
  6. Liên hệ GO88

    Hi! 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 setting up my own but I’m not sure
    where to begin. Do you have any points or suggestions? Many thanks

    Reply
  7. 비아그라 구매

    I just like the valuable information you provide for your articles.
    I’ll bookmark your blog and check again here regularly. I’m somewhat
    sure I will be told lots of new stuff proper right here!
    Good luck for the next!

    Reply
  8. maximize Airbnb revenue

    Today, I went to the beachfront with my children. 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 placed 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 completely off topic but I had to tell
    someone!

    Reply
  9. Vin88

    Hey there! I know this is somewhat off topic but I was wondering which blog platform are you using for this site?
    I’m getting fed up of WordPress because I’ve had problems with hackers
    and I’m looking at alternatives for another platform.

    I would be awesome if you could point me in the direction of a good
    platform.

    Reply
  10. MALWARE

    Woah! I’m really loving the template/theme of this website.
    It’s simple, yet effective. A lot of times it’s tough to get that “perfect balance” between user
    friendliness and appearance. I must say that you’ve done
    a awesome job with this. In addition, the blog loads super quick for me on Opera.
    Superb Blog!

    Reply
  11. minyak pembesar penis

    Thanks a bunch for sharing this with all people
    you really realize what you are speaking approximately!
    Bookmarked. Please additionally seek advice from my website =).
    We will have a link exchange agreement among us

    Reply
  12. https://www.arcadetimecapsule.com:443/wiki/index.php/Jak_wybrać_meble_tapicerowane_do_małego_mieszkania_–_praktyczne_porady_z_życia

    Ciekawy tekst. Dużo przydatnych informacji. Dzięki
    za ten materiał. Zapisuję do ulubionych.
    Trafnie napisane – sprawa urządzania wnętrz potrafi być
    trudna. Wreszcie konkrety.
    Szczerze pomocne. Szukałam podobnych porad już jakiś
    czas. Super robota!

    Check out my site :: https://www.arcadetimecapsule.com:443/wiki/index.php/Jak_wybrać_meble_tapicerowane_do_małego_mieszkania_–_praktyczne_porady_z_życia

    Reply
  13. tekfen holding porno ifşa

    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
  14. Best crypto casinos

    Howdy would you mind letting me know which webhost you’re using?
    I’ve loaded your blog in 3 completely different web browsers and I must say
    this blog loads a lot faster then most. Can you suggest
    a good internet hosting provider at a reasonable price?
    Thanks, I appreciate it!

    Reply
  15. mcm998

    Your means of explaining all in this article is really
    fastidious, all be able to without difficulty be aware of it,
    Thanks a lot.

    Reply
  16. paper.io

    paper.io

    Attractive component of content. I just stumbled upon your web site and in accession capital to assert
    that I acquire in fact enjoyed account your weblog posts.
    Any way I’ll be subscribing to your feeds and even I fulfillment
    you get right of entry to consistently fast.

    Reply
  17. trussardi my land

    Howdy would you mind sharing which blog platform you’re using?
    I’m going to start my own blog soon but I’m having a tough time choosing between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your layout seems different then most blogs and I’m looking for something
    completely unique. P.S Sorry for getting off-topic but I had to ask!

    Reply
  18. Lorrie

    I read this piece of writing completely regarding the
    resemblance of hottest and previous technologies, it’s
    amazing article.

    Reply
  19. viagra indonesia

    I am not sure where you are getting your info,
    but great topic. I needs to spend some time learning much more or understanding
    more. Thanks for great info I was looking for this information for my mission.

    Reply
  20. CH加密中心学院

    把它想象成一个“带有资料室的兴趣小组”。资料室就是它的工具导航站,兴趣小组就是它的社群。两者加在一起,构成了Cryptify Hub这个社群型品牌。资料室里的资料(链接)由小组成员共同维护,兴趣小组里的讨论也围绕这些资料展开。这种模式的好处是“学用结合”——找到工具后可以直接问别人怎么用。坏处是“质量不稳”——资料可能过时,讨论可能错误。

    Reply
  21. meitu

    Ahaa, its nice conversation about this article here at this weblog, I have read all that,
    so at this time me also commenting here.

    Reply
  22. 爱思助手电脑版下载

    My programmer is trying to convince me to move to .net from PHP.
    I have always disliked the idea because of the costs. But he’s
    tryiong none the less. I’ve been using WordPress on various websites for about a year and am worried about switching to
    another platform. I have heard good things about blogengine.net.
    Is there a way I can transfer all my wordpress posts into it?
    Any kind of help would be really appreciated!

    Reply
  23. 66b triều khúc

    excellent post, very informative. I ponder why the other specialists of
    this sector do not realize this. You should continue your writing.

    I am confident, you’ve a huge readers’ base already!

    Reply
  24. 주소야

    Simply wish to say your article is as amazing. The clarity
    in your publish is simply excellent and that i could assume you’re a professional in this subject.
    Fine with your permission let me to grasp your RSS
    feed to keep updated with drawing close post. Thank
    you one million and please continue the rewarding work.

    Reply
  25. website

    I really like your blog.. very nice colors & theme.
    Did you design this website yourself or did you hire someone
    to do it for you? Plz reply as I’m looking to design my own blog and would like to know where u got
    this from. thanks

    Reply
  26. hcinquiemecrayon.eu

    Hi, i believe that i noticed you visited my blog so i came to go back the prefer?.I am attempting to find things to enhance my
    site!I suppose its adequate to make use of a few of your concepts!!

    Reply
  27. kaikoslot login

    Just wish to say your article is as amazing. The clarity in your post
    is just cool and i could assume you are an expert on this subject.

    Well with your permission let me to grab your
    RSS feed to keep up to date with forthcoming post.
    Thanks a million and please continue the gratifying work.

    Reply
  28. Rogelio

    Wirklich guter Artikel. Eine Menge konkrete
    Anregungen. Großes Lob für diesen Inhalt. Ich warte auf mehr.

    Treffend formuliert – die Frage der Möbelauswahl kann nicht einfach.
    Gut, dass es jemand erklärt.
    Sehr inspirierend. Ich habe schon nach genau so einem Beitrag lange gesucht.
    Super Arbeit!

    Feel free to surf to my page; Rogelio

    Reply
  29. burun estetiği

    Hello there, I found your web site via Google whilst searching for a related topic, your website
    came up, it seems great. I have bookmarked it in my google bookmarks.

    Hi there, simply turned into aware of your blog via Google,
    and located that it is really informative. I’m gonna watch out for brussels.
    I’ll appreciate if you proceed this in future. Many people will be
    benefited out of your writing. Cheers!

    Reply
  30. Rubah4d

    Hey there just wanted to give you a quick heads up.
    The words in your article seem to be running off
    the screen in Internet explorer. I’m not sure if this is a formatting
    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 problem solved soon. Thanks

    Reply
  31. iptv portugal

    I’m truly enjoying the design and layout of your site.
    It’s a very easy on the eyes which makes it much more pleasant
    for me to come here and visit more often. Did you hire out a designer to create your theme?
    Superb work!

    Check out my blog post … iptv portugal

    Reply

Leave a Reply

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