Trilec Posted June 15, 2020 Share Posted June 15, 2020 Thought I'd share a little primitive center rotation snippet, any comments welcome. Note: Requires connectivity node upstream set to primitive and attrib "class". //Rotate primitive around center and defined axis int points[] = primpoints(0, @primnum); vector axis = set(0,1,0); //define user axis //vector axis = normalize(@N); //if normal axis is required float angle = ch('angle'); matrix3 rotm = ident(); rotate(rotm, radians(angle), axis); //get center (requires connectivity node, set primitime and sttrib "class") string grp = '\@class='+itoa(i@class); vector CenterPivot = getbbox_center(0,grp); vector pos; // move points to origin, rotate, move back foreach(int pt; points) { pos = point(0,"P",pt); pos -= CenterPivot; pos *= rotm; pos += CenterPivot; setpointattrib(0,"P",pt,pos, "set"); } 1 Quote Link to comment Share on other sites More sharing options...
konstantin magnus Posted June 15, 2020 Share Posted June 15, 2020 Hi Curt, once you have defined primitive classes, you could also run this over points: float amount = radians(chf('angle')); vector axis = normalize(chv('axis')); int class = prim(0, 'class', i@primnum); string grp = '@class==' + itoa(class); vector pivot = getbbox_center(0, grp); matrix m_rot = ident(); rotate(m_rot, amount, axis); vector pos = (v@P - pivot) * m_rot + pivot; v@P = pos; v@N *= m_rot; 2 Quote Link to comment Share on other sites More sharing options...
Trilec Posted June 15, 2020 Author Share Posted June 15, 2020 (edited) Thanks Konstantin , For curiosity sake, would this section be executed per/particle, does Houdini optimize for this? (thinking multi threading). int class = prim(0, 'class', i@primnum); string grp = '@class==' + itoa(class); vector pivot = getbbox_center(0, grp); matrix m_rot = ident(); rotate(m_rot, amount, axis); C Edited June 15, 2020 by Trilec Quote Link to comment Share on other sites More sharing options...
konstantin magnus Posted June 16, 2020 Share Posted June 16, 2020 10 hours ago, Trilec said: Thanks Konstantin , For curiosity sake, would this section be executed per/particle, does Houdini optimize for this? (thinking multi threading). Exactly. You would need to inspect the performance monitor to make sure it really is more performant, though. We've already had some cases where code that looks elegant does not perform too well and vice versa. Unfortunately I could not point you to a resource that goes deep about the inner workings and performance of VEX code. Quote Link to comment Share on other sites More sharing options...
Trilec Posted June 16, 2020 Author Share Posted June 16, 2020 thanks again, often its "un-optimized meany, can be faster than optimized few". Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.