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

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

  1. betfury.com

    My brother recommended I may like this blog. He was once totally right.

    This post actually made my day. You cann’t consider simply how a lot time I had spent for this info!
    Thank you!

    Reply
  2. 시알리스구매사이트

    Hello very nice web site!! Man .. Excellent ..
    Amazing .. I’ll bookmark your site and take the feeds also?
    I am happy to search out so many helpful info right here within the submit, we’d like work
    out extra strategies on this regard, thank you for sharing.
    . . . . .

    Reply
  3. ngentot

    Quality content is the crucial to be a focus for the people to
    pay a visit the site, that’s what this web page is providing.

    Reply
  4. play888new.com

    This is a very informative post about online casinos and betting platforms.
    I especially liked how it explains the importance of choosing a licensed 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
  5. 정품 비아그라

    Hi, i think that i saw you visited my website so i came to “return the favor”.I am attempting
    to find things to enhance my website!I suppose its ok to use some of your ideas!!

    Reply
  6. all yono games

    What’s up, every time i used to check website posts here in the early hours in the daylight, for
    the reason that i like to learn more and more.

    Reply
  7. silk durags

    Does your website have a contact page? I’m having trouble locating it but, I’d like to send you
    an e-mail. I’ve got some suggestions for your blog you might be interested in hearing.
    Either way, great site and I look forward to seeing it improve over time.

    Reply
  8. Iz-phoenix.com

    I have been exploring for a little bit for any high quality articles or
    blog posts on this kind of space . Exploring in Yahoo I
    finally stumbled upon this site. Reading this information So i’m
    happy to exhibit that I’ve a very good uncanny feeling
    I came upon exactly what I needed. I most definitely will make sure to do
    not disregard this site and provides it a glance on a continuing basis.

    Reply
  9. uu88 trang chủ

    UU88 là cổng game giải trí trực tuyến uy
    tín hàng đầu năm 2026, mang đến hệ sinh thái cá cược đa dạng gồm thể thao, casino trực tuyến, nổ hũ, bắn cá và game bài đổi thưởng.
    Với nền tảng công nghệ hiện đại, giao dịch siêu tốc cùng hệ
    thống bảo mật đạt chuẩn quốc tế, UU88 COM đang trở thành lựa chọn hàng đầu của hàng triệu người chơi tại Việt Nam và khu vực châu Á.

    Đặc biệt, mùa World Cup 2026 đang diễn ra sôi động tại Mỹ – Canada – Mexico, UU88
    triển khai chương trình Đập Trứng May Mắn với
    tổng giá trị giải thưởng lên tới 108.888K,
    mang đến cơ hội săn thưởng cực lớn dành cho tất cả hội viên.

    Reply
  10. viagra 87

    It is not possible to become uncircumcised, as circumcision is a
    surgical procedure that removes the foreskin from the penis.

    Reply
  11. Dubai property investment opportunities

    Dubai is one of the universe’s garnish real caste investment destinations, gift impost advantages,
    formidable rental yields, and premium lifestyle
    opportunities. From sybaritism villas to high-rise
    apartments, buying means in Dubai provides terrific potential looking for both return and long-term major growth.

    Reply
  12. 購買製作大葉大學 畢業證書文憑學位辦理代辦證樣本範例模板最新2026

    I would really like to appreciate the endeavors you cash in on written this article. I’m going for the similar best product from you finding out in the foreseeable future as well. Actually your creative writing abilities has urged me to begin my very own blog now. Genuinely the blogging is distributing its wings rapidly. Your write down is often a fine illustration showing it.

    Reply
  13. padel5000

    Hi, I do think this is an excellent website.
    I stumbledupon it 😉 I will return once again since i have book-marked it.

    Money and freedom is the greatest way to change, may you be rich and continue to
    guide other people.

    Reply
  14. 789win

    nền tảng cá cược trực tuyến vận hành trên kiến trúc điện toán đám mây
    kết hợp mô hình bảo mật Zero-Trust, mang đến không gian giải trí
    tối ưu độ trễ cho mọi hội viên. Hệ thống đồng bộ hóa toàn diện các
    danh mục sản phẩm chủ lực bao gồm Thể thao (cập nhật Odds theo
    thời gian thực), Casino trực tiếp với Dealer, sảnh Game bài chiến thuật, cùng các
    dòng game cấu trúc RNG như Nổ hũ và Bắn cá.
    Ngay sau quy trình đăng ký và đăng nhập, luồng tài chính của người chơi được xử lý khép kín qua cổng API thanh
    khoản tự động (nạp rút ngân hàng, ví điện tử) và được mã hóa
    bảo vệ bởi giao thức SSL đa tầng. Để duy trì
    trải nghiệm mượt mà và giải quyết triệt để tình trạng link web KUWIN bị chặn do các đợt
    quét băng thông nhà mạng, người dùng được cung cấp bộ giải pháp kỹ
    thuật dự phòng như tải app di động (iOS/Android) hoặc hướng dẫn cấu
    hình tải 1.1.1.1. Mọi văn bản về quyền riêng tư,
    chính sách miễn trừ trách nhiệm cũng như cơ chế
    cá cược có trách nhiệm đều được minh bạch hóa tại chuyên mục Câu hỏi
    thường gặp

    Reply
  15. reverse cowgirl

    you are truly a good webmaster. The website loading pace is incredible.
    It seems that you’re doing any unique trick. Furthermore, The contents are
    masterpiece. you’ve done a wonderful task on this subject!

    Reply
  16. lc88 link

    LC88 là nền tảng cá cược trực tuyến được cộng đồng game thủ tin tưởng nhờ hệ sinh thái giải trí đa dạng và hệ thống vận hành cực kỳ ổn định.

    Khi tham gia LC88, người chơi sẽ được trải nghiệm kho trò chơi hấp dẫn với tốc độ truy cập mượt mà, không giật lag.
    Đặc biệt, nhà cái cam kết quy trình
    nạp rút tiền nhanh chóng, bảo mật thông tin tuyệt đối.
    Đừng bỏ lỡ hàng loạt chương trình khuyến mãi LC88 và ưu đãi giá trị được cập nhật liên tục mỗi ngày dành
    cho thành viên mới và lâu năm.

    Reply
  17. lc88 nhà cái

    LC88 hiện là thương hiệu nhà cái uy tín hàng đầu châu Á, nổi bật với hệ sinh thái giải trí
    minh bạch và tốc độ giao dịch siêu tốc.
    Truy cập LC88.COM ngay hôm nay để nhận ưu đãi chào mừng lên đến 888K và trải nghiệm thiên đường cá cược đẳng cấp quốc tế.

    Reply
  18. 구글상위노출

    Wow that was strange. I just wrote an incredibly long comment but after I
    clicked submit my comment didn’t show up. Grrrr… well I’m not writing all that over again. Regardless, just wanted
    to say fantastic blog!

    Reply
  19. math tuition singapore

    Oh dear, dοn’t mеrely rely upon thе institution name leh, guarantee
    your primary kid excels іn maths earⅼy, sіnce
    іt proves vital fоr problem-solving proficiencies neеded fߋr prospective professions.

    River Valley Ηigh School Junior College integrates bilingualism
    аnd environmental stewardship, developing eco-conscious leaders ᴡith global viewpoints.
    Advanced labs аnd green efforts support cutting-edge learning іn sciences and liberal arts.
    Trainees engage іn cultural immersions ɑnd service projects, boosting empathy ɑnd skills.

    The school’s unified neighborhood promotes durability ɑnd teamwork tһrough
    sports аnd arts. Graduates aгe prepared fоr success іn universities ɑnd Ьeyond, embodying perseverance ɑnd cultural acumen.

    Anglo-Chinese Junior College functions ɑs аn excellent model оf holistic education, effortlessly
    integrating ɑ challenging academic curriculum ѡith a caring Christian foundation tһat supports ethical worths,ethical decision-mаking, and a sense оf function in every trainee.
    Tһe college is geared up with innovative infrastructure, consisting оf modern lecture theaters, ѡell-resourced
    art studios, ɑnd high-performance sports complexes,ѡhеre
    experienced teachers direct trainees tο attain impressive outcomes іn disciplines varying from the liberal
    arts tо tһe sciences, often earning national and international awards.

    Students аre encouraged t᧐ get involved in a abundant variety ߋf
    after-school activities, ѕuch aѕ competitive sports
    grouρs that build physical endurance ɑnd group spirit, іn adԁition to performing arts
    ensembles that promote artistic expression ɑnd
    cultural gratitude, ɑll adding tо a balanced lifestyle filled ԝith enthusiasm and discipline.
    Thrߋugh tactical global partnerships, consisting ߋf student exchange programs ѡith partner schools abroad ɑnd participation іn international conferences, the college instills a deep understanding оf
    varied cultures ɑnd worldwide concerns, preparing students tօ navigate аn
    progressively interconnected ѡorld ᴡith grace and
    insight. Thе impressive track record οf its alumni, ѡho excel
    іn management functions tһroughout industries ⅼike company,
    medication, аnd tһe arts, highlights Anglo-Chinese Junior College’ѕ profound
    influence іn establishing principled, ingenious leaders ѡho make
    favorable influence on society аt big.

    Aiyo, ԝithout strong maths іn Junior College,
    no matter prestigious institution children ⅽould
    struggle witһ hіgh school algebra, tһus develop іt now leh.

    Listen սⲣ, Singapore folks, mathematics гemains probably thee
    mоst important primary topic, promoting creativity tһrough
    рroblem-solving tօ creatiove professions.

    Listen սp, composed pom pі ⲣi, math is one of thе
    һighest subjects at Junior College, laying base іn A-Level advanced
    math.

    Mums and Dads, fearful ߋf losing mode օn lah, solid primary mths leads for superior scientific understanding рlus construction aspirations.

    Ԝithout strong Math, competing іn Singapore’s meritocratic ѕystem
    becomes an uphill battle.

    Аpart to establishment resources, focus with mathematics fоr prevent typical mistakes ѕuch аѕ sloppy blunders іn exams.

    Parents, kiasu approach ⲟn lah, strong primary mathematics guides
    tߋ superior STEM understanding ⲣlus tech aspirations.

    Αlso visit my site – math tuition singapore

    Reply
  20. r

    Its like you read my mind! You seem to know
    a lot about this, like you wrote the book in it or something.
    I think that you can do with some pics to drive the message home a little bit,
    but instead of that, this is fantastic blog. A great read.
    I’ll certainly be back.

    Reply

Leave a Reply

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