Ejemplo n.º 1
0
def createController(object):
    # object = pma.ls(sl=True)
    pivotObj = pma.xform(object, query=True, t=True, worldSpace=True)
    edges = pma.filterExpand(pma.polyListComponentConversion(te=1), sm=32,
                             ex=1)  # convert edges to curve ancd create one object
    for edge in edges:
        vtx = pma.ls(pma.polyListComponentConversion(edge, fe=1, tv=1), fl=1)
        p1 = pma.pointPosition(vtx[0])
        p2 = pma.pointPosition(vtx[1])
        curves = pma.curve(n="line_ctrl_curve", d=1, p=(p1, p2))

    ctrl = pma.curve(n="bool_ctrl", d=1, ws=True, p=pivotObj)
    pma.xform(centerPivots=True)
    for curveEdge in pma.ls("line_ctrl*"):
        pma.parent(curveEdge, ctrl, s=1, r=1)
        pma.rename(curveEdge, "shapeunused")

    transforms = pma.ls(type='transform')
    deleteList = []
    for tran in transforms:
        if pma.nodeType(tran) == 'transform':
            children = pma.listRelatives(tran, c=True)
            if children is None:
                # print '%s, has no childred' %(tran)
                deleteList.append(tran)

    if not deleteList:
        pma.delete(deleteList)
    return ctrl
Ejemplo n.º 2
0
def curve_through_points(**kwargs):
    selection_points = kwargs.get("selection_points", None)
    curve_degree = kwargs.get("curve_degree", 3)
    curve_name = kwargs.get("curve_name", "Curve")

    if not selection_points:
        selection_points = pm.ls(selection=True)
        if not selection_points:
            pm.displayInfo("Please select reference points")
            return None
    if len(selection_points) < curve_degree + 1:
        pm.displayInfo("please select more than " + str(curve_degree + 1) +
                       " points")
        return None

    points_locations = []
    for point in selection_points:
        points_locations.append(
            pm.xform(point, query=True, translation=True, worldSpace=True))
    pm.select(clear=True)
    current_curve = pm.curve(degree=curve_degree,
                             worldSpace=True,
                             point=points_locations)
    pm.rename(current_curve, curve_name)
    return current_curve
Ejemplo n.º 3
0
    def displayConnect(self, obj):
        # Create curve for display, between selected objects
        # Return [curve, locator1, locator2]
        if len(obj) == 0:
            obj = pm.ls(transforms=1, sl=1)

        if len(obj) < 2:
            pm.error(u"KH_curve_Connect : 선택된 오브젝트가 없습니다.")

        pointA = obj[0]
        pointB = obj[1]

        curve = pm.curve(p=[(0, 0, 0), (0, 0, 0)], k=[0, 1], d=1)
        pointCurveConstraint1 = pm.pointCurveConstraint(curve + ".ep[0]",
                                                        ch=True)
        pointCurveConstraint2 = pm.pointCurveConstraint(curve + ".ep[1]",
                                                        ch=True)

        pointCostraint1 = pm.pointConstraint(pointA, pointCurveConstraint1[0])
        pointCostraint2 = pm.pointConstraint(pointB, pointCurveConstraint2[0])

        locShape1 = pm.listRelatives(pointCurveConstraint1[0], s=1)
        locShape2 = pm.listRelatives(pointCurveConstraint2[0], s=1)
        pm.setAttr(locShape1[0] + ".visibility", 0)
        pm.setAttr(locShape2[0] + ".visibility", 0)

        return [
            curve,
            pm.PyNode(pointCurveConstraint1[0]),
            pm.PyNode(pointCurveConstraint2[0]), pointCostraint1,
            pointCostraint2
        ]
Ejemplo n.º 4
0
def __create_curve_from_edge(edge):
    edgeloop = __get_edge_loop(edge, [], None)
    edgeloop.insert(0, edge)
    edge_curves = []
    for edgeloop_edge in edgeloop:
        edge_curves.append(
            pm.curve(
                # name=n,
                degree=1,
                ws=True,
                point=[
                    v.getPosition() for v in edgeloop_edge.connectedVertices()
                ]))

    pm.select(None)
    if (len(edge_curves) > 1):
        merged_curve = pm.attachCurve(edge_curves[:-1],
                                      method=1,
                                      keepMultipleKnots=False,
                                      ch=False)[0]
        edge_curves.pop(edge_curves.index(merged_curve))
        # closed_curve = pm.closeCurve( merged_curve )[0]
        closed_curve = merged_curve
        # pm.delete( merged_curve )
    else:
        closed_curve = None
    pm.delete(edge_curves)
    return closed_curve, edgeloop
Ejemplo n.º 5
0
def curve_through_points(**kwargs):
    selection_points = pm.ls(selection=True)
    curve_name = kwargs.get("curve_name", "")
    curve_degree = kwargs.get("curve_degree", 1)
    points_locations = kwargs.get("position_list", [])
    pm.select(clear=True)
    current_curve = pm.curve(degree = curve_degree, worldSpace=True, point = points_locations)
    pm.rename(current_curve, curve_name)
    return None
Ejemplo n.º 6
0
def build_box(car_name):
    """Method 1 - This buider make box strucutre (not strong)
    """
    sel = pm.ls(sl=True)

    group = pm.group(name=car_name + '_group', empty=True)
    nodes_group = pm.group(name='nodes_group', empty=True, parent=group)
    beams_group = pm.group(name='beams_group', empty=True, parent=group)

    if not sel:
        return

    trans = sel[0]
    mesh = trans.getShape()
    pm.hide(trans)

    d = {}
    verts = mesh.verts
    for index, vtx in enumerate(verts):

        loc = pm.spaceLocator()
        loc.rename('b' + str(index))
        loc.t.set(vtx.getPosition(space='world'))
        loc.overrideEnabled.set(True)
        loc.overrideColor.set(17)
        loc.setParent(nodes_group)

        index = vtx.index()
        d[index] = {'loc': loc, 'connected': []}

        for c in vtx.connectedVertices():
            c_index = c.index()
            if c_index < index:
                continue
            d[index]['connected'].append(c_index)

    index = 0
    for each in d:
        loc = d[each]['loc']

        for other in d[each]['connected']:
            other_loc = d[other]['loc']

            curve = pm.curve(p=[(0, 0, 0), (1, 0, 0)], degree=1)
            curve.rename('beam_' + str(index))
            shape = curve.getShape()
            curve.overrideEnabled.set(True)
            curve.overrideColor.set(15)
            lock_hide(curve)
            loc.t >> shape.controlPoints[0]
            other_loc.t >> shape.controlPoints[1]
            curve.setParent(beams_group)
            index += 1

    pm.select(clear=True)
Ejemplo n.º 7
0
def make_beam(index, c, group):
    """Make a beam from 2 Nodes
    """
    curve = pm.curve(p=[(0, 0, 0), (1, 0, 0)], degree=1)
    curve.rename('beam_' + str(index))
    shape = curve.getShape()
    curve.overrideEnabled.set(True)
    curve.overrideColor.set(15)
    lock_hide(curve)

    start = pm.DependNode(str(c[0]))
    end = pm.DependNode(str(c[1]))

    start.t >> shape.controlPoints[0]
    end.t >> shape.controlPoints[1]
    curve.setParent(group)
    index += 1
Ejemplo n.º 8
0
def curve_through_points(**kwargs):
    selection_points = pm.ls(selection=True)
    mt_pth = kwargs.get("motion_path", False)
    if len(selection_points) < 2:
        print "please select more than one points"
        return None
    curve_name = kwargs.get("curve_name", "")
    curve_degree = kwargs.get("curve_degree", 1)
    points_locations = []
    for point in selection_points:
        points_locations.append(
            pm.xform(point, query=True, translation=True, worldSpace=True))
    pm.select(clear=True)
    current_curve = pm.curve(degree=curve_degree,
                             worldSpace=True,
                             point=points_locations)
    pm.rename(current_curve, curve_name)
    print "CRV", current_curve
    if mt_pth:
        motion_path(objs=selection_points, path_curve=current_curve)
    return None
def __create_curve_from_edge( edge ) :
	edgeloop = __get_edge_loop( edge, [], None )
	edgeloop.insert(0, edge )
	edge_curves = []
	for edgeloop_edge in edgeloop :
		edge_curves.append( pm.curve(
			# name=n,
			degree=1,
			ws=True,
			point=[ v.getPosition() for v in edgeloop_edge.connectedVertices() ]
		) )	

	pm.select(None)
	if( len( edge_curves ) > 1 ) :
		merged_curve = pm.attachCurve( edge_curves[:-1], method=1, keepMultipleKnots=False, ch=False )[0]
		edge_curves.pop( edge_curves.index(merged_curve) )
		# closed_curve = pm.closeCurve( merged_curve )[0]
		closed_curve = merged_curve
		# pm.delete( merged_curve )
	else :
		closed_curve = None
	pm.delete( edge_curves )		
	return closed_curve, edgeloop
def project_curves_onto_mesh2( mesh, source_mesh, direction ) :
	# duplicate sources_mesh
	dup_source_mesh = pm.duplicate( source_mesh )[0]
	dup_source_mesh.setParent(None)

	# create curve around mesh	
	edge_curves = []
	for edge in mesh.getShape().e :
		edge_curves.append( pm.curve(
			# name=n,
			degree=1,
			ws=True,
			point=[ v.getPosition(space='world') for v in edge.connectedVertices() ]
		) )
	merged_curve = pm.attachCurve( edge_curves, method=1, keepMultipleKnots=False, ch=False )[0]
	merged_curve = pm.duplicate( merged_curve )
	pm.delete( edge_curves )

	# project curve onto dup_source_mesh	
	projected_curves = projected_curves = pm.polyProjectCurve( dup_source_mesh, merged_curve, direction=direction )[0]
	# pm.delete( projected_curves.getChildren()[1:] )
	projected_curve = projected_curves.getChildren()[0]

	split_mesh = pm.polySplit( dup_source_mesh, detachEdges=0, projectedCurve=projected_curve )	
	split_mesh = split_mesh[0]	

	# delete faces not within mesh bounds
	# faces_to_delete = []
	pm.select(None)
	for face in split_mesh.f :
		face_center = ( 0.0, 0.0, 0.0 )
		for v in face.connectedVertices() :
			face_center += v.getPosition( space='world' )
		face_center /= len( face.connectedVertices() )		

		if( point_in_rect_bb( face_center, mesh.getBoundingBox( space='world' ) ) ) :
			# faces_to_delete.append( face )
			dot = face.getNormal( space='world' ).dot( mesh.f[0].getNormal( space='world' ) )
			if( dot > 0.0 )	 :
				pm.select(face, add=True)
		
	# for face in faces_to_delete :		
	# 	dot = face.getNormal( space='world' ).dot( mesh.f[0].getNormal( space='world' ) )
	# 	if( dot > 0.0 )	 :
	# 		pm.select(face, add=True)

	pm.runtime.InvertSelection()
	pm.delete()

	# transfer UVs from mesh to dup_source_mesh
	pm.transferAttributes( mesh, split_mesh, transferUVs=2 )

	# assign mesh material to dup_source_mesh


	# rename dup_source_mesh to mesh
	pm.delete( split_mesh, ch=True )
	n = mesh.name()
	p = mesh.getParent()
	pm.delete( mesh )
	split_mesh.rename( n )

	for attr in split_mesh.listAttr() :		
		if attr.isLocked() : attr.setLocked(False)


	# cleanup

	pm.delete( projected_curves )
	pm.delete( merged_curve )
	pm.delete( dup_source_mesh )

	# split_mesh.centerPivots( True )
	# t = split_mesh.getPivots( worldSpace=1 )[0]
	# split_mesh.setTranslation((-t[0], -t[1], -t[2]), space='world')		
	# pm.makeIdentity( split_mesh, apply=True )
	# split_mesh.setParent( p )
	# split_mesh.setTranslation( ( 0,0,0 ) )
	# pm.makeIdentity( split_mesh, apply=True )

	# position bodge
	split_mesh.setTranslation( ( 0, 0, 1 ), space='world' )
	split_mesh.setParent( p )

	pm.polyTriangulate( split_mesh )

	if( not split_mesh.hasAttr( THU_MFT_SPRITE_ATTR ) ) :
		split_mesh.addAttr( THU_MFT_SPRITE_ATTR, dt='string' )
	split_mesh.setAttr( THU_MFT_SPRITE_ATTR, split_mesh.name().replace( '.png', '' ) )
Ejemplo n.º 11
0
	def create( self, _jointchain=None ) :
		super( IkRig, self ).create( _jointchain )

		jointchains = self.tree_children( 'jointchain' )
		if( len( jointchains ) != 1 ) :
			utils.err( 'IkRig children includes more than ONE jointchain. Not sure which to use. Skipping...' )
			return False		

		jointchain = jointchains[0]

		# create a simple joint chain
		simplejointchain = jointchain.duplicate_jointchain( self.PARTNAME, 'driver', _simple=True )
		self.add_child( simplejointchain )
		
		pm.PyNode( 'leftUpperArm_1_IKJ_DRIVER' ).hide()
		pm.PyNode( 'leftUpperArm_1_j' ).hide()

		for i in range( len( simplejointchain.rigjoints ) - 1 ) :
			# create a curve between each pair of simple rigjoints
			rigjoint1 = simplejointchain.rigjoints[i]
			rigjoint2 = simplejointchain.rigjoints[i+1]

			v1 = pm.datatypes.Vector( rigjoint1.getTranslation( space='world' ) )
			v2 = pm.datatypes.Vector( rigjoint2.getTranslation( space='world' ) )
			curvelength = float( v1.distanceTo( v2 ) )

			dirvector = [ a * b for a, b in zip( 
				( curvelength, curvelength, curvelength ),
				utils.aim_axis_to_vectors( settings.rotationorder )[0]
			) ]

			curve = pm.curve( degree=1, point=[
				( 0, 0, 0 ),
				dirvector
				# v1, v2
			], name=utils.name_from_tags( rigjoint1, 'curve' ) )

			# rebuild with numspan 2 and 3 degree
			pm.rebuildCurve( curve, degree=3, spans=2 )

			# move vtx[1] and vtx[-2] to respective ends of curve		
			curve.cv[1].setPosition( curve.cv[0].getPosition( space='world' ), space='world' )
			curve.cv[-2].setPosition( curve.cv[-1].getPosition( space='world' ), space='world' )

			ribbonlength = 0.2

			ribbon = pm.extrude(
				curve,
				polygon=0,
				useProfileNormal=1,
				extrudeType=0,
				length=ribbonlength,
				ch=False,
				name=utils.name_from_tags( rigjoint1, 'nurbs' )
			)[0]

			ribbon.setTranslation( ( 0, 0, -(ribbonlength)/2 ) )
			ribbon.setPivots( ( 0, 0, 0 ), worldSpace=True )
			pm.makeIdentity( ribbon, apply=True )
			pm.delete( ribbon, ch=True )
			pm.delete( curve )

			utils.create_zero_sdk_groups( ribbon, _replacelast=False )

			startcluster = pm.cluster( 	ribbon.cv[0:1][0:1], name=utils.name_from_tags( rigjoint1, 'start', 'cluster') )[1]
			midcluster = pm.cluster( 	ribbon.cv[2][0:1], name=utils.name_from_tags( rigjoint1, 'mid', 'cluster' ) )[1]
			endcluster = pm.cluster( 	ribbon.cv[-2:][0:1], name=utils.name_from_tags( rigjoint1, 'end', 'cluster' ) )[1]

			# parent clusters to respective rigjoints
			pm.parentConstraint( [ rigjoint1, startcluster ], mo=False )
			pm.parentConstraint( [ rigjoint2, endcluster ], mo=False )

			# group then point/parent constrain middle cluster to end clusters
			sdkgroup, zerogroup = utils.create_zero_sdk_groups( midcluster, _replacelast=False )
			zerogroup.setRotation( rigjoint1.getRotation( space='world' ), space='world' )
			pm.pointConstraint( [ rigjoint1, rigjoint2, zerogroup ], mo=False )
			pm.orientConstraint( [ rigjoint1, zerogroup ], mo=False )

			jointsToAttachToCurve = [ jointchain.rigjoints[i] ]
			jointsToAttachToCurve += jointchain.minorrigjoints[ jointsToAttachToCurve[0] ]
			jointsToAttachToCurve += [ jointchain.rigjoints[i+1] ]

	
			for rigjoint in jointsToAttachToCurve :

				p = rigjoint.getTranslation( space='world' )
				posi = pm.nodetypes.ClosestPointOnSurface()
				ribbon.worldSpace >> posi.inputSurface
				posi.inPosition.set( p )
				u = min( max( posi.u.get(), 0.001 ), 0.999 )
				v = min( max( posi.v.get(), 0.001 ), 0.999 )

				pm.delete( posi )

				follicleshape = pm.nodetypes.Follicle()
				ribbon.local >> follicleshape.inputSurface
				ribbon.worldMatrix[0] >> follicleshape.inputWorldMatrix
				follicleshape.parameterU.set( u )
				follicleshape.parameterV.set( v )
				
				follicle = follicleshape.getParent()
				follicle.rename( utils.name_from_tags( rigjoint, 'follicle' ) )
				follicleshape.rename( follicle.name() + 'Shape' )

				follicleshape.outRotate >> follicle.rotate
				follicleshape.outTranslate >> follicle.translate

				# remove any constraints already on the joint
				pm.delete( rigjoint.getChildren( type='constraint' ) )

				pm.parentConstraint( [ follicle, rigjoint ], mo=True )
				

		return True
Ejemplo n.º 12
0
    def create_ctrl(self):

        if self.shape == CreateCtrl.triangle:
            ctrl = pm.curve(name=self.name,
                            d=1,
                            p=[(-1, 0, 1), (1, 0, 1), (0, 0, -1), (-1, 0, 1)],
                            k=[
                                0,
                                1,
                                2,
                                3,
                            ])

        elif self.shape == CreateCtrl.square:
            ctrl = pm.curve(name=self.name,
                            degree=1,
                            point=[(0, 2, 2), (0, 2, -2), (0, -2, -2),
                                   (0, -2, 2), (0, 2, 2)])

        elif self.shape == CreateCtrl.octagon:
            ctrl = pm.curve(name=self.name,
                            degree=1,
                            point=[(0, 3, 1), (0, 3, -1), (0, 1, -3),
                                   (0, -1, -3), (0, -3, -1), (0, -3, 1),
                                   (0, -1, 3), (0, 1, 3), (0, 3, 1)])

        elif self.shape == CreateCtrl.circle:
            ctrl = pm.circle(name=self.name,
                             normalX=1,
                             normalZ=0,
                             radius=2,
                             constructionHistory=False)[0]

        elif self.shape == CreateCtrl.cube:
            ctrl = pm.curve(name=self.name,
                            degree=1,
                            point=[(1, 1, 1), (1, 1, -1), (-1, 1, -1),
                                   (-1, 1, 1), (1, 1, 1), (1, -1, 1),
                                   (1, -1, -1), (-1, -1, -1), (-1, -1, 1),
                                   (1, -1, 1), (1, -1, -1), (1, 1, -1),
                                   (-1, 1, -1), (-1, -1, -1), (-1, -1, 1),
                                   (-1, 1, 1)])

        elif self.shape == CreateCtrl.pyramid:
            ctrl = pm.curve(name=self.name,
                            degree=1,
                            point=[(1, 2, 1), (1, 2, -1), (-1, 2, -1),
                                   (-1, 2, 1), (1, 2, 1), (0, 0, 0),
                                   (1, 2, -1), (-1, 2, -1), (0, 0, 0),
                                   (-1, 2, 1)])
        elif self.shape == CreateCtrl.cone:
            ctrl = pm.curve(name=self.name,
                            d=1,
                            p=[(-0.5, 2, 0.866025), (0, 0, 0),
                               (0.5, 2, 0.866025), (-0.5, 2, 0.866025),
                               (-1, 2, -1.5885e-07), (0, 0, 0),
                               (-1, 2, -1.5885e-07), (-0.5, 2, -0.866026),
                               (0, 0, 0), (0.5, 2, -0.866025),
                               (-0.5, 2, -0.866026), (0.5, 2, -0.866025),
                               (0, 0, 0), (1, 2, 0), (0.5, 2, -0.866025),
                               (1, 2, 0), (0.5, 2, 0.866025)],
                            k=[
                                0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
                                14, 15, 16
                            ])

        elif self.shape == CreateCtrl.diamond:
            ctrl = pm.curve(name=self.name,
                            degree=1,
                            point=[(1, 0, 1), (1, 0, -1), (-1, 0, -1),
                                   (-1, 0, 1),
                                   (1, 0, 1), (0, -2, 0), (1, 0, -1),
                                   (-1, 0, -1), (0, -2, 0), (-1, 0, 1),
                                   (1, 0, 1), (0, 2, 0), (1, 0, -1),
                                   (-1, 0, -1), (0, 2, 0), (-1, 0, 1)])

        elif self.shape == CreateCtrl.one_arrow:
            ctrl = pm.curve(name=self.name,
                            d=1,
                            p=[(0, 1.003235, 0), (0.668823, 0, 0),
                               (0.334412, 0, 0), (0.334412, -0.167206, 0),
                               (0.334412, -0.501617, 0),
                               (0.334412, -1.003235, 0),
                               (-0.334412, -1.003235, 0),
                               (-0.334412, -0.501617, 0),
                               (-0.334412, -0.167206, 0), (-0.334412, 0, 0),
                               (-0.668823, 0, 0), (0, 1.003235, 0)],
                            k=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])

        elif self.shape == CreateCtrl.two_arrow:
            ctrl = pm.curve(name=self.name,
                            d=1,
                            p=[
                                (0, 1, 0),
                                (1, 1, 0),
                                (2, 1, 0),
                                (3, 1, 0),
                                (3, 2, 0),
                                (4, 1, 0),
                                (5, 0, 0),
                                (4, -1, 0),
                                (3, -2, 0),
                                (3, -1, 0),
                                (2, -1, 0),
                                (1, -1, 0),
                                (0, -1, 0),
                                (-1, -1, 0),
                                (-2, -1, 0),
                                (-3, -1, 0),
                                (-3, -2, 0),
                                (-4, -1, 0),
                                (-5, 0, 0),
                                (-4, 1, 0),
                                (-3, 2, 0),
                                (-3, 1, 0),
                                (-2, 1, 0),
                                (-1, 1, 0),
                                (0, 1, 0),
                            ],
                            k=[
                                0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
                                14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24
                            ])

        elif self.shape == CreateCtrl.two_arrow_curved:
            ctrl = pm.curve(name=self.name,
                            d=1,
                            p=[(-0.251045, 0, -1.015808),
                               (-0.761834, 0, -0.979696),
                               (-0.486547, 0, -0.930468),
                               (-0.570736, 0, -0.886448),
                               (-0.72786, 0, -0.774834),
                               (-0.909301, 0, -0.550655),
                               (-1.023899, 0, -0.285854),
                               (-1.063053, 0, 9.80765e-009),
                               (-1.023899, 0, 0.285854),
                               (-0.909301, 0, 0.550655),
                               (-0.72786, 0, 0.774834),
                               (-0.570736, 0, 0.886448),
                               (-0.486547, 0, 0.930468),
                               (-0.761834, 0, 0.979696),
                               (-0.251045, 0, 1.015808),
                               (-0.498915, 0, 0.567734),
                               (-0.440202, 0, 0.841857),
                               (-0.516355, 0, 0.802034),
                               (-0.658578, 0, 0.701014),
                               (-0.822676, 0, 0.498232),
                               (-0.926399, 0, 0.258619),
                               (-0.961797, 0, 8.87346e-009),
                               (-0.926399, 0, -0.258619),
                               (-0.822676, 0, -0.498232),
                               (-0.658578, 0, -0.701014),
                               (-0.516355, 0, -0.802034),
                               (-0.440202, 0, -0.841857),
                               (-0.498915, 0, -0.567734),
                               (-0.251045, 0, -1.015808)],
                            k=[
                                0, 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
                            ])

        elif self.shape == CreateCtrl.four_arrow:
            ctrl = pm.curve(name=self.name,
                            d=1,
                            p=[
                                (1, 0, 1),
                                (3, 0, 1),
                                (3, 0, 2),
                                (5, 0, 0),
                                (3, 0, -2),
                                (3, 0, -1),
                                (1, 0, -1),
                                (1, 0, -3),
                                (2, 0, -3),
                                (0, 0, -5),
                                (-2, 0, -3),
                                (-1, 0, -3),
                                (-1, 0, -1),
                                (-3, 0, -1),
                                (-3, 0, -2),
                                (-5, 0, 0),
                                (-3, 0, 2),
                                (-3, 0, 1),
                                (-1, 0, 1),
                                (-1, 0, 3),
                                (-2, 0, 3),
                                (0, 0, 5),
                                (2, 0, 3),
                                (1, 0, 3),
                                (1, 0, 1),
                            ],
                            k=[
                                0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
                                14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24
                            ])

        elif self.shape == CreateCtrl.ring:
            ctrl = pm.curve(name=self.name,
                            d=1,
                            p=[(-0.707107, 0.0916408, 0.707107),
                               (0, 0.0916408, 1), (0, -0.0916408, 1),
                               (-0.707107, -0.0916408, 0.707107),
                               (-0.707107, 0.0916408, 0.707107),
                               (-1, 0.0916408, 0), (-1, -0.0916408, 0),
                               (-0.707107, -0.0916408, 0.707107),
                               (-1, -0.0916408, 0),
                               (-0.707107, -0.0916408, -0.707107),
                               (-0.707107, 0.0916408, -0.707107),
                               (-1, 0.0916408, 0),
                               (-0.707107, 0.0916408, -0.707107),
                               (0, 0.0916408, -1), (0, -0.0916408, -1),
                               (-0.707107, -0.0916408, -0.707107),
                               (-0.707107, 0.0916408, -0.707107),
                               (-0.707107, -0.0916408, -0.707107),
                               (0, -0.0916408, -1),
                               (0.707107, -0.0916408, -0.707107),
                               (0.707107, 0.0916408, -0.707107),
                               (0, 0.0916408, -1),
                               (0.707107, 0.0916408, -0.707107),
                               (1, 0.0916408, 0), (1, -0.0916408, 0),
                               (0.707107, -0.0916408, -0.707107),
                               (1, -0.0916408, 0),
                               (0.707107, -0.0916408, 0.707107),
                               (0.707107, 0.0916408, 0.707107),
                               (1, 0.0916408, 0),
                               (0.707107, 0.0916408, 0.707107),
                               (0, 0.0916408, 1), (0, -0.0916408, 1),
                               (0.707107, -0.0916408, 0.707107)],
                            k=[
                                0, 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
                            ])

        elif self.shape == CreateCtrl.sun:
            ctrl = pm.circle(name=self.name, s=16, nr=[0, 1, 0])[0]
            pm.select((ctrl + '.cv[1]'), (ctrl + '.cv[3]'), (ctrl + '.cv[5]'),
                      (ctrl + '.cv[7]'), (ctrl + '.cv[9]'), (ctrl + '.cv[11]'),
                      (ctrl + '.cv[13]'), (ctrl + '.cv[15]'),
                      (ctrl + '.cv[17]'), (ctrl + '.cv[19]'),
                      r=True)
            pm.scale(0.3, 0.3, 0.3, p=[0, 0, 0], r=True)
            pm.makeIdentity(ctrl, apply=True, t=1, r=1, s=1, n=0)
            pm.xform(ctrl, cp=True)

        print(ctrl)
        self.obj = ctrl
        return self.obj
Ejemplo n.º 13
0
def project_curves_onto_mesh2(mesh, source_mesh, direction):
    # duplicate sources_mesh
    dup_source_mesh = pm.duplicate(source_mesh)[0]
    dup_source_mesh.setParent(None)

    # create curve around mesh
    edge_curves = []
    for edge in mesh.getShape().e:
        edge_curves.append(
            pm.curve(
                # name=n,
                degree=1,
                ws=True,
                point=[
                    v.getPosition(space='world')
                    for v in edge.connectedVertices()
                ]))
    merged_curve = pm.attachCurve(edge_curves,
                                  method=1,
                                  keepMultipleKnots=False,
                                  ch=False)[0]
    merged_curve = pm.duplicate(merged_curve)
    pm.delete(edge_curves)

    # project curve onto dup_source_mesh
    projected_curves = projected_curves = pm.polyProjectCurve(
        dup_source_mesh, merged_curve, direction=direction)[0]
    # pm.delete( projected_curves.getChildren()[1:] )
    projected_curve = projected_curves.getChildren()[0]

    split_mesh = pm.polySplit(dup_source_mesh,
                              detachEdges=0,
                              projectedCurve=projected_curve)
    split_mesh = split_mesh[0]

    # delete faces not within mesh bounds
    # faces_to_delete = []
    pm.select(None)
    for face in split_mesh.f:
        face_center = (0.0, 0.0, 0.0)
        for v in face.connectedVertices():
            face_center += v.getPosition(space='world')
        face_center /= len(face.connectedVertices())

        if (point_in_rect_bb(face_center, mesh.getBoundingBox(space='world'))):
            # faces_to_delete.append( face )
            dot = face.getNormal(space='world').dot(
                mesh.f[0].getNormal(space='world'))
            if (dot > 0.0):
                pm.select(face, add=True)

    # for face in faces_to_delete :
    # 	dot = face.getNormal( space='world' ).dot( mesh.f[0].getNormal( space='world' ) )
    # 	if( dot > 0.0 )	 :
    # 		pm.select(face, add=True)

    pm.runtime.InvertSelection()
    pm.delete()

    # transfer UVs from mesh to dup_source_mesh
    pm.transferAttributes(mesh, split_mesh, transferUVs=2)

    # assign mesh material to dup_source_mesh

    # rename dup_source_mesh to mesh
    pm.delete(split_mesh, ch=True)
    n = mesh.name()
    p = mesh.getParent()
    pm.delete(mesh)
    split_mesh.rename(n)

    for attr in split_mesh.listAttr():
        if attr.isLocked(): attr.setLocked(False)

    # cleanup

    pm.delete(projected_curves)
    pm.delete(merged_curve)
    pm.delete(dup_source_mesh)

    # split_mesh.centerPivots( True )
    # t = split_mesh.getPivots( worldSpace=1 )[0]
    # split_mesh.setTranslation((-t[0], -t[1], -t[2]), space='world')
    # pm.makeIdentity( split_mesh, apply=True )
    # split_mesh.setParent( p )
    # split_mesh.setTranslation( ( 0,0,0 ) )
    # pm.makeIdentity( split_mesh, apply=True )

    # position bodge
    split_mesh.setTranslation((0, 0, 1), space='world')
    split_mesh.setParent(p)

    pm.polyTriangulate(split_mesh)

    if (not split_mesh.hasAttr(THU_MFT_SPRITE_ATTR)):
        split_mesh.addAttr(THU_MFT_SPRITE_ATTR, dt='string')
    split_mesh.setAttr(THU_MFT_SPRITE_ATTR,
                       split_mesh.name().replace('.png', ''))