View unanswered posts
View active topics
It is currently Sun Sep 24, 2017 3:31 am


Author Message
ymangolds
Post  Post subject: Maya script to convert materials into Furryball  |  Posted: Fri Oct 30, 2015 5:39 am
User avatar

Joined: Fri Aug 17, 2012 8:23 am
Posts: 89

Offline
Here's a script for Maya I wrote to convert existing phong, blinn, lambert, mia_material, mia_material_x and mia_material_x_passes into furryball ones. Requires PyMel (included in Maya 2014+). It's not 100% accurate, but works good enough for most materials.

Code:
import maya.cmds as mc
import pymel.core as pm
import maya.mel as mel
import random

def randomMatte():
   fbmats = pm.ls(type='furryballMaterial')
   used =[]
   for fbmat in fbmats:
      attempt = 0
      while True:
         attempt += 1
         red = random.uniform(0.1,1)
         green = random.uniform(0.1,1)
         blue = random.uniform(0.1,1)
         if isNotUsed([red,green,blue],used) or attempt >= 20:
            break
      used.append([red,green,blue])
      fbmat.matteColor.set([red,green,blue])

def isNotUsed(new,used):
   if not len(used):
      return True
   for use in used:
      if abs(new[0]-use[0]) <=0.1 and abs(new[1]-use[1]) <=0.1 and abs(new[2]-use[2]) <=0.1:
         return False
      elif round(new[0]-use[0],1) == round(new[1]-use[1],1) == round(new[2]-use[2],1):
         return False
   return True

def unlockFB():
   fbGlobalNodes = mc.ls(type='furryBallGlobal')
   for node in fbGlobalNodes:
      try:
         mc.lockNode(node,lock=0)
      except:
         pass
   return fbGlobalNodes

def convertFbMatToBlinn(referenced=False,deleteold=True):
   refs = pm.ls(referencedNodes=True, materials=True)
   fbmats = pm.ls(sl=True,type='furryballMaterial')
   if not len(fbmats):
      fbmats = pm.ls(type='furryballMaterial')
   for fbmat in fbmats:
      if fbmat.type() != 'furryballMaterial': continue
      #--------------------------------------- Skip the default lambert ---------------------------------------
      if str(fbmat) == 'lambert1': continue
      if not referenced and fbmat in refs: continue
      blinn = pm.shadingNode('blinn', asShader=1)
      #--------------------------------------- Diffuse ---------------------------------------
      if fbmat.color.connections():
         fbmat.color.connections(p=1)[0] >> blinn.color
      else:
         blinn.color.set(fbmat.color.get())
      blinn.diffuse.set(fbmat.diffuse.get())
      #--------------------------------------- Bump ---------------------------------------
      if fbmat.normalCamera.connections():
         fbmat.normalCamera.connections(p=1)[0] >> blinn.normalCamera
         fbmat.normalCamera.connections()[0].bumpDepth.set(0.5)
      #--------------------------------------- Transparency ---------------------------------------
      if fbmat.transparencyColor.connections():
         fbmat.transparencyColor.connections(p=1)[0] >> blinn.transparency
      else:
         blinn.transparency.set((fbmat.transparency.get(),fbmat.transparency.get(),fbmat.transparency.get()))
      blinn.refractiveIndex.set(fbmat.refractionIndex.get())
      blinn.surfaceThickness.set(fbmat.transparencyThickness.get())
      blinn.shadowAttenuation.set(fbmat.transparencyShadowAttenuation.get())
      #--------------------------------------- Alpha ---------------------------------------
      if fbmat.alphaMaskColor.connections():
         fbmat.alphaMaskColor.connections(p=1)[0] >> blinn.matteOpacity
      else:
         blinn.matteOpacity.set(fbmat.alphaMaskColor.get())
      #--------------------------------------- Emission ---------------------------------------
      if fbmat.emissionColor.connections():
         fbmat.emissionColor.connections(p=1)[0] >> blinn.incandescence
      else:
         blinn.incandescence.set(fbmat.emissionColor.get())
      #--------------------------------------- Specular ---------------------------------------
      if fbmat.specularColor.connections():
         fbmat.specularColor.connections(p=1)[0] >> blinn.specularColor
      else:
         blinn.specularColor.set(fbmat.specularColor.get())

      if fbmat.reflectionColor.connections():
         fbmat.reflectionColor.connections(p=1)[0] >> blinn.reflectedColor
      else:
         blinn.reflectedColor.set(fbmat.reflectionColor.get())
      blinn.reflectivity.set(fbmat.reflectivity.get())
      blinn.eccentricity.set(fbmat.specular.get())
      blinn.specularRollOff.set(fbmat.specularRoughness.get())
      #--------------------------------------- Replace Material ---------------------------------------
      for sg in fbmat.outColor.connections():
         if sg.type() == 'shadingEngine':
            blinn.outColor >> sg.surfaceShader
      if deleteold and fbmat not in refs:
         matName = str(fbmat)
         pm.delete(fbmat)
      else:
         matName = str(fbmat)+'_blinn'
      blinn.rename(matName)
      continue

def convertMatToFb(referenced=False,deleteold=True):
   refs = pm.ls(referencedNodes=True, materials=True)
   mats = pm.ls(sl=True, materials=True)
   if not len(mats):
      mats = pm.ls(materials=True)
   for mat in mats:
      #--------------------------------------- Skip the default lambert ---------------------------------------
      if str(mat) == 'lambert1': continue
      if not referenced and mat in refs: continue
      matType = mat.type()
      #===========================================================
      # Phong, Blinn, Lambert
      #===========================================================
      if matType in ('phong','blinn','lambert'):
         fbmat = pm.shadingNode('furryballMaterial', asShader=1)
         #--------------------------------------- Diffuse ---------------------------------------
         if mat.color.connections():
            mat.color.connections(p=1)[0] >> fbmat.color
         else:
            fbmat.color.set(mat.color.get())
         fbmat.diffuse.set(mat.diffuse.get())
         #--------------------------------------- Bump ---------------------------------------
         if mat.normalCamera.connections():
            mat.normalCamera.connections(p=1)[0] >> fbmat.normalCamera
            mat.normalCamera.connections()[0].bumpDepth.set(0.5)
         #--------------------------------------- Transparency ---------------------------------------
         if mat.transparency.connections():
            mat.transparency.connections(p=1)[0] >> fbmat.transparencyColor
            #lumi = pm.shadingNode('luminance', asUtility=1)
            #mat.transparency.connections()[0].outColor >> lumi.value
            #lumi.outValue >> fbmat.transparency
            fbmat.solidAlpha.set(0)
            #lumi.outValue >> fbmat.alphaMaskColor
            #lumi.rename(mat.transparency.connections()[0] + "_luminance")
         else:
            fbmat.transparencyColor.set(mat.transparency.get())
            fbmat.transparency.set(0.2126 * mat.transparencyR.get() + 0.7152 * mat.transparencyG.get() + 0.0722 * mat.transparencyB.get())
         fbmat.refractionIndex.set(mat.refractiveIndex.get())
         fbmat.transparencyThickness.set(mat.surfaceThickness.get())
         fbmat.transparencyShadowAttenuation.set(mat.shadowAttenuation.get())
         #--------------------------------------- Alpha ---------------------------------------
         if mat.matteOpacity.connections():
            mat.matteOpacity.connections(p=1)[0] >> fbmat.alphaMaskColor
            fbmat.alphaMaskThreshold.set(0.1)
         else:
            fbmat.alphaMaskColor.set(mat.matteOpacity.get())
         #--------------------------------------- Emission ---------------------------------------
         if mat.incandescence.connections():
            mat.incandescence.connections(p=1)[0] >> fbmat.emissionColor
            lumi = pm.shadingNode('luminance', asUtility=1)
            mat.incandescence.connections()[0].outColor >> lumi.value
            lumi.outValue >> fbmat.emission
            lumi.rename(mat.incandescence.connections()[0] + "_luminance")
         else:
            fbmat.emissionColor.set(mat.incandescence.get())
            fbmat.emission.set(0.2126 * mat.incandescenceR.get() + 0.7152 * mat.incandescenceG.get() + 0.0722 * mat.incandescenceB.get())
         #--------------------------------------- Specular ---------------------------------------
         if matType in ('phong','blinn'):
            if mat.specularColor.connections():
               mat.specularColor.connections(p=1)[0] >> fbmat.specularColor
            else:
               fbmat.specularColor.set(mat.specularColor.get())

            if matType == 'phong':
               fbmat.specular.set(0.2126 * mat.specularColorR.get() + 0.7152 * mat.specularColorG.get() + 0.0722 * mat.specularColorB.get())
               fbmat.specularRoughness.set(max((100-mat.cosinePower.get())/100,0))
            else:
               fbmat.specular.set(mat.eccentricity.get())
               fbmat.specularRoughness.set(mat.specularRollOff.get())
            #--------------------------------------- Reflection -------------------------
            if mat.reflectedColor.connections():
               mat.reflectedColor.connections(p=1)[0] >> fbmat.reflectionColor
            else:
               fbmat.reflectionColor.set(mat.reflectedColor.get())
            fbmat.reflectionRoughness.set(1-mat.reflectionSpecularity.get())
         #--------------------------------------- Replace Material -----------------------------------------------------
         for sg in mat.outColor.connections():
            if sg.type() == 'shadingEngine':
               fbmat.outColor >> sg.surfaceShader
         if deleteold and mat not in refs:
            matName = str(mat)
            pm.delete(mat)
         else:
            matName = str(fbmat)+'_fb'
         fbmat.rename(matName)
         continue
      #===========================================================
      # mia_material, mia_material_x, mia_material_x_passes
      #===========================================================
      elif matType in ('mia_material','mia_material_x','mia_material_x_passes'):
         fbmat = pm.shadingNode('furryballMaterial', asShader=1)
         #--------------------------------------- Diffuse ---------------------------------------
         if mat.diffuse.connections():
            mat.diffuse.connections(p=1)[0] >> fbmat.color
         else:
            fbmat.color.set(mat.diffuse.get())
         fbmat.diffuse.set(mat.diffuse_weight.get())
         fbmat.roughness.set(mat.diffuse_roughness.get())
         #--------------------------------------- Bump ---------------------------------------
         if mat.standard_bump.connections():
            mat.standard_bump.connections(p=1)[0] >> fbmat.normalCamera
            if mat.standard_bump.connections()[0].bumpDepth.get() == 1:
               mat.standard_bump.connections()[0].bumpDepth.set(0.5)
         #--------------------------------------- Specular ---------------------------------------
         if mat.refl_color.connections():
            mat.refl_color.connections(p=1)[0] >> fbmat.specularColor
         else:
            fbmat.specularColor.set(mat.refl_color.get())
         fbmat.specular.set(mat.reflectivity.get())
         fbmat.specularRoughness.set(1-mat.refl_gloss.get())
         if mat.anisotropy.get() != 1:
            fbmat.anisotropyEnable.set(1)
            if mat.anisotropy.get() < 1:
               fbmat.anisotropy.set(1-(mat.anisotropy.get()/2))
            else:
               fbmat.anisotropy.set(1-((1/mat.anisotropy.get())/2))
            fbmat.anisotropyRotation.set(mat.anisotropy_rotation.get())
         if mat.brdf_fresnel.get == 1:
            fbmat.fresnelEnabled.set(1)
            fbmat.fresnel.set(0.2)
            fbmat.transparencyFresnelIOR.set(1)
         #--------------------------------------- Transparency ---------------------------------------
         if mat.refr_color.connections():
            mat.refr_color.connections(p=1)[0] >> fbmat.transparencyColor
         else:
            fbmat.transparencyColor.set(mat.refr_color.get())
         if mat.transparency.connections():
            mat.transparency.connections(p=1)[0] >> fbmat.transparency
         else:
            fbmat.transparency.set(mat.transparency.get())
         fbmat.refractionIndex.set(mat.refr_ior.get())
         fbmat.transparencyRoughness.set(1-mat.refr_gloss.get())
         if mat.thin_walled.get():
            fbmat.transparencyThickness.set(1)
         if mat.do_refractive_caustics.get():
            fbmat.transparencyShadowAttenuation.set(0)
         if mat.propagate_alpha.get():
            fbmat.solidAlpha.set(0)
         if mat.cutout_opacity.connections():
            mat.cutout_opacity.connections(p=1)[0] >> fbmat.alphaMaskColor
         else:
            fbmat.alphaMaskColor.set(mat.cutout_opacity.get())
         #--------------------------------------- Emission ---------------------------------------
         if mat.additional_color.connections():
            mat.additional_color.connections(p=1)[0] >> fbmat.emissionColor
            lumi = pm.shadingNode('luminance', asUtility=1)
            mat.additional_color.connections(p=1)[0] >> lumi.value
            lumi.outValue >> fbmat.emission
            lumi.rename(mat.additional_color.connections()[0] + "_luminance")
         else:
            fbmat.emissionColor.set(mat.additional_color.get())
            fbmat.emission.set(0.2126 * mat.additional_colorR.get() + 0.7152 * mat.additional_colorG.get() + 0.0722 * mat.additional_colorB.get())
         #--------------------------------------- Replace Material ---------------------------------------
         for sg in mat.message.connections():
            if sg.type() == 'shadingEngine':
               fbmat.outColor >> sg.surfaceShader
         fbmat.rename(mat+'_fb')
         if deleteold and mat not in refs: pm.delete(mat)
         continue

def convertLightToFb(referenced=False,deleteold=True):
   refs = pm.ls(referencedNodes=True, lights=True)
   lgts = []
   mayaLightTypes = ['ambientLight','areaLight','directionalLight','pointLight','spotLight']
   fbLightTypes = ['furryballAmbientLight','furryballAreaLight','furryballDirectionalLight','furryballPointLight','furryballSpotLight']
   sel = pm.ls(sl=1)
   if len(sel):
      for obj in sel:
         if obj.type() == 'transform':
            obj = obj.getShape()
         if obj.type() in fbLightTypes:
            fbLgts.append(obj.getShape())
   if not len(lgts):
      lgts = pm.ls(type=mayaLightTypes)
   for lgt in lgts:
      if not referenced and lgt in refs: continue

      #--------------------------------------- Create and associate ---------------------------------------
      lgtType = lgt.type()
      fbLgt =pm.PyNode(furryBallUtilities.furryBallCreateLocator(fbLightTypes[mayaLightTypes.index(lgtType)], True))
      defLgts = pm.sets('defaultLightSet',q=1)
      if lgt.getParent() not in defLgts :
         pm.disconnectAttr(str(fbLgt.getParent())+'.instObjGroups[0]')
      attached = pm.lightlink (query=True, light=fbLgt.getParent())
      breakLight = pm.ls (attached, type=['mesh', 'subdiv', 'nurbsSurface'])
      for obj in breakLight:
         pm.lightlink (b=True, light=fbLgt.getParent(), object=obj)
      attached = pm.lightlink (query=True, light=lgt.getParent())
      breakLight = pm.ls (attached, type=['mesh', 'subdiv', 'nurbsSurface'])
      for obj in breakLight:
         pm.lightlink (m=True, light=fbLgt.getParent(), object=obj)
      #--------------------------------------- Position and heirarchy ---------------------------------------
      lgtLoc = pm.xform(lgt.getParent(),q=1,ws=1,translation=1)
      lgtRot = pm.xform(lgt.getParent(),q=1,ws=1,rotation=1)
      lgtSca = pm.xform(lgt.getParent(),q=1,ws=1,scale=1)
      pm.parent(fbLgt.getParent(),lgt.getParent().getParent())
      fbLgt.getParent().setTranslation(lgtLoc,ws=1)
      fbLgt.getParent().setRotation(lgtRot,ws=1)
      fbLgt.getParent().setScale(lgtSca,ws=1)
      #pm.move(lgtLoc[0],lgtLoc[1],lgtLoc[2],fbLgt.getParent(), a=1,ws=1)
      #pm.rotate(lgtRot[0],lgtRot[1],lgtRot[2],fbLgt.getParent(), a=1,ws=1)
      #pm.scale(lgtSca[0],lgtSca[1],lgtSca[2],fbLgt.getParent(), a=1)
      children = pm.listRelatives(lgt.getParent(),type='transform')
      for child in children:
         pm.parent(child,fbLgt.getParent())
      #--------------------------------------- Attributes ---------------------------------------
      transferAttr(lgt, fbLgt, {'color':'color','intensity':'intensity','shadowColor':'fbShadowColor'})
      if lgtType != 'ambientLight':
         transferAttr(lgt, fbLgt, {'emitDiffuse':'emitDiffuse','emitSpecular':'emitSpecular',})
      if lgtType in ['areaLight','pointLight','spotLight']:
         transferAttr(lgt, fbLgt, {'decayRate':'decayRate'})

      if lgtType == 'ambientLight':
         if lgt.useRayTraceShadows.get():
            fbLgt.fbCastShadows.set(1)
            transferAttr(lgt, fbLgt, {'shadowRays':'fbLightSamples','shadowRadius':'shadowRadius','rayDepthLimit':'fbShadowTransparencyDepth'})
         else:
            fbLgt.fbCastShadows.set(0)
      elif lgtType == 'areaLight':
         if lgt.useRayTraceShadows.get() or lgt.useDepthMapShadows.get():
            fbLgt.fbCastShadows.set(1)
            if lgt.useRayTraceShadows.get():
               transferAttr(lgt, fbLgt, {'shadowRays':'fbLightSamples','rayDepthLimit':'fbShadowTransparencyDepth'})
         else:
            fbLgt.fbCastShadows.set(0)
      elif lgtType == 'directionalLight':
         if lgt.useRayTraceShadows.get() or lgt.useDepthMapShadows.get():
            fbLgt.fbCastShadows.set(1)
            if lgt.useRayTraceShadows.get():
               transferAttr(lgt, fbLgt, {'shadowRays':'fbLightSamples','rayDepthLimit':'fbShadowTransparencyDepth','lightAngle':'lightAngle'})
         else:
            fbLgt.fbCastShadows.set(0)
      elif lgtType == 'pointLight':
         if lgt.useRayTraceShadows.get() or lgt.useDepthMapShadows.get():
            fbLgt.fbCastShadows.set(1)
            if lgt.useRayTraceShadows.get():
               transferAttr(lgt, fbLgt, {'shadowRays':'fbLightSamples','rayDepthLimit':'fbShadowTransparencyDepth','lightRadius':'lightRadius'})
         else:
            fbLgt.fbCastShadows.set(0)
      elif lgtType == 'spotLight':
         transferAttr(lgt, fbLgt, {'coneAngle':'coneAngle','penumbraAngle':'penumbraAngle','dropoff':'dropoff'})
         if lgt.useRayTraceShadows.get() or lgt.useDepthMapShadows.get():
            fbLgt.fbCastShadows.set(1)
            if lgt.useRayTraceShadows.get():
               transferAttr(lgt, fbLgt, {'shadowRays':'fbLightSamples','rayDepthLimit':'fbShadowTransparencyDepth','lightRadius':'lightRadius'})
         else:
            fbLgt.fbCastShadows.set(0)
      if deleteold and lgt not in refs:
         lgtName = str(lgt.getParent())
         pm.delete(lgt.getParent())
      else:
         lgtName = str(lgt.getParent())+'_fb'
      fbLgt.getParent().rename(lgtName)

def convertFbLightToStandard(referenced=False,deleteold=True,useRayTraceShadows=False):
   refs = pm.ls(referencedNodes=True, lights=True)
   fbLgts = []
   mayaLightTypes = ['ambientLight','areaLight','directionalLight','pointLight','spotLight']
   fbLightTypes = ['furryballAmbientLight','furryballAreaLight','furryballDirectionalLight','furryballPointLight','furryballSpotLight']
   sel = pm.ls(sl=1)
   if len(sel):
      for obj in sel:
         if obj.type() == 'transform':
            obj = obj.getShape()
         if obj.type() in fbLightTypes:
            fbLgts.append(obj.getShape())
   if not len(fbLgts):
      fbLgts = pm.ls(type=fbLightTypes)
   for fbLgt in fbLgts:
      if not referenced and fbLgt in refs: continue

      #--------------------------------------- Create and associate ---------------------------------------
      lgtType = fbLgt.type()
      lgt = pm.createNode(mayaLightTypes[fbLightTypes.index(lgtType)])
      defLgts = pm.sets('defaultLightSet',q=1)
      if fbLgt.getParent() in defLgts :
         pm.connectAttr(str(lgt.getParent())+'.instObjGroups', 'defaultLightSet.dagSetMembers',nextAvailable=1)
      attached = pm.lightlink (query=True, light=lgt.getParent())
      breakLight = pm.ls (attached, type=['mesh', 'subdiv', 'nurbsSurface'])
      for obj in breakLight:
         pm.lightlink (b=True, light=lgt.getParent(), object=obj)
      attached = pm.lightlink (query=True, light=fbLgt.getParent())
      breakLight = pm.ls (attached, type=['mesh', 'subdiv', 'nurbsSurface'])
      for obj in breakLight:
         pm.lightlink (m=True, light=lgt.getParent(), object=obj)
      #--------------------------------------- Position and heirarchy ---------------------------------------
      lgtLoc = pm.xform(fbLgt.getParent(),q=1,ws=1,translation=1)
      lgtRot = pm.xform(fbLgt.getParent(),q=1,ws=1,rotation=1)
      lgtSca = pm.xform(fbLgt.getParent(),q=1,ws=1,scale=1)
      pm.parent(lgt.getParent(),fbLgt.getParent().getParent())
      lgt.getParent().setTranslation(lgtLoc,ws=1)
      lgt.getParent().setRotation(lgtRot,ws=1)
      lgt.getParent().setScale(lgtSca,ws=1)
      #pm.move(lgtLoc[0],lgtLoc[1],lgtLoc[2],fbLgt.getParent(), a=1,ws=1)
      #pm.rotate(lgtRot[0],lgtRot[1],lgtRot[2],fbLgt.getParent(), a=1,ws=1)
      #pm.scale(lgtSca[0],lgtSca[1],lgtSca[2],fbLgt.getParent(), a=1)
      children = pm.listRelatives(fbLgt.getParent(),type='transform')
      for child in children:
         pm.parent(child,lgt.getParent())
      #--------------------------------------- Attributes ---------------------------------------
      transferAttr(fbLgt, lgt, {'color':'color','intensity':'intensity','fbShadowColor':'shadowColor'})
      if lgtType != 'furryballAmbientLight':
         transferAttr(fbLgt, lgt, {'emitDiffuse':'emitDiffuse','emitSpecular':'emitSpecular',})
      if lgtType in ['furryballAreaLight','furryballPointLight','furryballSpotLight']:
         transferAttr(fbLgt, lgt, {'decayRate':'decayRate'})

      if lgtType == 'furryballAmbientLight':
         if fbLgt.fbCastShadows.get() and useRayTraceShadows:
            transferAttr(fbLgt, lgt, {'fbLightSamples':'shadowRays','shadowRadius':'shadowRadius','fbShadowTransparencyDepth':'rayDepthLimit'})
         else:
            lgt.useRayTraceShadows.set(0)

      elif lgtType == 'furryballAreaLight':
         if fbLgt.fbCastShadows.get():
            if useRayTraceShadows:
               lgt.useRayTraceShadows.set(1)
               transferAttr(fbLgt, lgt, {'fbLightSamples':'shadowRays','fbShadowTransparencyDepth':'rayDepthLimit'})
            else:
               lgt.useDepthMapShadows.set(1)
         else:
            lgt.useRayTraceShadows.set(0)
      elif lgtType == 'furryballDirectionalLight':
         if fbLgt.fbCastShadows.get():
            if useRayTraceShadows:
               lgt.useRayTraceShadows.set(1)
               transferAttr(fbLgt, lgt, {'fbLightSamples':'shadowRays','fbShadowTransparencyDepth':'rayDepthLimit','lightAngle':'lightAngle'})
            else:
               lgt.useDepthMapShadows.set(1)
         else:
            lgt.useRayTraceShadows.set(0)
      elif lgtType == 'furryballPointLight':
         if fbLgt.fbCastShadows.get():
            if useRayTraceShadows:
               lgt.useRayTraceShadows.set(1)
               transferAttr(fbLgt, lgt, {'fbLightSamples':'shadowRays','fbShadowTransparencyDepth':'rayDepthLimit','lightRadius':'lightRadius'})
            else:
               lgt.useDepthMapShadows.set(1)
         else:
            lgt.useRayTraceShadows.set(0)
      elif lgtType == 'furryballSpotLight':
         transferAttr(fbLgt, lgt, {'coneAngle':'coneAngle','penumbraAngle':'penumbraAngle','dropoff':'dropoff'})
         if fbLgt.fbCastShadows.get():
            if useRayTraceShadows:
               lgt.useRayTraceShadows.set(1)
               transferAttr(fbLgt, lgt, {'fbLightSamples':'shadowRays','fbShadowTransparencyDepth':'rayDepthLimit','lightRadius':'lightRadius'})
            else:
               lgt.useDepthMapShadows.set(1)
         else:
            lgt.useRayTraceShadows.set(0)
      if deleteold and fbLgt not in refs:
         lgtName = str(fbLgt.getParent())
         pm.delete(fbLgt.getParent())
      else:
         lgtName = str(fbLgt.getParent())+'_maya'
      lgt.getParent().rename(lgtName)


def transferAttr(oldObj, newObj, mapping):
   for oldAttrName, newAttrName in mapping.iteritems():
      oldAttr = oldObj.attr(oldAttrName)
      newAttr = newObj.attr(newAttrName)
      if oldAttr.inputs():
         oldAttr.inputs(p=1)[0] >> newAttr
      else:
         newAttr.set(oldAttr.get())
      if oldAttr.outputs():
         for output in oldAttr.outputs(p=1):
            oldAttr // output
            newAttr >> output

To use, source/import the script, then either select the materials you want to convert (or select nothing if you want to convert all materials in the scene), and run:
Code:
convertMatToFb()

Which will not convert materials from referenced files and will remove the old shaders.
If you want to convert materials from referenced files run:
Code:
convertMatToFb(referenced=True)

If you want to keep the old materials (note they they will not be hooked up to any shadergroup), run:
Code:
convertMatToFb(deleteold=False)


If you figure out how to improve accuracy or extend it to be able to handle additional material types, please share.

:idea: Added randomMatte() procedure that will make every material's matte a different color in a matte pass.

:idea: Added convertLightToFb() procedure that will convert maya lights into Furryball ones including any complex attribute connections (like if there's 8 point lights with most of their attributes connected to the first one to make adjusting them all easy), light links, etc

:idea: Added convertFbLightToStandard() to convert Furryball lights into standard maya lights.

:idea: Extended randomMatte() so that it won't choose colors that are similar.


Last edited by ymangolds on Mon Jan 11, 2016 9:00 pm, edited 6 times in total.


Top
Jan_Tomanek
Post  Post subject: Re: Maya script to convert materials into Furryball  |  Posted: Fri Oct 30, 2015 1:27 pm
User avatar

Joined: Tue Oct 27, 2009 11:03 pm
Posts: 1555
Location: Prague - Czech republic

Offline
Great - thanks!

_________________
Thank you for contacting us.
If you have any further questions, please do not hesitate to contact us.

All the Best
Jan


Top
ymangolds
Post  Post subject: Re: Maya script to convert materials into Furryball  |  Posted: Fri Nov 20, 2015 5:54 am
User avatar

Joined: Fri Aug 17, 2012 8:23 am
Posts: 89

Offline
Updated the code above with various improvements. Also included a "Furryball to Blinn" conversion function, that we use when automatically creating scene assembly representations. That way, if an animator needs to be able to see textures (for example: a soldier interacting with a touch-GUI that controls a robot, the animator needs to see the controls on the GUI), they can switch the representation to the Blinn version. Also useful for recording playblasts using viewport 2.0 (since the purpose of playblasts is to evaluate animation quality only).


Top
Jan_Tomanek
Post  Post subject: Re: Maya script to convert materials into Furryball  |  Posted: Fri Nov 20, 2015 11:30 am
User avatar

Joined: Tue Oct 27, 2009 11:03 pm
Posts: 1555
Location: Prague - Czech republic

Offline
Thanks - good work!

_________________
Thank you for contacting us.
If you have any further questions, please do not hesitate to contact us.

All the Best
Jan


Top
Display posts from previous:  Sort by  
Print view

Who is online
Users browsing this forum: No registered users and 1 guest
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
Jump to:   
cron

Delete all board cookies | The team | All times are UTC + 1 hour [ DST ]

Powered by phpBB® Forum Software © phpBB Group
DAJ Glass 2 template created by Dustin Baccetti