Jump to content
ianwww

Change radius of sphere primitive in vex

Recommended Posts

I've created a sphere primitive in vex, using:

centre_pt = addpoint(0, pos);   
sphere_prim = addprim(0, 'sphere', centre_pt);

I want to be able to vary its size in the viewport but can't work out how to do it.  When a sphere prim is added using a SOP, the sphere's size can be changed using scale (the Uniform scale slider).  I thought that this vex would therefore do the same thing:

setprimattrib(0, 'scale', sphere_prim, chf('sphere_size'), 'set');

but changing chf('sphere_size') has no effect on the sphere's size. (I've also tried replacing 'scale' with 'radius', and also with 'radx', 'rady' and 'radz'.)

I've found this link cgwiki which explains how to do it for a prim that has multiple points but a sphere prim only has its single central point.

How can I change a sphere prim's size in vex?

Share this post


Link to post
Share on other sites

Hi Ian, set and scale a transform matrix:

float scale = chf('scale');
vector pos = chv('position');

int pt = addpoint(0, pos);
matrix3 xform = ident();
xform *= scale;

int prim = addprim(0, 'sphere', pt);
setprimintrinsic(0, 'transform', prim, xform);

 

Share this post


Link to post
Share on other sites

Brilliant - that did it!  Thanks Konstantin.  I would never have worked that out by myself...!

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

×