Ejemplo n.º 1
0
def create_curves_from_mesh(mesh):
    global THU_MFT_ANGLE_TOLERANCE

    try:
        edges = mesh.edges
    except:
        pm.error('Could not get edges from %s' % (mesh))

    edge_curve_group_name = mesh.name().split(':')[-1] + '_edgeCurve_GRP'
    try:
        edge_curve_group = pm.PyNode(edge_curve_group_name)
    except:
        edge_curve_group = pm.group(name=edge_curve_group_name,
                                    world=True,
                                    empty=True)

    converted_edges = []
    for c, edge in enumerate(edges):
        if (edge not in converted_edges):
            print 'Processing edge %s of %s' % (c, len(edges))
            merged_curve, edgeloop = __create_curve_from_edge(edge)
            pm.select(None)
            converted_edges.extend(edgeloop)
            # print merged_curve
            if (merged_curve):
                merged_curve.setParent(edge_curve_group)

    return edge_curve_group
def create_material( xml_path, suppress_warnings=True ) :
	pm.select( None )
	if( suppress_warnings ) :
		pm.scriptEditorInfo( edit=True, suppressWarings=True )

	tree = et.parse( xml_path )
	root_keys = tree.getroot().keys()
	if( not 'imagePath' in root_keys ) :
		pm.error( 'The XML file does not appear to be a Texture Packer XML' )
	texture_file = tree.getroot().get( 'imagePath' )
	texture_path = os.path.join( os.path.dirname( xml_path ), texture_file );
	
	material_name = __get_filename_noext( texture_file ) + '_MAT'
	try : material = pm.PyNode( material_name )
	except : material = pm.createSurfaceShader( 'lambert', name=material_name )[0]
	try : material_file = material.connections( type='file' )[0]
	except : material_file = pm.File( name=__get_filename_noext( texture_file ) + '_FILE' )
	try : material_file.outColor >> material.color
	except : pass
	try : material_file.outTransparency >> material.transparency
	except : pass
	material_file.fileTextureName.set( texture_path )

	if( suppress_warnings ) :
		pm.scriptEditorInfo( edit=True, suppressWarings=False )

	return material
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 rename(text, prefix = None, suffix = None, padding = 0, letters = False, capital = False):
    nodes = pm.ls(sl=True)
    newNames = []
    for i, _ in enumerate(nodes):
        tempName = ''
        if prefix: tempName += prefix + text + str(i)
        if suffix: tempName += suffix

        tempName = tempName.partition(prefix+text)[2]
        if suffix:
            tempName = tempName.rpartition(suffix)[0]
        if letters: # 페딩을 문자로 사용한다
            alpha   = getAlpha(int(i), capital)
            newName = prefix+text+alpha+suffix
            newNames.append(newName)
        else:
            num = str(i+1).zfill(padding+1)
            newName = prefix+text+num+suffix
            newNames.append(newName)
        
    error_msg = 'Fail to rename one of more nodes.\n'
    failedNodes = []
    for i, node in enumerate(nodes):
        if not pm.objExists(newNames[i]):
            node.rename(newNames[i])
        else:
            error_msg += '\t {} ==> {} \n'.format(node.name(), newNames[i]) 
            failedNodes.append(node)
            
    if failedNodes:
        pm.error(error_msg)
        print failedNodes    
Ejemplo n.º 5
0
def __get_object_list( selected_only ) :
	objects = []
	if( not selected_only ) :
		objects = pm.ls( assemblies=True, visible=True )
	else :
		objects = pm.ls( sl=True )
		for obj in objects :
			if(  obj.getShape() ) :
				pm.error( 'Please group your meshes when using selective export' )
	remove_list = [ 'top', 'front', 'side', 'perp' ]
	objects[:] = [ obj for obj in objects if obj.name() not in remove_list ]
	return objects
Ejemplo n.º 6
0
def exportAbc(options, exportList, operation):
    exportAbcCommand = 'AbcExport '
    startFrame = options['startFrame']
    endFrame = options['endFrame']

    for cache in exportList:
        print cache
        if cache['nodeType'] != 'bg':
            cacheFile = cache['abcPath']
            rootNode = cache['rootNode']
            exportAbcCommand += abcCommandSegment(startFrame, endFrame,
                                                  rootNode, cacheFile) + " "
    exportAbcCommand += ';'

    if operation == 'print':
        print exportAbcCommand
        return
    try:
        pm.mel.eval(exportAbcCommand)
    except:
        pm.error('AbcExport Error!!')
Ejemplo n.º 7
0
def importYeti(path):
    """입력 받은 경로에 shader를 import 한후 쉐이더를 적용 한다.
    
    :param path: 파일 경로
    :type path: str
    
    """
    yetiInfo = getYetiInfo()
    if yetiInfo:
        for yetiNode, shader in yetiInfo.items():
            if pm.objExists(yetiNode):
                pm.delete(yetiNode)
            if pm.objExists(shader):
                pm.delete(shader)

    if pm.objExists('yetiInfoNode'):
        yetiInfoNode = pm.PyNode('yetiInfoNode')
        yetiInfoNode.unlock()
        pm.delete(yetiInfoNode)

    pm.importFile(path)
    if not pm.objExists('yetiInfoNode'):
        pm.error(u'"yetiInfoNode"가 존재 하지 않습니다.')

    yetiInfoNode = pm.PyNode('yetiInfoNode')
    yetiInfo = json.loads(yetiInfoNode.yetiInfo.get())

    for yetiNodeName, shaderName in yetiInfo.items():
        yetiNode = pm.createNode('pgYetiMaya', n=yetiNodeName + 'Shape')
        yetiParent = yetiNode.getParent()
        yetiParent.rename(yetiNodeName)
        yetiNode.renderDensity.set(1)
        yetiNode.aiOpaque.set(0)

        pm.select(yetiParent)
        surfaceShader = pm.PyNode(shaderName)
        pm.hyperShade(assign=surfaceShader)
def create_curves_from_mesh( mesh ) :	
	global THU_MFT_ANGLE_TOLERANCE

	try :
		edges = mesh.edges
	except :
		pm.error( 'Could not get edges from %s' % ( mesh ) )

	edge_curve_group_name = mesh.name().split( ':' )[-1] + '_edgeCurve_GRP'
	try : edge_curve_group = pm.PyNode( edge_curve_group_name )
	except : edge_curve_group = pm.group( name=edge_curve_group_name, world=True, empty=True )

	converted_edges = []
	for c, edge in enumerate( edges ) :
		if( edge not in converted_edges ) :
			print 'Processing edge %s of %s' % ( c, len(edges) )		
			merged_curve, edgeloop = __create_curve_from_edge( edge )
			pm.select( None )
			converted_edges.extend( edgeloop )
			# print merged_curve
			if( merged_curve ) :
				merged_curve.setParent( edge_curve_group )

	return edge_curve_group
Ejemplo n.º 9
0
def create_material(xml_path, suppress_warnings=True):
    pm.select(None)
    if (suppress_warnings):
        pm.scriptEditorInfo(edit=True, suppressWarings=True)

    tree = et.parse(xml_path)
    root_keys = tree.getroot().keys()
    if (not 'imagePath' in root_keys):
        pm.error('The XML file does not appear to be a Texture Packer XML')
    texture_file = tree.getroot().get('imagePath')
    texture_path = os.path.join(os.path.dirname(xml_path), texture_file)

    material_name = __get_filename_noext(texture_file) + '_MAT'
    try:
        material = pm.PyNode(material_name)
    except:
        material = pm.createSurfaceShader('lambert', name=material_name)[0]
    try:
        material_file = material.connections(type='file')[0]
    except:
        material_file = pm.File(name=__get_filename_noext(texture_file) +
                                '_FILE')
    try:
        material_file.outColor >> material.color
    except:
        pass
    try:
        material_file.outTransparency >> material.transparency
    except:
        pass
    material_file.fileTextureName.set(texture_path)

    if (suppress_warnings):
        pm.scriptEditorInfo(edit=True, suppressWarings=False)

    return material
def create_mesh( xml_path, name, locator=None ) :
	pm.select( None )
	tree = et.parse( xml_path )
	root_keys = tree.getroot().keys()
	if( not 'imagePath' in root_keys ) :
		pm.error( 'The XML file does not appear to be a Texture Packer XML' )
	texture_size = ( tree.getroot().get( 'width' ), tree.getroot().get( 'height' ) )

	sprite = tree.find( ".//*[@n='%s']" % ( name ) )
	material = create_material( xml_path )

	if( not len( material.shadingGroups() ) ) :
		pm.error( 'Material %s is not connected to a Shading Group. Aborting.' )

	plane_name = __get_filename_noext( name ) + '_G'
	if( locator ) :
		plane_name = '%s_%s' % ( locator.name(), plane_name )
	
	try : 
		plane_trans = pm.PyNode( plane_name )		
	except :
		# v = pm.datatypes.Vector( float(sprite.get('w')) / 100.0, float(sprite.get('h')) / 100.0 )
		# v = v.normal()
		w_scale = float(sprite.get('w')) / 100.0
		h_scale = float(sprite.get('h')) / 100.0
		w_h = w_scale / h_scale
		h_w = h_scale / w_scale
		if( w_h > h_w ) :
			wp = 1.0 / w_h
			# print wp
			w_scale = 1.0
			h_scale = 1.0 / w_h
			# print 'w_h', w_scale, h_scale
		else :
			hp = 1.0 / h_w
			# print hp
			h_scale = 1.0
			w_scale = 1.0 / h_w
			# print w_h, h_w
			# print 'h_w', w_scale, h_scale
		plane_trans = pm.polyPlane(
			name=plane_name,
			sw=1, sh=1,			
			w=w_scale, h=h_scale
		)[0]
	plane_shape = plane_trans.getShape()

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

	pm.sets( material.shadingGroups()[0], edit=True, forceElement=plane_trans )

	sx = ( float( sprite.get( 'x' ) ) / float( texture_size[0] ) )
	sy = 1 - ( float( sprite.get( 'y' ) ) / float( texture_size[1] ) )
	sw = ( float( sprite.get( 'w' ) ) / float( texture_size[0] ) )
	sh = ( float( sprite.get( 'h' ) ) / float( texture_size[1] ) )

	uv_positions = (
		( sx, sy - sh ),		
		( sx + sw, sy - sh ),
		( sx, sy ),
		( sx + sw, sy )
	)

	for uv, uv_position in zip( plane_shape.uvs, uv_positions ) :
		pm.polyEditUV( uv, r=False, u=uv_position[0], v=uv_position[1] )

	if( locator ) :
		# print locator
		plane_trans.setParent( locator )
		plane_trans.setTranslation( ( 0, 0, 0 ) )
		plane_trans.setRotation( ( 0, 0, 0 ) )
		plane_trans.setScale( ( 1, 1, 1 ) )		
		locator_bounds = locator.getBoundingBox()
		plane_bounds = plane_trans.getBoundingBox()
		if( plane_bounds.width() > plane_bounds.height() ) :
			pass
		else :
			s = locator_bounds.height() / plane_bounds.height()
			# plane_trans.setScale( (s, s, s) )
			
		

	pm.select( plane_trans )
	return plane_trans
Ejemplo n.º 11
0
def err( _message ) :	
	caller = _get_caller()
	_message = caller + ' : ' + _message
	if( settings.should_error ) : pm.error( _message )
	else : pm.warning( _message )
Ejemplo n.º 12
0
def export_scene( 
	res_path,
	scene_file_path,
	model_rel_path,
	texture_rel_path='',
	material_name='',
	selected_only=False,
	insert=False,
	insert_node_name=None
	) :
	
	print 'Exporting scene'

	res_path = os.path.abspath( res_path )
	scene_file_path = os.path.normpath( scene_file_path )
	model_rel_path = os.path.normpath( model_rel_path )
	texture_rel_path = os.path.normpath( texture_rel_path )

	sel = pm.ls( sl=True )

	objects = __get_object_list( selected_only )
	root = et.Element( 'Scene' )
	for obj in objects :
		clean_obj = __create_clean_object( obj )
		__recursive_create_scene_xml( 
			clean_obj,
			root,
			res_path,
			scene_file_path,
			model_rel_path,
			texture_rel_path,
			material_name			
		)
		pm.delete( clean_obj )

	tree = et.ElementTree( root )

	if( insert ) :
		try : old_tree = et.parse( scene_file_path )
		except : pm.error( 'Scene file is not an XML document' )
		if( old_tree ) : 
			element_to_insert_into = old_tree.find( ".//*[@name='%s']" % ( insert_node_name ) )
			if( not element_to_insert_into ) :
				pm.error( 'Could not find SceneObject named %s to insert into' % ( insert_node_name ) )
			for e in element_to_insert_into.findall( 'SceneObject' ) :
				element_to_insert_into.remove( e )
			index = len( list( element_to_insert_into ) )
			for e in list( tree.getroot() ) :
				element_to_insert_into.insert( index, e )
			tree = old_tree
	
		version_comment = et.Comment( '%s : Exported using ff_utils.export version %s' % ( time.strftime("%d/%m/%Y %H:%M:%S"), FFU_E_VERSION ) )
		tree.getroot().insert( 0, version_comment )

	xml_string = md.parseString( et.tostring( tree.getroot() ) ).toprettyxml( indent='\t' )
	xml_string = os.linesep.join( [ line for line in xml_string.split( os.linesep ) if line.strip() ] )

	with open( scene_file_path, 'w' ) as f :				
		f.write( xml_string )

	pm.select( sel )

	print 'Exporting scene finished'
	return True
Ejemplo n.º 13
0
def ui_do_export(  ) :
	global FFU_E_SETTINGS
	
	if( not FFU_E_SETTINGS.get('res_path').value ) :
		pm.error( 'Please enter a res path' )
	if( not FFU_E_SETTINGS.get('model_path').value ) :
		pm.error( 'Please enter a model path' )

	if( FFU_E_SETTINGS.get('export_models_bool').value ) :		
		print 'Exporting models from UI'
		export_models(
			FFU_E_SETTINGS.get('res_path').value,
			__clean_relative_path( FFU_E_SETTINGS.get('res_path').value, FFU_E_SETTINGS.get('model_path').value ),
			FFU_E_SETTINGS.get('selected_only_bool').value
		)

	if( FFU_E_SETTINGS.get('export_scene_bool').value ) :
		if( not FFU_E_SETTINGS.get('scene_file_path').value ) :
			pm.error( 'Please enter a scene file path' )
		if( not FFU_E_SETTINGS.get('material_string').value ) :
			pm.error( 'Please enter a default material name' )
		if( not FFU_E_SETTINGS.get('texture_path').value ) :
			pm.error( 'Please enter a default material name' )
		if( FFU_E_SETTINGS.get('insert_scene_bool').value ) :
			if( not FFU_E_SETTINGS.get('insert_nodename_string').value ) :
				pm.error( 'Please enter a SceneObject name to insert into when using insertion mode' )
		
		print 'Exporting scene from UI'
		export_scene(
			FFU_E_SETTINGS.get('res_path').value,
			FFU_E_SETTINGS.get('scene_file_path').value,
			__clean_relative_path( FFU_E_SETTINGS.get('res_path').value, FFU_E_SETTINGS.get('model_path').value ),
			__clean_relative_path( FFU_E_SETTINGS.get('res_path').value, FFU_E_SETTINGS.get('texture_path').value ),
			FFU_E_SETTINGS.get('material_string').value,
			FFU_E_SETTINGS.get('selected_only_bool').value,
			FFU_E_SETTINGS.get('insert_scene_bool').value,
			FFU_E_SETTINGS.get('insert_nodename_string').value
		)
Ejemplo n.º 14
0
def create_mesh(xml_path, name, locator=None):
    pm.select(None)
    tree = et.parse(xml_path)
    root_keys = tree.getroot().keys()
    if (not 'imagePath' in root_keys):
        pm.error('The XML file does not appear to be a Texture Packer XML')
    texture_size = (tree.getroot().get('width'), tree.getroot().get('height'))

    sprite = tree.find(".//*[@n='%s']" % (name))
    material = create_material(xml_path)

    if (not len(material.shadingGroups())):
        pm.error('Material %s is not connected to a Shading Group. Aborting.')

    plane_name = __get_filename_noext(name) + '_G'
    if (locator):
        plane_name = '%s_%s' % (locator.name(), plane_name)

    try:
        plane_trans = pm.PyNode(plane_name)
    except:
        # v = pm.datatypes.Vector( float(sprite.get('w')) / 100.0, float(sprite.get('h')) / 100.0 )
        # v = v.normal()
        w_scale = float(sprite.get('w')) / 100.0
        h_scale = float(sprite.get('h')) / 100.0
        w_h = w_scale / h_scale
        h_w = h_scale / w_scale
        if (w_h > h_w):
            wp = 1.0 / w_h
            # print wp
            w_scale = 1.0
            h_scale = 1.0 / w_h
            # print 'w_h', w_scale, h_scale
        else:
            hp = 1.0 / h_w
            # print hp
            h_scale = 1.0
            w_scale = 1.0 / h_w
            # print w_h, h_w
            # print 'h_w', w_scale, h_scale
        plane_trans = pm.polyPlane(name=plane_name,
                                   sw=1,
                                   sh=1,
                                   w=w_scale,
                                   h=h_scale)[0]
    plane_shape = plane_trans.getShape()

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

    pm.sets(material.shadingGroups()[0], edit=True, forceElement=plane_trans)

    sx = (float(sprite.get('x')) / float(texture_size[0]))
    sy = 1 - (float(sprite.get('y')) / float(texture_size[1]))
    sw = (float(sprite.get('w')) / float(texture_size[0]))
    sh = (float(sprite.get('h')) / float(texture_size[1]))

    uv_positions = ((sx, sy - sh), (sx + sw, sy - sh), (sx, sy), (sx + sw, sy))

    for uv, uv_position in zip(plane_shape.uvs, uv_positions):
        pm.polyEditUV(uv, r=False, u=uv_position[0], v=uv_position[1])

    if (locator):
        # print locator
        plane_trans.setParent(locator)
        plane_trans.setTranslation((0, 0, 0))
        plane_trans.setRotation((0, 0, 0))
        plane_trans.setScale((1, 1, 1))
        locator_bounds = locator.getBoundingBox()
        plane_bounds = plane_trans.getBoundingBox()
        if (plane_bounds.width() > plane_bounds.height()):
            pass
        else:
            s = locator_bounds.height() / plane_bounds.height()
            # plane_trans.setScale( (s, s, s) )

    pm.select(plane_trans)
    return plane_trans