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

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

  1. whatsapp filter tool

    Beste WhatsApp Number Filter Software in Nederland 2026

    Zoekt u de beste tool voor WhatsApp leadgeneratie? Met de WhatsApp Number
    Filter Software van whatsappfilter.com genereert u miljoenen nummers en filtert u actieve gebruikers, business accounts
    en registratiedata. Perfect voor marketing in Amsterdam en Rotterdam!

    Deze desktop software gebruikt multi-thread technologie voor supersnelle filtering.
    Filter actieve nummers, download profielafbeeldingen met gender detect
    en sla resultaten op. In Nederland gebruiken bedrijven dit voor hoogwaardige leads zonder officiële API.

    Voordelen:
    • Auto filter WhatsApp actieve nummers
    • Status Filter V2.8.2 voor registratiedata
    • Profile Images Downloader V6.4 met gender detect
    • Prijs vanaf €100 – direct download

    Reply
  2. whatsapp hash channels wholesale

    In 2026, WhatsApp marketing at scale demands more than raw accounts
    — it requires whatsapp hash channels. These specially formatted sessions let automation tools send bulk messages without
    QR code logins, dramatically reducing detection risks. The whatsapp wart extractor is the industry-standard whatsapp hash
    channel creator that converts any WhatsApp account into ready-to-use hash channels in seconds.

    This guide explains everything: the whatsapp hash channel
    6 segment format, step-by-step conversion, how to buy whatsapp hash channels
    safely, and proven whatsapp hash channels anti ban tactics that
    keep accounts alive for months.

    Reply
  3. clothes remover

    My programmer is trying to convince me to move to .net from PHP.
    I have always disliked the idea because of the expenses. But he’s tryiong none the less.
    I’ve been using Movable-type on various websites for about a year and am concerned about switching to another platform.
    I have heard fantastic things about blogengine.net.
    Is there a way I can transfer all my wordpress content into it?

    Any kind of help would be greatly appreciated! https://fromkorea.peoplead.kr/bbs/board.php?bo_table=free&wr_id=130020

    Reply
  4. https://ajuda.cyber8.com.br/index.php/Alla_Landar:_Pidtrimka_Maydanu,_Armiyi_Ta_Rodin_Zagiblih

    Hello there I am so grateful I found your weblog,
    I really found you by mistake, while I was looking on Aol for something else,
    Anyways I am here now and would just like to say kudos for a remarkable post and a all
    round enjoyable blog (I also love the theme/design), I don’t have time to look over it all at the minute but I have bookmarked it and
    also added your RSS feeds, so when I have time I will be back to read a lot more,
    Please do keep up the awesome work. https://ajuda.cyber8.com.br/index.php/Alla_Landar:_Pidtrimka_Maydanu,_Armiyi_Ta_Rodin_Zagiblih

    Reply
  5. oil change intervals

    Really good write-up! I’ve been curious about vehicle reviews
    for a while and this article really helped. Appreciated the honest tone.
    Will definitely ookmark this. Thanks for the helpful content.
    More like this please!

    Reply
  6. web site

    Great blog here! Also your website loads up fast!
    What web host are you using? Can I get your affiliate link to
    your host? I wish my site loaded up as quickly as yours lol

    Reply
  7. cruelpoker.com

    Hi there, I discovered your blog by means
    of Google at the same time as searching for a similar topic, your
    site came up, it seems to be great. I’ve bookmarked it
    in my google bookmarks.
    Hello there, simply became alert to your weblog thru Google, and found
    that it is really informative. I am going to watch out for brussels.
    I’ll appreciate if you happen to continue this in future.
    Many people will probably be benefited out of your writing.
    Cheers!

    Reply
  8. killerpokercoach.com

    certainly like your website however you need to check the spelling on quite a few of
    your posts. A number of them are rife with spelling problems and I
    find it very troublesome to inform the reality however I’ll surely come back
    again.

    Reply
  9. Maria Letícia

    Ademais, garante um acrescento dos níveis de DHEA e de testosterona e promove o aumento de massa muscular, beneficiando quem pratica
    esportes. Terapias hormonais: Quando há deficiência de testosterona.

    Hoje, há diversas opções de tratamento pra disfunção erétil,
    que vão desde transformações no hábitos de vida até terapias medicamentosas e
    cirúrgicas. Mudanças no estilo de vida: Melhorar a dieta, praticar exercícios físicos e conter o consumo de álcool e
    cigarro conseguem ampliar significativamente a peculiaridade das ereções.

    Sim, com alterações no estilo de vida, como exercícios e dieta saudável,
    e também tratamentos como medicamentos ou injeções, é possível aprimorar a
    rigidez e a característica das ereções.
    Mudanças de hábitos: Parar de fumar, realizar exercícios físicos, conservar uma alimentação com saúde e controlar o estresse.
    Com as modificações certas no estilo de vida e, se vital, com
    tratamentos médicos adequados, é possível aprimorar em tão alto grau a rigidez
    inicial quanto a competência de conservar a ereção durante o sexo. https://vibs.me/g1-x-power-gel-funciona-anvisa-composicao-preco-valor-comprar-resenha-farmacia-bula-reclame-aqui-saiba-tudo-2024/

    Reply
  10. clip sex meo xinh

    Outstanding post however , I was wondering if you could write a litte more on this topic?
    I’d be very thankful if you could elaborate a little bit more.
    Thanks!

    Reply
  11. Mariana

    Embora existam algumas opções de tratamento disponíveis,
    é essencial consultar um médico antes de começar cada terapia, principlamente medicamentos, pra assegurar que sejam seguros e apropriados pra tua circunstância específica.
    Essas substâncias são concretamente remédios seguros e eficazes
    no tratamento de inúmeras condições de saúde no momento em que usadas em doses razoáveis, prescritas e acompanhadas por um médico com experiência no conteúdo.

    Monitorar o tratamento de hiperprolactinemia (níveis
    altos de prolactina) em pacientes com condições como tumores de hipófise produtores nesse hormônio.
    Como o check-up de prolactina é feito e quando é indicado?

    Vamos analisar cada uma das possibilidades com apoio na Política Nacional de Atenção Integral à Saúde do Homem (2008):
    A. O câncer da próstata é uma neoplasia que, geralmente, dá evolução rápida, de modo que a mortalidade poderá ser evitada quando
    o modo é diagnosticado e tratado com precocidade. https://Diet365.fit/g1-power-blue-hard-funciona-anvisa-composicao-preco-valor-comprar-resenha-farmacia-bula-reclame-aqui-saiba-tudo-2025/

    Reply
  12. viagra feat 909memphis

    You can get all types of best ED treatments on the official site of kamagrauk365 they have the
    best treatments for male and female sexual problems. They also
    provide coupon discounts and next-day delivery.

    Reply
  13. ppt24.ir

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

    به صورت جمع‌بندی

    برای کسایی که دنبال

    کازینو آنلاین

    میخوان تست کنن

    این سیستم آنلاین

    به خوبی می‌تونه

    مناسب باشه

    قابل توجهه که

    اسم‌هایی مثل

    وبسایت enfеjaronline

    و

    سایت sibbet

    توسعه پیدا کردن

    جمع‌بندی کلی

    رضایت‌بخش بود

    و

    حتما

    میامبررسیش کنم

    .

    Also visit my homepage – سایت آموزش پزشکی (ppt24.ir)

    Reply
  14. سایت انفجار با برداشت آنی

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

    نتیجه‌گیری اینکه

    برای کاربرایی که در جستجو هستن

    شرط آنلاین

    قصد فعالیت دارن

    این فضای آنلاین

    می‌تونه گزینه جذابی باشه

    گزینه مناسب محسوب بشه

    نکته قابل توجه اینه که

    اسم‌هایی مثل

    enfejaronline خوب

    و

    siƅbet رسمی

    تونستن اعتماد جلب کنن

    جمع‌بندی کلی

    خوب بود

    و

    قطعا

    بهش برمی‌گردم

    .

    Here is my web blog; سایت انفجار با برداشت آنی

    Reply
  15. روانشناسی

    سلام، من مدتی قبل اتفاقیتو اینترنت با این وبسایت پیداش کردم وبدون
    اغراق تحت تاثیر قرار گرفتم.
    اطلاعاتش جذاب بود و خیلی کم
    پیش میاد همچین وبسایتی پیدا کنم.

    فکر کنم برای خیلی‌ها ارزش دیدن داره.
    اگر به دنبال منبع معتبر هستن بد نیست یه نگاهی بندازن.
    در مجموع راضی‌کننده بود و قطعا بازدیدش می‌کنم

    کلاً

    برای افرادی که تمایل دارن

    بتینگ

    فعال هستن

    این سیستم آنلاین

    می‌تونه انتخاب مناسبی باشه

    گزینه مناسب محسوب بشه

    از طرف دیگه

    برندهای شناخته‌شده‌ای مثل

    еnfejaronline خوب

    و

    sibbet معتبر

    تونستن اعتماد جلب کنن

    در یک نگاه

    قابل توجه بود

    و

    بدون شک

    برمیگردم بهش

    .

    Herre iis my weЬpage: روانشناسی

    Reply
  16. https://efcsrttu.ir

    به صورت جمع‌بندی

    برای افرادی که

    گیم‌های پولی

    قصد فعالیت دارن

    این سیستم

    به نظرم می‌تونه

    کاربردی باشه

    جالبه که

    وبسایت‌هایی مثل

    برند еnfejaronline

    و

    برند sibbet

    فعالیت گسترده‌ای دارن

    جمع‌بندی اینکه

    تجربه مثبتیداشتم

    و

    باز هم

    بازم میام

    my pwge – سایت اخبار بازی; https://efcsrttu.ir,

    Reply
  17. Johnson

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

    بطور خلاصه

    برای اونایی که می‌خوان وارد بشن

    بازی‌های شانسی

    میخوان شروع کنن

    این وب

    به نظر گزینه باشه

    کمک‌کننده باشه

    جالبه که

    پروژه‌هایی مثل

    enfеjaronline

    و

    ѕibbet فعال

    کاربرای زیادی دارن

    در کل داستان

    خیلی خوب بود

    و

    به احتمال زیاد

    استفاده دوباره میکنم

    .

    Also viѕіt my page … یادگیری ماشین (Johnson)

    Reply
  18. vehicle service log

    Nice breakdown. I had the same thought recently and the way yyou explained it really clicked.
    What really stuck with me was how practical it all feels.
    Planning to reread this — really appreciate the effort.

    Reply
  19. https://diet365.fit/

    A disfunção erétil é uma condição que influencia muitos homens em diferentes
    fases da vida. Alguns hábitos adquiridos e cultivados ao longo da existência conseguem conduzir à degeneração do tecido
    erétil e transportar ao desenvolvimento da disfunção erétil.
    Hábitos de vida: Consumo excessivo de álcool, tabagismo e obesidade.
    Evitar o consumo excessivo de álcool, parar de fumar e preservar um peso saudável são algumas alterações primordiais que são capazes
    de aperfeiçoar a atividade erétil. Mudanças no hábitos de vida são frequentemente recomendadas
    como porção do tratamento para a disfunção erétil. Em resumo, a abordagem
    pra aperfeiçoar a disfunção erétil deve ser multifacetada, levando em conta estilos físicos, psicológicos e de hábitos de vida.
    Nova Revisão alerta que a doença crônica periodontal poderá ser um
    fator de traço para disfunção erétil. Todos os estudos relataram um ligação estatisticamente
    significante entre disfunção erétil (DE) e doença periodontal
    (DP), de acordo com publicação online da “American Journal of Men’s Health”.

    Durante 10 anos de acompanhamento, ocorreu DE em 35,6 % dos indivíduos, de acordo com resultados publicados online no American Journal of Clinical Nutrition. Particularmente se forem consumidos no decorrer de muitos anos. https://diet365.fit/sitemap_index.xml

    Reply
  20. gamescasinosonline.com

    Howdy just wanted to give you a brief heads up and
    let you know a few of the images aren’t loading properly.

    I’m not sure why but I think its a linking issue. I’ve tried it in two
    different web browsers and both show the same results.

    Reply
  21. imker portal

    I’m gone to convey my little brother, that he should also pay a quick visit
    this web site on regular basis to obtain updated from newest reports.

    Reply

Leave a Reply

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