def project_curves_onto_mesh(mesh, curves_grp, direction): # projected_curves = [] mesh = mesh old_meshes = [] for i, curve in enumerate(curves_grp.getChildren()): try: if (not type(curve.getShape()) is pm.NurbsCurve): continue except: continue while True: nv = len(mesh.vtx) mesh = delete_vertex(mesh) if (len(mesh.vtx) == nv): break projected_curves = pm.polyProjectCurve(mesh, curve, direction=direction)[0] pm.delete(projected_curves.getChildren()[1:]) projected_curve = projected_curves.getChildren()[0] split_mesh = pm.polySplit(mesh, detachEdges=0, projectedCurve=projected_curve) # print projected_curve split_mesh = split_mesh[0] pm.delete(split_mesh, ch=True) old_meshes.append(mesh) mesh = split_mesh if (projected_curves): pm.delete(projected_curves) # if( i == 10 ) : return for old_mesh in old_meshes: try: pm.delete(old_mesh) except: pm.warning('Could not delete %s' % (old_mesh)) pm.polyTriangulate(mesh) # pm.polyQuad( mesh ) # -ver 1 -trm 0 -p 50 -vct 0 -tct 0 -shp 0.5326 -keepBorder 1 -keepMapBorder 1 -keepColorBorder 1 -keepFaceGroupBorder 1 -keepHardEdge 1 -keepCreaseEdge 1 -keepBorderWeight 0.5 -keepMapBorderWeight 0.5 -keepColorBorderWeight 0.5 -keepFaceGroupBorderWeight 0.5 -keepHardEdgeWeight 0.5 -keepCreaseEdgeWeight 0.5 -useVirtualSymmetry 0 -symmetryTolerance 0.01 -sx 0 -sy 1 -sz 0 -sw 0 -preserveTopology 1 -keepQuadsWeight 1 -vertexMapName "" -replaceOriginal 1 -cachingReduce 1 -ch 1 # pm.polyReduce( mesh, ver=True, trm=False, p=50, replaceOriginal=True, kb=True, kbw=1.0, kmb=True, kmw=1.0, kfb=True, kfw=1.0, kqw=1.0 ) pm.polySoftEdge(mesh, a=180, ch=True) pm.delete(mesh, ch=True)
def project_curves_onto_mesh( mesh, curves_grp, direction ) : # projected_curves = [] mesh = mesh old_meshes = [] for i, curve in enumerate( curves_grp.getChildren( ) ) : try : if( not type(curve.getShape()) is pm.NurbsCurve ) : continue except : continue while True : nv = len(mesh.vtx) mesh = delete_vertex(mesh) if( len(mesh.vtx) == nv ) : break projected_curves = pm.polyProjectCurve( mesh, curve, direction=direction )[0] pm.delete( projected_curves.getChildren()[1:] ) projected_curve = projected_curves.getChildren()[0] split_mesh = pm.polySplit( mesh, detachEdges=0, projectedCurve=projected_curve ) # print projected_curve split_mesh = split_mesh[0] pm.delete( split_mesh, ch=True ) old_meshes.append( mesh ) mesh = split_mesh if( projected_curves ) : pm.delete( projected_curves ) # if( i == 10 ) : return for old_mesh in old_meshes : try : pm.delete( old_mesh ) except : pm.warning( 'Could not delete %s' % (old_mesh) ) pm.polyTriangulate( mesh ) # pm.polyQuad( mesh ) # -ver 1 -trm 0 -p 50 -vct 0 -tct 0 -shp 0.5326 -keepBorder 1 -keepMapBorder 1 -keepColorBorder 1 -keepFaceGroupBorder 1 -keepHardEdge 1 -keepCreaseEdge 1 -keepBorderWeight 0.5 -keepMapBorderWeight 0.5 -keepColorBorderWeight 0.5 -keepFaceGroupBorderWeight 0.5 -keepHardEdgeWeight 0.5 -keepCreaseEdgeWeight 0.5 -useVirtualSymmetry 0 -symmetryTolerance 0.01 -sx 0 -sy 1 -sz 0 -sw 0 -preserveTopology 1 -keepQuadsWeight 1 -vertexMapName "" -replaceOriginal 1 -cachingReduce 1 -ch 1 # pm.polyReduce( mesh, ver=True, trm=False, p=50, replaceOriginal=True, kb=True, kbw=1.0, kmb=True, kmw=1.0, kfb=True, kfw=1.0, kqw=1.0 ) pm.polySoftEdge( mesh, a=180, ch=True ) pm.delete( mesh, ch=True )
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', '' ) )
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', ''))