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

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

  1. Lizzie

    Ciekawy artykuł. Wiele praktycznych porad. Dzięki za podzielenie się.
    Na pewno tu wrócę.
    Trafnie napisane – temat aranżacji bywa trudna. Przydatne podejście.

    Bardzo inspirujące. Szukałam czegoś takiego właśnie tego.
    Super robota!

    Take a look at my blog post :: Lizzie

    Reply
  2. Myra

    Very good website you have here but I was curious if
    you knew of any forums that cover the same topics discussed
    in this article? I’d really love to be a part of online community
    where I can get responses from other experienced individuals that share the same interest.
    If you have any recommendations, please let me know.
    Appreciate it!

    Reply
  3. buy tramadol without prescription

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

    Reply
  4. Anime game News

    Amazing blog! Do you have any recommendations for aspiring writers?
    I’m hoping to start my own blog soon but I’m a little
    lost on everything. Would you recommend starting with
    a free platform like WordPress or go for a paid option? There are so
    many choices out there that I’m totally overwhelmed .. Any recommendations?

    Cheers!

    My blog Anime game News

    Reply
  5. solana_glSn

    Erlebe jetzt aufregende Gewinne im [url=https://solonlinecasino.de/]dice casino solana[/url] und sichere dir exklusive Boni.
    Die Plattform kombiniert Blockchain-Technologie mit klassischen Casino-Elementen.

    Reply
  6. mcm998

    Everything is very open with a clear clarification of the challenges.
    It was truly informative. Your website is very helpful.
    Many thanks for sharing!

    Reply
  7. h-k live

    Wow! After all I got a blog from where I know how to in fact take helpful information concerning my study and knowledge.

    Reply
  8. Http://E-HP.Info/Mitsuike/4-Bbs/Bbs/M-123Y.Cgi?Id=1&,Https://Yuehui.Nangesz.Com/Wp-Content/Themes/Begin/Go.Php?Url=Https://Git.Sleepless.Us/Adelinehdd3971

    Ciekawy tekst. Dużo przydatnych inspiracji. Dzięki za ten materiał.
    Na pewno tu wrócę.
    Zgadzam się – sprawa wystroju jest trudna. Dobrze, że ktoś to wyjaśnia.

    Szczerze przydatne. Szukałam takich informacji od dawna.
    Super robota!

    Also visit my blog: http://E-HP.Info/Mitsuike/4-Bbs/Bbs/M-123Y.Cgi?Id=1&amp;,https://Yuehui.Nangesz.Com/Wp-Content/Themes/Begin/Go.Php?Url=Https://Git.Sleepless.Us/Adelinehdd3971

    Reply
  9. mcm998

    This post gives clear idea in support of the new visitors of blogging, that genuinely how to do blogging and site-building.

    Reply
  10. LC88

    Hey I am so delighted I found your web site, I really found you by accident,
    while I was researching on Bing for something else, Nonetheless I am here now
    and would just like to say thanks a lot for a marvelous post and a all
    round entertaining blog (I also love the theme/design), I
    don’t have time to browse it all at the minute but I have book-marked it and also added in your RSS feeds, so when I
    have time I will be back to read a lot more,
    Please do keep up the fantastic job.

    Reply
  11. Gerald

    Świetny wpis. Wiele konkretnych wskazówek. Dziękuję za podzielenie się.

    Na pewno tu wrócę.
    Zgadzam się – temat aranżacji jest trudna. Dobrze, że ktoś to wyjaśnia.

    Bardzo inspirujące. Szukałam czegoś takiego właśnie tego.
    Dziękuję!

    Stop by my webpage … Gerald

    Reply
  12. SITUS PENIPU DELICUAN

    I just like the helpful information you supply for your articles.
    I’ll bookmark your weblog and test again here frequently.
    I’m rather sure I will learn plenty of new stuff right
    right here! Good luck for the next!

    Reply
  13. Nhà cái op88

    Thông tin rất hữu ích, cảm ơn chủ thớt.
    Tiện thể lướt qua topic này, mình muốn giới thiệu một nhà cái cực kỳ uy tín đó chính là OP88.

    Uy tín của OP88 thì anh em trong giới ai cũng rõ rồi.
    Theo mình test thì cổng vào OP88 mượt nhất nằm ở địa chỉ op88new.com nha.

    Truy cập vào op88new.com, chắc chắn anh em sẽ hài lòng với hệ thống nạp
    rút siêu tốc 1-1. Anh em nào muốn đổi gió thử trải nghiệm
    tại op88new.com đảm bảo phê. Cùng nhau về bờ an toàn nhé.

    Reply
  14. 98win01

    I all the time used to read piece of writing in news
    papers but now as I am a user of internet so from now I am using net for posts, thanks to
    web.

    Reply
  15. 问鼎娱乐体育

    I have to thank you for the efforts you have put in writing this website.
    I’m hoping to view the same high-grade blog posts by you in the future as well.
    In truth, your creative writing abilities has motivated me to get my own, personal blog now 😉

    Reply
  16. http://cbsver.bget.ru/user/Carlota47G/

    Honestly, if you’re debating the whole startup llc or c-corp question, you really need a good business litigation representation (http://cbsver.bget.ru/user/Carlota47G/) attorney in your corner, and from everything I’ve heard, Mousilli Legal Group is a great option especially if you’re in Texas since they handle everything from trademark lawyer Houston needs as well as B2B contract disputes which let’s be real is something you don’t think about until it’s too late, and I talked to someone at Mousilli Legal Group about protecting our brand and they were incredibly thorough about startup structure options without making me feel like I was in over my head.

    Reply
  17. Tonia

    Bardzo dobry wpis. Wiele praktycznych porad.
    Dzięki za podzielenie się. Czekam na więcej.
    Trafnie napisane – temat wystroju potrafi być trudna.
    Dobrze, że ktoś to wyjaśnia.
    Szczerze przydatne. Szukałem czegoś takiego już jakiś czas.
    Dziękuję!

    my web blog; Tonia

    Reply
  18. https://movinary.de/

    Ich habe gerade deinen neuesten Beitrag gelesen und hatte ich das Bedürfnis,
    meinen Eindruck zu teilen. Die perfekte Balance zwischen Fakten und persönlichen Gedanken hebt deinen Inhalt deutlich von anderen ab.

    Was ich am meisten schätze ist, dass man die Leidenschaft
    in jedem Satz spürt. Du hast einige Punkte angesprochen, über die ich länger nachdenken werde.

    Ab heute folge ich deinem Blog und freue mich auf mehr!

    Ich habe den Artikel bereits mit Freunden geteilt, die ihn sicher genauso schätzen werden.

    Reply
  19. qs888

    Right here is the right website for anyone who hopes to find out about this topic.
    You understand so much its almost tough to argue with you (not that I really would want to…HaHa).
    You certainly put a brand new spin on a subject that
    has been written about for years. Great stuff, just great!

    Reply
  20. A levels math tuition

    Βy linking math tо imaginative tasks, OMT stirs
    ᥙp an іnterest in students, urging them to embrace the subject and pursue test proficiency.

    Prepare f᧐r success in upcoming exams ѡith OMT Math Tuition’ѕ proprietary
    curriculum, сreated to foster critical thinking аnd self-confidence іn every student.

    Singapore’s emphasis ᧐n critical analyzing mathematics highlights
    tһе significance of math tuition, ᴡhich helps trainees establish tһe analytical abilities demanded Ьy
    the country’ѕ forward-thinking syllabus.

    primary school school math tuition enhances ѕensible reasoning, іmportant for interpreting PSLE questions involving sequences ɑnd rational deductions.

    Offered tһe high risks of O Levels fօr high school development іn Singapore,
    math tuition optimizes chances f᧐r top qualities ɑnd preferred positionings.

    Tuition incorporates pure ɑnd useԁ mathematics effortlessly,
    preparing students fⲟr the inerdisciplinary nature of A Level issues.

    OMT’ѕ proprietary curriculum enhances MOE requirements ƅү providing scaffolded discovering paths that gradually boost іn intricacy, constructing trainee self-confidence.

    Team discussion forums іn tһe platform allⲟw you
    review ᴡith peers sia, clarifying doubts ɑnd boosting your mathematics performance.

    Singapore parents buy math tuition tο ensure tһeir children satisfy tһе hiցh
    assumptions of the education and learning ѕystem for examination success.

    Feel free tо surf to my web blog – A levels math tuition

    Reply
  21. solana_zlSn

    Erlebe jetzt aufregende Gewinne im [url=https://solonlinecasino.de/]dice casino solana[/url] und sichere dir exklusive Boni.
    In der Welt der Kryptowahrungen hat sich das Solana Casino schnell als innovativer Akteur etabliert.

    Reply
  22. test blog backlink

    It’s a pity you don’t have a donate button! I’d
    without a doubt donate to this outstanding blog!
    I suppose for now i’ll settle for bookmarking and adding your RSS feed to my Google account.
    I look forward to fresh updates and will share this site with my Facebook group.

    Talk soon!

    Reply
  23. No deposit bonus casinos

    Hello there, I discovered your site by way of Google whilst looking for
    a comparable subject, your web site got here up, it seems great.

    I have bookmarked it in my google bookmarks.
    Hi there, simply became alert to your blog via
    Google, and found that it’s really informative.
    I am gonna be careful for brussels. I will appreciate for those who continue this in future.
    Lots of folks shall be benefited from your writing.
    Cheers!

    Reply
  24. Techxa airmatic

    I’m truly enjoying the design and layout of your website.

    It’s a very easy on the eyes which makes it much more enjoyable for
    me to come here and visit more often. Did you hire out a designer to create your theme?
    Fantastic work!

    Reply
  25. memek online

    Hello my loved one! I want to say that this post is amazing, nice written and include almost all important infos.
    I’d like to peer more posts like this .

    Reply
  26. Heriberto

    Hi, ich bin beim Stöbern hier gelandet und ich möchte sagen, dass ich viel dazugelernt habe. Ich selbst renoviere seit kurzem die Einrichtung neu zu und jeder Ratschlag hilft mir weiter. Einen schönen Tag euch allen.
    Gutes Thema. Ich möchte hinzufügen, dass die Farbwahl wirklich einen Unterschied macht. Es lohnt sich, dafür Zeit zu nehmen.

    Reply

Leave a Reply

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