Jump to content

Scaling packed Objects with VEX


tricecold

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 ???
 
Link to comment
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 2
  • Thanks 2
Link to comment
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

Link to comment
Share on other sites

  • 1 month later...

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
Link to comment
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

Link to comment
Share on other sites

  • 11 months later...
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?

Link to comment
Share on other sites

  • 4 weeks later...

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
Link to comment
Share on other sites

  • 3 months later...
  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...