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
Example #2
0
def create_locator(name):
    pm.select(None)
    global THU_MFT_LOCATOR_MATERIAL_NAME, THU_MFT_LOCATOR_ATTR
    try:
        material = pm.PyNode(THU_MFT_LOCATOR_MATERIAL_NAME)
    except:
        material = pm.createSurfaceShader(
            'lambert', name=THU_MFT_LOCATOR_MATERIAL_NAME)[0]
    material.color.set((1, 0, 0))
    material.transparency.set((0.8, 0.8, 0.8))

    loc_name = '%s_%s' % (name, THU_MFT_LOCATOR_ATTR)
    try:
        locator_trans = pm.PyNode(loc_name)
    except:
        locator_trans = pm.polyPlane(name=loc_name, sw=1, sh=1)[0]
        pm.sets(material.shadingGroups()[0],
                edit=True,
                forceElement=locator_trans)

    if (not locator_trans.hasAttr(THU_MFT_LOCATOR_ATTR)):
        locator_trans.addAttr(THU_MFT_LOCATOR_ATTR, dt='string')
    locator_trans.setAttr(THU_MFT_LOCATOR_ATTR, name)

    return locator_trans
def create_locator( name ) :
	pm.select( None )
	global THU_MFT_LOCATOR_MATERIAL_NAME, THU_MFT_LOCATOR_ATTR
	try : material = pm.PyNode( THU_MFT_LOCATOR_MATERIAL_NAME )
	except : material = pm.createSurfaceShader( 'lambert', name=THU_MFT_LOCATOR_MATERIAL_NAME )[0]
	material.color.set( ( 1, 0, 0 ) )
	material.transparency.set( ( 0.8, 0.8, 0.8 ) )

	loc_name = '%s_%s' % ( name, THU_MFT_LOCATOR_ATTR )
	try : 
		locator_trans = pm.PyNode( loc_name )
	except :
		locator_trans = pm.polyPlane(
			name=loc_name,
			sw=1, sh=1
		)[0]
		pm.sets( material.shadingGroups()[0], edit=True, forceElement=locator_trans )

	if( not locator_trans.hasAttr( THU_MFT_LOCATOR_ATTR ) ) :
		locator_trans.addAttr( THU_MFT_LOCATOR_ATTR, dt='string' )
	locator_trans.setAttr( THU_MFT_LOCATOR_ATTR, name )

	return locator_trans
Example #4
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