| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | import pymel.core as pm; import pymel.core.datatypes as dt; import maya.mel as cmds; from math import *; class SplineGeometryGenerator:     def __init__(self, curveName, splineDivisions):         self.curveName = curveName;         self.splineDivisions = splineDivisions;     def getPointOnCurve( self, curveTransformName, t ):         curve = pm.listRelatives( curveTransformName )[0];         spans = pm.getAttr( "{0}.spans".format( curve ) );         cpCount = spans;         lt = t * cpCount;         point = pm.pointOnCurve( curve, pr=lt );         return point;     def generate(self, cookieMesh):         curveStartPoint = self.getPointOnCurve(self.curveName, 0.0 );         curveNextPoint = self.getPointOnCurve(self.curveName, 0.0001 );         dx = curveStartPoint[0] - curveNextPoint[0];         dy = curveStartPoint[1] - curveNextPoint[1];         dz = curveStartPoint[2] - curveNextPoint[2];         look = dt.Vector( dx, dy, dz ).normal();         up = dt.Vector( 0.0, 1.0, 0.0 )         if abs( look.dot(up) ) >= 0.999:             up = dt.Vector( 0.0, 0.0, 1.0 );         right = look.cross( up ).normal();         up = look.cross( right ).normal();         mat = dt.TransformationMatrix();         mat.a00 = right.x; mat.a01 = right.y; mat.a02 = right.z; mat.a03 = 0.00;         mat.a10 = up.x; mat.a11 = up.y; mat.a12 = up.z; mat.a13 = 0.00;         mat.a20 = look.x; mat.a21 = look.y; mat.a22 = look.z; mat.a23 = 0.00;         mat.a30 = curveStartPoint[0]; mat.a31 = curveStartPoint[1]; mat.a32 = curveStartPoint[2]; mat.a33 = 1.00;         pm.xform( cookieMesh, matrix = mat );         pm.polyExtrudeFacet( "{0}".format(cookieMesh), inc=self.curveName, divisions=self.splineDivisions); class CubeSplineGeometryGenerator(SplineGeometryGenerator):     def __init__(self, curveName, splineDivisions, scaleVec):         self.scaleVec = scaleVec;         SplineGeometryGenerator.__init__(self, curveName, splineDivisions);     def createMeshCookie( self, scaleVec ):             verts = [         ( -scaleVec[0], -scaleVec[1], 0.0 ),         ( -scaleVec[0], scaleVec[1], 0.0 ),         (  scaleVec[0], scaleVec[1], 0.0 ),         (  scaleVec[0], -scaleVec[1], 0.0 )         ];         mesh = pm.polyCreateFacet(point=verts)[0];         return mesh;     def generate( self ):         mesh = self.createMeshCookie( self.scaleVec );         SplineGeometryGenerator.generate( self, mesh );      class TriangleSplineGeometryGenerator(SplineGeometryGenerator):     def __init__(self, curveName, splineDivisions, scaleVec):         self.scaleVec = scaleVec;         SplineGeometryGenerator.__init__(self, curveName, splineDivisions);     def createMeshCookie( self, scaleVec ):         verts = [         (  scaleVec[0], 0.0, 0.0 ),         ( 0.0, -scaleVec[1], 0.0 ),         ( -scaleVec[0], 0.0, 0.0 )         ];         mesh = pm.polyCreateFacet(point=verts)[0];         return mesh;     def generate( self ):         mesh = self.createMeshCookie( self.scaleVec );         SplineGeometryGenerator.generate( self, mesh ); class CylinderSplineGeometryGenerator(SplineGeometryGenerator):     def __init__(self, curveName, splineDivisions, scaleVec, cylinderDivisions):         self.scaleVec = scaleVec;         self.cylinderDivisions = cylinderDivisions;         SplineGeometryGenerator.__init__(self, curveName, splineDivisions);     def createMeshCookie( self, scaleVec, cylinderDivisions ):         twoPi = 3.14159 * 2.0;         angleInc = twoPi / cylinderDivisions;         verts = [];         t = 0.00;         radians = 0.00;         while t <= 1.0:             x = cos(radians) * scaleVec[0];             y = sin( radians ) * scaleVec[1];             verts.append( [x, y, 0.0] );             radians -= angleInc;             t = -radians / twoPi;         mesh = pm.polyCreateFacet(point=verts)[0];         return mesh     def generate( self ):         mesh = self.createMeshCookie( self.scaleVec, self.cylinderDivisions );         SplineGeometryGenerator.generate( self, mesh ); #spline = CubeSplineGeometryGenerator("curve1", 100.0, [1.0, 1.0]); #spline = TriangleSplineGeometryGenerator("curve1", 120.0, [1.0, 1.0]); spline = CylinderSplineGeometryGenerator("curve1", 200.0, [1.0, 1.0], 20); spline.generate(); | 
Video:
