CGTalk twist setting
 04-12-2013, 03:51 AM #1 JokerMartini Expert   portfolio John Martini CG Supervisor, 3D, Maxscript, VFX Ingenuity Engine Los Angeles, USA   Join Date: Mar 2009 Posts: 1,313 twist setting Looking to solve my twist issue in the math equation? Thank you for the help guys. Below is a function I'm using to generate verts between a start and end radius of verts. The twist function is collapsing the verts instead of retaining it's volume. The problem lies in my math question below somewhere. I looking for some help. Code: ``` fn genTweenSegs numHeightSegs:0 startHeight:0.0 maxHeight:0.0 startVerts:#() endVerts:#() biasHeight:0.0 powerHeight:0.0 biasRad:0.0 powerRad:0.0 = ( local tmpVerts = #() for eachSeg = 1.0 to numHeightSegs-1 do ( f = eachSeg/numHeightSegs h = maxHeight*(fastValue f bias:biasHeight power:powerHeight)+startHeight for v = 1 to startVerts.count do ( bottomRadius = startVerts[v] topRadius = endVerts[v] r = bottomRadius + (topRadius - bottomRadius)*(fastValue f bias:biasRad power:powerRad) mPos = [r[1],r[2],h] append tmpVerts mpos ) ) return tmpVerts )``` __________________ ____________ ___ __ _ John A. Martini JokerMartini@hotmail.com www.JokerMartini.com share quote
 04-12-2013, 10:23 PM #2 denisT MAX Doctor   portfolio Denis Trofimov CA, USA   Join Date: Jul 2009 Posts: 9,637 i don't have time to debug your code now, but here is a function that does do twist: Code: ``` fn twistPolyAboutZ node angle:45 = if iskindof node editable_poly do ( tm = node.objecttransform itm = inverse tm bb = nodeGetBoundingBox node tm for v=1 to node.numverts do ( p = (polyop.getvert node v) * itm a = (bb[2].z - p.z)/(bb[2].z - bb[1].z)*angle t = p * (rotatez (matrix3 1) a) * tm polyop.setvert node v t ) update node ) delete objects c = cylinder radius:20 height:40 heightsegs:8 sides:24 wirecolor:orange pos:[10,10,10] rotation:(eulerangles 40 20 50) twistPolyAboutZ (converttopoly c) angle:45 c = cone radius1:20 radius2:5 height:40 heightsegs:8 sides:24 wirecolor:green pos:[-10,-10,-10] rotation:(eulerangles -40 -20 -50) twistPolyAboutZ (converttopoly c) angle:90``` share quote
 04-12-2013, 10:41 PM #3 denisT MAX Doctor   portfolio Denis Trofimov CA, USA   Join Date: Jul 2009 Posts: 9,637 here is an expended version for all three axis Code: ```fn twistPoly node angle:45 axis:#z = if iskindof node editable_poly do ( k rotate = case axis of ( #x: (k = 1; rotatex) #y: (k = 2; rotatey) #z: (k = 3; rotatez) ) tm = node.objecttransform itm = inverse tm bb = nodeGetBoundingBox node tm for v=1 to node.numverts do ( p = (polyop.getvert node v) * itm a = (bb[2][k] - p[k])/(bb[2][k] - bb[1][k])*angle t = p * (rotate (matrix3 1) a) * tm polyop.setvert node v t ) update node ) delete objects c = cylinder radius:20 height:40 heightsegs:8 sides:24 wirecolor:orange pos:[10,10,10] rotation:(eulerangles 40 20 50) twistPoly (converttopoly c) angle:65 axis:#x c = cone radius1:20 radius2:5 height:40 heightsegs:8 sides:24 wirecolor:green pos:[-10,-10,-10] rotation:(eulerangles -40 -20 -50) twistPoly (converttopoly c) angle:180 axis:#z twistPoly c angle:45 axis:#y``` share quote
 04-12-2013, 10:45 PM #4 JokerMartini Expert   portfolio John Martini CG Supervisor, 3D, Maxscript, VFX Ingenuity Engine Los Angeles, USA   Join Date: Mar 2009 Posts: 1,313 I ended up messing with it a bit last night and I got a similar setup. I'm going to add bias and what not to this as well. I'll post that version. __________________ ____________ ___ __ _ John A. Martini JokerMartini@hotmail.com www.JokerMartini.com share quote
 04-23-2013, 01:48 PM #5 JokerMartini Expert   portfolio John Martini CG Supervisor, 3D, Maxscript, VFX Ingenuity Engine Los Angeles, USA   Join Date: Mar 2009 Posts: 1,313 Denis Denis here is an idea. I've taken your script and added just a few lines to show what a bend would look like. How would the function be modifier to replicate that of the actual bend modifier, assuming the base pivot of the rotation is always at the base center of the object like in the example? Code: ``` fn twistPoly node angle:45 axis:#z = if iskindof node editable_poly do ( k rotate = case axis of ( #x: (k = 1; rotatex) #y: (k = 2; rotatey) #z: (k = 3; rotatez) ) tm = node.objecttransform itm = inverse tm bb = nodeGetBoundingBox node tm for v=1 to node.numverts do ( p = (polyop.getvert node v) * itm a = (bb[2][k] - p[k])/(bb[2][k] - bb[1][k])*angle t = p * (rotate (matrix3 1) a) * tm polyop.setvert node v t ) update node ) delete objects c = cylinder radius:10 height:40 heightsegs:8 sides:24 wirecolor:orange pos:[0,0,0] rotation:(eulerangles 0 0 0) twistPoly (converttopoly c) angle:90 axis:#x c = cylinder radius:10 height:40 heightsegs:8 sides:24 wirecolor:orange pos:[0,60,0] rotation:(eulerangles 0 0 0) addmodifier c (bend angle:90 direction:90)``` __________________ ____________ ___ __ _ John A. Martini JokerMartini@hotmail.com www.JokerMartini.com share quote
 04-23-2013, 02:30 PM #6 JokerMartini Expert   portfolio John Martini CG Supervisor, 3D, Maxscript, VFX Ingenuity Engine Los Angeles, USA   Join Date: Mar 2009 Posts: 1,313 simplified for testing use for testing Code: ``` ( local startRadius = 10.0 local endRadius = 5.0 local height = (units.decodevalue "30.0cm") local heightSegs = 20 local columns = 8 local columnAngle = 360.0 / columns local bendAngle = 45.0 clearlistener() delete objects for row = 1.0 to heightSegs do ( f = row/heightSegs stepHeight = height*f curRadius = startRadius + (endRadius - startRadius)*f curBend = bendAngle*f --*(fastValue f bias:0.0 power:10.0) col = random white white for c = 1 to columns do ( calcX = curRadius * cos((c-1) * columnAngle) calcY = curRadius * sin((c-1) * columnAngle) orgPos = [calcX,calcY,stepHeight] /* BENDING */ tm = rotateY (transmatrix orgPos) curBend bentPos = (tm * (matrix3 1)).pos point pos:bentPos size:1 wirecolor:col ) ) c = cone radius1:10 radius2:5 pos:[0,0,0] addmodifier c (Bend angle:bendAngle) )``` __________________ ____________ ___ __ _ John A. Martini JokerMartini@hotmail.com www.JokerMartini.com Last edited by JokerMartini : 04-23-2013 at 09:02 PM. share quote
 04-23-2013, 08:21 PM #7 JokerMartini Expert   portfolio John Martini CG Supervisor, 3D, Maxscript, VFX Ingenuity Engine Los Angeles, USA   Join Date: Mar 2009 Posts: 1,313 anyone have any ideas on how to properly do a bend on an objects verts without using the the bend modifier? __________________ ____________ ___ __ _ John A. Martini JokerMartini@hotmail.com www.JokerMartini.com share quote
 04-23-2013, 08:21 PM #8 CGTalk Moderation Expert   Join Date: Sep 2003 Posts: 1,066,478 Thread automatically closed This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum. __________________ CGTalk Policy/Legalities Note that as CGTalk Members, you agree to the terms and conditions of using this website. share quote