Jump to content
tricecold

Scaling packed Objects with VEX

Recommended Posts

Hi, I need to find a way to scale packed objects but with VEX.

 

If I make a simple box, then pack it and use a transform to scale it it works as expected, but I need to accomplish this with VEX

 

so if I copied 100 boxes on a grid and applied the code below

 

all points move as expected, since point wrangle runs on points I get the same result without the loop also ( but thats another question)

 

for( int i=0; i<1; i++ ){
    @P.y += 1 + @Cd.r;
}
 
 
 
so I need to change the code above for scaling, any Ideas ???
 

Share this post


Link to post
Share on other sites

you need to modify intrinsic:transform of each primitive with intrinsic() and setintrinsic() VEX functions

 

vector scale = fit01(vector(rand(@primnum)), 0.2,1);

matrix3 trn = primintrinsic(0, "transform", @primnum);
matrix scalem = maketransform(0, 0, {0,0,0}, {0,0,0}, scale, @P);
trn *= matrix3(scalem);
setprimintrinsic(0, "transform", @primnum, trn);

 

attached file:

ts_scale_packed_VEX.hip

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

I have another question , apparently I need to do the same treatment to the convex Hull shapes in DOPS ( a collegue told me to scale convex hull shape instead of recalculation, which is imho great idea for performance reasons). Even thou the collision visibility shows correct scale, pieces always collide with the startup collision size, unless I change sop object to deforming to update from outside the DOPS, which then works fine but I have to scale the packed objects outside. I would like to keep the scaling in DOPS, because I might connect the scaling to some random conditions that might or might not occur during the simulation ? Any idea

Share this post


Link to post
Share on other sites

So here is an example file, of the above code working just fine, However the Convex Hull does not update, I am trying to scale the collision shape as well, instead of using use deforming active rigid objects. There has to be a way to scale the convex hull during simulation. Please Help

 

PackedScale_RBDs.hipnc

Edited by tricecold

Share this post


Link to post
Share on other sites

Hi Tim,

you can use ModifyData and link it to sopsolver.

 

See attached example, rbd (dopimport's) input is not time dependent. Scaling happens inside sopsolver.

 

I don't think that you can avoid using Active Deforming Object (I think it internally turns on some procedures that manage collision shape updates).

 

(If somebody have better (more in depth) explanation I would like to know).

pz_PackedScale_RBDs_in_DOPs.hipnc

Share this post


Link to post
Share on other sites
vector scale = fit01(vector(rand(@primnum)), 0.2,1);

matrix3 trn = primintrinsic(0, "transform", @primnum);
matrix scalem = maketransform(0, 0, {0,0,0}, {0,0,0}, scale, @P);
trn *= matrix3(scalem);
setprimintrinsic(0, "transform", @primnum, trn);

With @anim code, the scaling of the packed objects works great, but only if you want to scale up or down the original packed object by a given amount. I'm trying to replace the scale entirly with new values but due to 

trn *= matrix3(scalem);

I'm multiplying my previous value by a value. Can someone explain how I replace the scale instead of multiplying it please?

Share this post


Link to post
Share on other sites

I gave this a try, as this was something I missed as a feature for a long time and found a really simple solution: just delete the id attribute when scaling to force bullet to update the collision geometry. Not sure if this is the most elegant solution but it looks that it works fine even with sims with constraints.

i@id=-1 also works, so you can update it faster using Geometry wrangle instead of SOP solver + wrangle nodes.

 

float sc = 1.01;
vector scale = set(sc,sc,sc);
matrix3 trn = primintrinsic(0, "transform", @primnum); 
matrix scalem = maketransform(0, 0, {0,0,0}, {0,0,0}, scale, @P); 
trn *= matrix3(scalem); 
setprimintrinsic(0, "transform", @primnum, trn);

int pts[] = primpoints(0,i@primnum);
setpointattrib(0,"id",pts[0],-1);

 

Cheers!

  • Like 5

Share this post


Link to post
Share on other sites
4 minutes ago, tricecold said:

Jeff Wagner said that's the only way at the moment

Thanks, man!

Good to know!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×