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. erek erek 2d

    each time i used to read smaller content that also clear their motive, and that is also happening with this post which I am reading
    here.

    Reply
  2. плей фортуна официальный

    Hey there would you mind stating which blog platform you’re using?
    I’m planning to start my own blog in the near future but I’m having a difficult time selecting
    between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your design seems different then most blogs and I’m looking for something completely unique.

    P.S Sorry for being off-topic but I had to ask!

    Reply
  3. situs slot online

    Please let me know if you’re looking for a article writer
    for your blog. You have some really great articles and I feel I would be a good asset.
    If you ever want to take some of the load off, I’d love to write some
    content for your blog in exchange for a link back to mine.
    Please send me an email if interested. Kudos!

    Reply
  4. 카드현금화

    정보 정리 감사합니다. 신용카드 현금화을 알아볼 때는 수수료를 먼저 확인하는 게 중요하다고 생각합니다.

    공감합니다. 급하게 결정하기보다 정산 방식과 주의사항을 같이 보는 게 필요합니다.

    저도 비슷하게 생각합니다. 신용카드현금화 관련 정보는 간단한 진행보다 실제 조건이 더 중요합니다.

    잘 읽었습니다. 카드깡을 검색하는
    사람들은 대부분 급한 상황이 많아서, 개인정보를 놓치기
    쉬운 것 같습니다.

    참고했습니다. 카드현금화 관련해서는 상담 전 조건을 기록해두고
    비교하는 게 좋다고 봅니다.

    공감되는 내용입니다. 빠른 정산 같은 표현은 편해 보이지만,
    실제로는 정산 기준까지 봐야 합니다.

    정보 감사합니다. 카드깡 관련 글은 주의사항를 같이 설명해주는 쪽이 더 도움이 되는 것 같습니다.

    괜찮은 글이네요. 생활비 부족 때문에 알아보는 경우라도, 상환 가능성은 꼭 따져봐야 합니다.

    좋은 포인트입니다. 카드깡은 후기보다 실제 조건이 중요하다고 봅니다.

    참고하겠습니다. 이런 주제는 상황이 바쁠수록 더
    차분하게 정산조건을 확인해야 합니다.

    Reply
  5. learn more

    Good cleaning can help support hygiene.
    This applies to commercial spaces where cleanliness matters.

    One example in this field is reinigungs-profies.de.

    Reply
  6. tkslot

    Greetings! Very useful advice within this article!
    It is the little changes that produce the biggest changes.

    Many thanks for sharing!

    Reply
  7. make big penis

    Hmm it appears like your site ate my first comment (it was extremely long)
    so I guess I’ll just sum it up what I had written and say,
    I’m thoroughly enjoying your blog. I too am an aspiring blog blogger but
    I’m still new to the whole thing. Do you have any recommendations for newbie blog writers?
    I’d really appreciate it.

    Reply
  8. Dieter

    I take pleasjre in, resul iin I dicovered just
    what Iwaas hasving a look for. You have ended my fourr dayy lehgthy hunt!
    Godd Blezs yyou man. Have a nicfe day. Bye

    Stopp bby myy homepagee :: xmxx; Dieter,

    Reply
  9. Charles

    Very nice post. I just stumbled upon your blog and wished to mention that I’ve truly
    loved surfing around your weblog posts. After all I’ll be subscribing to
    your feed and I’m hoping you write again very soon!

    Reply
  10. wypłacalne kasyna online

    We absolutely love your blog and find the majority of your post’s to be exactly what I’m looking for. Do you offer guest writers to write content to suit your needs? I wouldn’t mind composing a post or elaborating on a number of the subjects you write about here. Again, awesome weblog!

    Reply
  11. new88

    Hey there! 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 gains. If you know of any please share.
    Many thanks!

    Reply
  12. نمایندگی داکت اسپیلت اجنرال

    Fantastic goods from you, man. I’ve understand your
    stuff previous to and you’re just extremely fantastic.

    I actually like what you have acquired here, really like what you are saying and the way in which
    you say it. You make it entertaining and you still take care of to keep it smart.
    I cant wait to read much more from you. This is really a terrific site.

    Reply
  13. Sadye

    Wonderful beat ! I would like to apprentice while you amend your web site, how can i subscribe for a blog site?
    The account aided me a acceptable deal. I had been a little bit acquainted of this your broadcast offered bright clear idea

    Reply
  14. 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 trusted 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
  15. tkslot

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

    Reply
  16. tai day

    Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here It’s always nice when you can not only be informed, but also entertained I’m sure you had fun writing this article.

    Reply
  17. tkslot

    Hi everyone, it’s my first go to see at this web site,
    and piece of writing is genuinely fruitful in support of me, keep up posting these types
    of content.

    Reply
  18. tkslot

    Good site you’ve got here.. It’s hard to find high quality writing
    like yours these days. I truly appreciate people like you!
    Take care!!

    Reply
  19. نمایندگی تعمیر یخچال آرچلیک

    Hey there I am so happy I found your weblog, I really found you
    by error, while I was browsing on Digg for something else,
    Nonetheless I am here now and would just like to say many thanks for a tremendous
    post and a all round enjoyable blog (I also love the theme/design),
    I don’t have time to browse it all at the moment but I have saved
    it and also added in your RSS feeds, so when I
    have time I will be back to read more, Please do keep up the fantastic jo.

    Reply
  20. Https://Mistnews.Com/

    Wertvoller Artikel. Viele konkrete Tipps. Grüße für diesen Inhalt.
    Ich speichere mir die Seite ab.
    Du hast recht – die Frage der Wohnungsgestaltung wird oft schwierig.

    Danke für die klare Erklärung.
    Echt praxisnah. Ich suche schon nach genau so einem Beitrag seit Wochen gesucht.
    Danke!

    Feel free to visit my blog post https://Mistnews.Com/

    Reply
  21. نمایندگی تعمیر مایکروفر دوو

    Have you ever thought about publishing an ebook or guest authoring on other blogs?
    I have a blog based on the same information you discuss and would really
    like to have you share some stories/information. I know my visitors would enjoy your work.
    If you’re even remotely interested, feel free to send me an email.

    Reply
  22. 939au0gz3bk88c.isweb.co.kr

    Whats up this is somewhat of off topic but I was wondering if blogs use WYSIWYG editors
    or if you have to manually code with HTML. I’m starting a blog soon but have no coding knowledge so I wanted to get advice from someone with experience.
    Any help would be greatly appreciated!

    Reply
  23. maximize Airbnb revenue

    I used to be suggested this website by means of my cousin. I am no longer certain whether
    or not this post is written via him as no one else realize such distinct about my trouble.
    You’re wonderful! Thanks!

    Reply
  24. Https://Viki.Forsakensaga.Com

    Guten Tag, ich bin zufällig auf dieses Thema gestoßen und ich möchte sagen, dass das Thema hervorragend beschrieben ist. Ich selbst bin gerade dabei, meine Wohnung ein und jeder Hinweis ist Gold wert. Danke und viele Grüße.
    Gutes Thema. Ich möchte hinzufügen, dass die Farbwahl wirklich einen Unterschied macht. Ich empfehle, sich nicht zu hetzen.

    Feel free to surf to my site; https://viki.forsakensaga.com/index.php/Schlafzimmerm%C3%B6bel:_Mehr_Als_Nur_Ein_Bett

    Reply
  25. https://Tapczany.info/

    Servus, ich bin zufällig auf dieses Thema gestoßen und mir ist aufgefallen, dass ich viel dazugelernt habe. Ich selbst bin gerade dabei, mein Zuhause neu zu gestalten und jeder Hinweis ist Gold wert. Viele Grüße.
    Spannender Thread. Aus meiner Erfahrung die Farbwahl eine enorme Rolle spielt. Lieber einmal richtig als zweimal.

    Reply
  26. 레비트라 강직도

    Hey! I know this is somewhat off topic but I was wondering if you knew where I could
    locate a captcha plugin for my comment form? I’m using the
    same blog platform as yours and I’m having problems finding one?
    Thanks a lot!

    Reply
  27. 비아그라 구매

    Thank you a lot for sharing this with all people you actually recognise what you’re speaking about!
    Bookmarked. Please also visit my website =). We
    will have a link change contract between us

    Reply
  28. 0832 Yupoo For Sale

    My brother recommended I might like this website. He was entirely right.

    This post truly made my day. You can not imagine just how much time
    I had spent for this information! Thanks!

    Reply
  29. 完美体育

    Hello to all, how is the whole thing, I think every one is getting more from this site, and your views are nice
    in support of new people.

    Reply
  30. http://betcardreview.com/terms/

    بخوام خودمونی بگم، اولش فکر نمی‌کردم چیز خاصی ببینم ولی
    چند بخشش برام قابل توجه بود.
    سلام دوستان، چون چند وقتیه درباره این فضا کنجکاو
    شدم گفتم اینجا هم نظرم رو ثبت کنم.
    دیروز وقتی یکی از دوستام درباره بتینگ آنلاین حرف می‌زد
    اینجا برام جالب شد. بعد از چند دقیقه بررسی
    حس کردم برای آشنایی اولیه می‌تونه مفید باشه.
    برداشت شخصی من اینه که در موضوعات مالی و بازی‌های پولی باید محتاط بود.
    یکی از آشناهای من دنبال این بود که چند
    پلتفرم مختلف رو مقایسه کنه.
    همین باعث شد من هم دقیق‌تر
    نگاه کنم. از نظر من نکته مثبتش این بود که چند بخشش برای مقایسه مفید بود.
    البته نباید فقط با یک کامنت نتیجه‌گیری کرد.
    برای اون دسته از کاربرها که می‌خوان درباره بازی انفجار بیشتر بدونن، این
    سایت می‌تونه یکی از گزینه‌های
    بررسی باشه. گاهی هم نمونه‌هایی مثل еnfeϳaгonline.net و پلتفرم sibbet باعث
    شدن کاربرا بیشتر دنبال مقایسه باشن.

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

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

    Stop by my site :: محدودیت‌های بانکی مرتبط با
    تراکنش‌ها [http://betcardreview.com/terms/]

    Reply
  31. https://poka88.sceltetop.com/

    An interesting discussion is definitely worth comment.
    There’s no doubt that that you should write more about
    this topic, it might not be a taboo subject but generally people do not speak about such topics.
    To the next! Kind regards!!

    Reply
  32. slon7

    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 totally off
    topic but I had to tell someone!

    Reply

Leave a Reply

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