Пример #1
0
def basic(*args):
    """creates a basic 6 light light rig for interiors, probably unnecessary now..."""
    if (not cmds.ls('lights')):
        cmds.group(name='lights', em=True, w=True)
    cool = [.8, .85, 1]
    warm = [1, .88, .8]
    north = cmds.directionalLight(n='lFill_fromSouthOnNorth', rgb=cool, i=.2)
    cmds.setAttr(
        cmds.listRelatives(north, type='transform', p=True)[0] + '.ry', 180)
    south = cmds.directionalLight(n='lFill_fromNorthOnSouth', rgb=cool, i=.2)
    east = cmds.directionalLight(n='lFill_fromWestOnEast', rgb=cool, i=.2)
    cmds.setAttr(
        cmds.listRelatives(east, type='transform', p=True)[0] + '.ry', 90)
    west = cmds.directionalLight(n='lFill_fromEastOnWest', rgb=cool, i=.2)
    cmds.setAttr(
        cmds.listRelatives(west, type='transform', p=True)[0] + '.ry', -90)
    sky = cmds.directionalLight(n='lFill_fromFloorOnSky', rgb=warm, i=.1)
    cmds.setAttr(
        cmds.listRelatives(sky, type='transform', p=True)[0] + '.rx', 90)
    floor = cmds.directionalLight(n='lFill_fromSkyOnFloor', rgb=cool, i=.2)
    cmds.setAttr(
        cmds.listRelatives(floor, type='transform', p=True)[0] + '.rx', -90)
    amb = cmds.ambientLight(n='lAmb_onSet', i=.01)
    cmds.parent(cmds.ls(type='light'), 'lights')
    refresh()
Пример #2
0
def ambientLight(*args, **kwargs):
    """
    Maya Bug Fix:
      - name flag was ignored
    """
    if kwargs.get('query', kwargs.get('q', False)) or kwargs.get(
            'edit', kwargs.get('e', False)):
        return cmds.ambientLight(*args, **kwargs)

    else:
        name = kwargs.pop('name', kwargs.pop('n', False))
        if name:
            tmp = cmds.ambientLight(*args, **kwargs)
            tmp = cmds.rename(cmds.listRelatives(tmp, parent=1)[0], name)
            return _general.PyNode(cmds.listRelatives(tmp, shapes=1)[0])

    return _general.PyNode(cmds.ambientLight(*args, **kwargs))
Пример #3
0
def createAmblight():

    ambLight_Name   = 'amb_light'
    if cmds.objExists(ambLight_Name):
        cmds.delete(ambLight_Name)

    ambLight_Shape  = cmds.ambientLight(intensity=0.2, name=ambLight_Name)
    ambLight_Name   = cmds.listRelatives(ambLight_Shape, parent=True)

    return ambLight_Name
Пример #4
0
    def createLight(self, lightNodeType, lightName, *args, **kwargs):
        preCreationSelection = mc.ls(sl=True, long=True)
        if len(preCreationSelection) < 1:
            preCreationSelection = None
        else:
            preCreationSelection = preCreationSelection[0]

        if lightNodeType == 'spotLight':
            shapeNode = mc.spotLight(name=lightName)
        elif lightNodeType == 'directionalLight':
            shapeNode = mc.directionalLight(name=lightName)
        elif lightNodeType == 'pointLight':
            shapeNode = mc.pointLight(name=lightName)
        elif lightNodeType == 'ambientLight':
            shapeNode = mc.ambientLight(name=lightName)
        elif lightNodeType == 'volumeLight':
            initNode = mc.createNode('volumeLight')
            transform = mc.listRelatives(initNode, parent=True,
                                         fullPath=True)[0]
            result = mc.rename(transform, lightName)
            shapeNode = mc.listRelatives(result,
                                         shapes=True,
                                         noIntermediate=True,
                                         type='light')[0]
        elif lightNodeType == 'areaLight':
            initNode = mc.createNode('areaLight')
            transform = mc.listRelatives(initNode, parent=True,
                                         fullPath=True)[0]
            result = mc.rename(transform, lightName)
            shapeNode = mc.listRelatives(result,
                                         shapes=True,
                                         noIntermediate=True,
                                         type='light')[0]
        else:
            return None
        if shapeNode:
            transformNode = mc.listRelatives(shapeNode, parent=True)[0]
            self.alignLight(transformNode, preCreationSelection)
            tools.setDefaultAttrs(shapeNode)

            try:
                self.post_fn.postLightCreation(transformNode, shapeNode, *args,
                                               **kwargs)
            except:
                tools.logger.exception(
                    "Post light creation function not executed due to exceptions"
                )
            finally:
                return transformNode, shapeNode
        else:
            return None
Пример #5
0
def addLight(kind, *args):
	if(not cmds.ls('lights')):
		cmds.group(name='lights', em=True, w=True)
	if kind == 'spot':
		newLight = cmds.spotLight()
	elif kind == 'dir':
		newLight = cmds.directionalLight()
	elif kind == 'point':
		newLight = cmds.pointLight()
	elif kind == 'amb':
		newLight = cmds.ambientLight()
	elif kind == 'area':
		newLight = cmds.shadingNode ('areaLight', asLight=True)
	cmds.parent(newLight, 'lights')
	refresh()
Пример #6
0
def add_light(kind, *args):
    """adds a new light, organizes it, and refreshes the UI"""
    if (not cmds.ls('lights')):
        cmds.group(name='lights', em=True, w=True)
    if kind == 'spot':
        new_light = cmds.spotLight()
    elif kind == 'dir':
        new_light = cmds.directionalLight()
    elif kind == 'point':
        new_light = cmds.pointLight()
    elif kind == 'amb':
        new_light = cmds.ambientLight()
    elif kind == 'area':
        new_light = cmds.shadingNode('areaLight', asLight=True)
    cmds.parent(new_light, 'lights')
    refresh()
Пример #7
0
def add_light(kind, *args):
    """adds a new light, organizes it, and refreshes the UI"""
    if(not cmds.ls('lights')):
        cmds.group(name='lights', em=True, w=True)
    if kind == 'spot':
        new_light = cmds.spotLight()
    elif kind == 'dir':
        new_light = cmds.directionalLight()
    elif kind == 'point':
        new_light = cmds.pointLight()
    elif kind == 'amb':
        new_light = cmds.ambientLight()
    elif kind == 'area':
        new_light = cmds.shadingNode ('areaLight', asLight=True)
    cmds.parent(new_light, 'lights')
    refresh()
Пример #8
0
def makeLights(daytime, name_):
    '''
    Creates lights for the city.
    
    daytime: Boolean variable which is true if it is day and false if it is night.
    On exit: A directional light has been created and rotated randomly. If daytime
             is true a ambient light has also been created.    
    '''
    light = cmds.directionalLight(name = name_ + "directionalLight", rs = True)
    rotatex = random.randint(-90,0)
    rotatey = random.randint(0,360)
    cmds.xform(name_ + "directionalLight", rotation = (rotatex,rotatey,0), translation = (0,50,0),relative = True, ws = True)
    if daytime == False:
        cmds.setAttr(light + ".intensity", 0.05)
    else:
        light2 = cmds.ambientLight(name = name_ + "ambientLight",intensity = 0.5)
        cmds.xform(name_ + "ambientLight", translation = (0,50,0))
Пример #9
0
    def keepRenderGlobalInfo(self):
        
        self._imageFormat = cmds.getAttr( self._renderGlobalNode+'.imageFormat' )
        self._imagePrefix = cmds.getAttr( self._renderGlobalNode+'.imageFilePrefix' )
        self._baseImageAnimValue = cmds.getAttr( self._renderGlobalNode+'.animation' )
        if not self._imagePrefix: self._imagePrefix = ''
        

        ambientShape = cmds.ambientLight( i=0.0 )
        directShape  = cmds.directionalLight( i=1.5 )
        ambient = cmds.listRelatives( ambientShape, p=1 )[0]
        direct  = cmds.listRelatives( directShape,  p=1 )[0]
        
        self._lights = [ ambient, direct ]
        
        mtx = cmds.getAttr( self._cam + '.wm' )
        cmds.xform( direct, ws=1, matrix=mtx )
        cmds.refresh()
Пример #10
0
def basic(*args):
	if(not cmds.ls('lights')):
			cmds.group(name='lights', em=True, w=True)
	cool = [.8, .85, 1]
	warm = [1, .88, .8]
	north = cmds.directionalLight(n='lFill_fromSouthOnNorth', rgb=cool, i=.2)
	cmds.setAttr(cmds.listRelatives(north,type='transform',p=True)[0] + '.ry', 180)
	south = cmds.directionalLight(n='lFill_fromNorthOnSouth', rgb=cool, i=.2)
	east = cmds.directionalLight(n='lFill_fromWestOnEast', rgb=cool, i=.2)
	cmds.setAttr(cmds.listRelatives(east,type='transform',p=True)[0] + '.ry', 90)
	west = cmds.directionalLight(n='lFill_fromEastOnWest', rgb=cool, i=.2)
	cmds.setAttr(cmds.listRelatives(west,type='transform',p=True)[0] + '.ry', -90)
	sky = cmds.directionalLight(n='lFill_fromFloorOnSky', rgb=warm, i=.1)
	cmds.setAttr(cmds.listRelatives(sky,type='transform',p=True)[0] + '.rx', 90)
	floor = cmds.directionalLight(n='lFill_fromSkyOnFloor', rgb=cool, i=.2)
	cmds.setAttr(cmds.listRelatives(floor,type='transform',p=True)[0] + '.rx', -90)
	amb = cmds.ambientLight(n='lAmb_onSet', i=.01)
	cmds.parent(cmds.ls(type='light'), 'lights')
	refresh()
Пример #11
0
    def keepRenderGlobalInfo(self):

        self._imageFormat = cmds.getAttr(self._renderGlobalNode +
                                         '.imageFormat')
        self._imagePrefix = cmds.getAttr(self._renderGlobalNode +
                                         '.imageFilePrefix')
        self._baseImageAnimValue = cmds.getAttr(self._renderGlobalNode +
                                                '.animation')
        if not self._imagePrefix: self._imagePrefix = ''

        ambientShape = cmds.ambientLight(i=0.0)
        directShape = cmds.directionalLight(i=1.5)
        ambient = cmds.listRelatives(ambientShape, p=1)[0]
        direct = cmds.listRelatives(directShape, p=1)[0]

        self._lights = [ambient, direct]

        mtx = cmds.getAttr(self._cam + '.wm')
        cmds.xform(direct, ws=1, matrix=mtx)
        cmds.refresh()
Пример #12
0
def doit():
  global voxelSize, cubeSize, cubeDict, allLights, amb, useAmbient, useShadows, disableUndos, showCommands, useVoxCtrl, useCubeCtrl, frameRange, verboseOutput, xmin, xmax, ymin, ymax, zmin, zmax, xLocs, yLocs, zLocs

  cubeDict = {}
  shaderDict = {}
  SGDict = {}

  if useAmbient:
      # disable and store all existing lights
      allLights = cmds.sets("defaultLightSet", q=1)
      cmds.sets(clear="defaultLightSet")
      # make an ambient light
      amb = cmds.ambientLight(i=True, ambientShade=0)
  else: allLights = None

  # identify control objects
  sel = cmds.ls(sl=True)
  if len(sel) > 0:
    # filter for polymeshes
    ctrl = cmds.filterExpand(sel, fullPath=0, selectionMask=12)
    cmds.select(cl=1)
    sel = []
    if ctrl == None:
      print "No meshes found in selection, checking scene..."
      # check for object or group named "voxelGeo"
      if cmds.objExists("voxelGeo"):
        cmds.select("voxelGeo")
        sel = cmds.ls(sl=1)
  if len(sel) == 0: # select all dag objects
    cmds.select(ado=True)
    sel = cmds.ls(sl=True)
  if sel == None or sel == []:
    cmds.confirmDialog( title='Mesh selection', message= 'No meshes found in scene.', button=['OK'])
    return 0
  else: # filter for polymeshes
    ctrl = cmds.filterExpand(sel, fullPath=0, selectionMask=12)
    if ctrl == None:
      cmds.confirmDialog( title='Mesh selection', message= 'No meshes found in scene.', button=['OK'])
      return 0

  if disableUndos: cmds.undoInfo(state=False)
  if not showCommands: cmds.scriptEditorInfo(sr=True, sw=True, si=True)
  firstFrame = frameRange[0]
  lastFrame = frameRange[1]
  duration = abs(int(lastFrame-firstFrame))+1

  # deal with backwards frame ranges
  if lastFrame < firstFrame:
    lastFrame -= 1
    frameStep = -1
  else:
    lastFrame += 1
    frameStep = 1

  startTime= cmds.timerX()
  makeProgBar(duration*len(ctrl))
  cmds.progressBar(gMainProgressBar, edit=True, beginProgress=True)
  s = "s" if duration > 1 else ""
  print "Voxelizer animating over", duration, "frame%s..."%s
  print "Press ESC to cancel"

  resetList = []
  directions = [(-1.0, 0.0, 0,0), (0.0, -1.0, 0,0), (0.0, 0.0, -1.0)]
  cubegroup = cmds.group(em=True, n='cubes')
  cmds.select(cl=1)

  #for f in range(firstFrame,lastFrame,frameStep): # for each frame
  for f in range(int(firstFrame),int(lastFrame),int(frameStep)): # for each frame
    stepTime= cmds.timerX()
    if cmds.progressBar(gMainProgressBar, query=True, isCancelled=True ):
      return docancel()
    cmds.currentTime(f, edit=True, update=True)

    # get sizes from control objects, if available
    if useVoxCtrl:
      voxelSize = round(cmds.getAttr('voxelScaleCtrl.scaleX'), 3)
    if useCubeCtrl:
      cubeSize = round(cmds.getAttr('cubeScaleCtrl.scaleX'), 3)

    # hide visible cubes
    for x in resetList:
      cmds.setKeyframe(x, at="scale", v=0, t=f)
    resetList = []

    # for every target control object:
    for c in ctrl:
      if cmds.progressBar(gMainProgressBar, query=True, isCancelled=True ):
        return docancel()
      cmds.progressBar(gMainProgressBar, edit=True, step=True)
      # if ctrl object is invisible, skip to the next one
      if objIsVisible(c) == 0:
        continue

      # bake textures into verts
      cmds.select(c)
      cmds.polyGeoSampler(sampleByFace=True, computeShadows=useShadows, rs=useShadows)
      
      # set ray starting points
      setLocs(c)
      locArrays = [xLocs, yLocs, zLocs]

      # for each axis:
      for i in range(3):
        # for every gridpoint:
        for loc in locArrays[i]:
          hits = []
          # zap a ray through the object
          rayInt = rayIntersect(c, loc, directions[i])
          hits = rayInt[0]
          hfaces =  rayInt[1]
          for j, x in enumerate(hits):
            # snap hit locations to cubegrid
            x = (roundToFraction(x[0], voxelSize), roundToFraction(x[1], voxelSize), roundToFraction(x[2], voxelSize) )

            # if location isn't in cubeDict: make a new cube
            if x not in cubeDict:
              # add location and new cube to cubeDict
              cubeDict[x] = cmds.polyCube(sz=1, sy=1, sx=1, cuv=4, d=1, h=1, w=1, ch=1)[0]
              cube = cubeDict[x]
              if useShadows:
                # prevent cubes from casting shadows onto the ctrl objs
                cmds.setAttr(cube+".castsShadows", 0)
              cmds.parent(cube, cubegroup)
              # move cube to location
              cmds.xform(cube, t=x)

              # shader coloring method: uses one shader per cube
              shader = cmds.shadingNode("lambert", asShader=1)
              # create a shading group
              shaderSG = cmds.sets(renderable=True, noSurfaceShader=True, empty=True, name=shader+"SG")
              # connect the shader to the shading group
              cmds.connectAttr('%s.outColor'%shader, '%s.surfaceShader'%shaderSG, f=True)
              # add cube to the shaderSG
              shape = cmds.listRelatives(cube, shapes=1)[0]
              cmds.sets('%s'%shape, e=True, fe='%s'%shaderSG)

              shaderDict[cube] = shader
              SGDict[cube] = shaderSG

              # set scale key of 0 on the previous frame
              cmds.setKeyframe(cube, at="scale", v=0, t=(f-1))

            cube = cubeDict[x]
            cubeshape = cmds.listRelatives(cube, shapes=1)[0]

            # add cube to resetList
            resetList.append(cube)

            if len(hfaces) > 0:
              # check the alpha of the face
              alpha = cmds.polyColorPerVertex(c+'.f['+str(hfaces[j])+']', q=True, a=True, cdo=True)
              
              if alpha[0] > 0.5: # if more than half opaque
                # get the color of the face
                fcolor = cmds.polyColorPerVertex(c+'.f['+str(hfaces[j])+']', q=True, rgb=True, cdo=True, nun=True)
                cmds.setKeyframe(shaderDict[cube]+'.colorR', v=fcolor[0])
                cmds.setKeyframe(shaderDict[cube]+'.colorG', v=fcolor[1])
                cmds.setKeyframe(shaderDict[cube]+'.colorB', v=fcolor[2])

                # set a scale key
                cmds.setKeyframe(cube, at="scale", v=cubeSize, t=f, breakdown=0, hierarchy="none", controlPoints=0, shape=0)

                # if previous frame didn't have a scale key, set it to 0
                tempCurTime = cmds.currentTime(q=True)-1
                lastKey = cmds.keyframe(cube, at="scale", q=True, t=(tempCurTime,tempCurTime), valueChange=True)
                if lastKey == None:
                  cmds.setKeyframe(cube, at="scale", v=0, t=(f-1))

    if verboseOutput:
      stepTime = cmds.timerX(st=stepTime)
      totalTime = cmds.timerX(st=startTime)
      print "frame:", cmds.currentTime(q=True), "\tkeyed cubes:", len(resetList), "\ttotal cubes:", len(cubeDict)
      cps = "inf" if stepTime == 0 else round(len(resetList)/stepTime, 2)
      if useVoxCtrl or useCubeCtrl:
        print "\t\tvoxelSize:", voxelSize, "\tcubeSize: ", cubeSize
      print "\t\tstepTime:", round(stepTime, 2), "\ttotal time:", round(totalTime, 2), "\tcubes per second:", cps

  # restore scene state
  if useAmbient:
    if cmds.objExists(amb): cmds.delete(cmds.listRelatives(amb, parent=True)[0])
    cmds.sets(allLights, add="defaultLightSet")
  elif useShadows:
    # turn the cubes' shadows back on
    for x in cubeDict:
      cmds.setAttr(cubeDict[x]+".castsShadows", 1)
  if not showCommands: cmds.scriptEditorInfo(sr=srState, sw=swState, si=siState)
  if disableUndos: cmds.undoInfo(state=True)

  cmds.progressBar(gMainProgressBar, edit=True, endProgress=True)
  totalTime = cmds.timerX(st=startTime)
  print("Voxelizer finished: "+str(round(totalTime, 2))+ " seconds ("+str(round(totalTime/60, 2)) + " minutes)")

#promptSetup()

### End Voxelizer 1.0 ###
Пример #13
0
def createSun(*args) :
  cmds.ambientLight(name='sun_LGT', intensity=0)
  cmds.connectAttr('sun_LGT.translate', 'fabricVegetation.sunPos')

  print 'FVegetation: Created and connected sun location.'
Пример #14
0
## create light set for viewport2
import maya.cmds as mc
sel = mc.ls('groupLightA')
if not sel:
    mc.ambientLight(n='ambiantLightA', intensity=0.6)
    mc.spotLight(n='spotLightA', intensity=0.6, coneAngle=80)
    mc.setAttr('spotLightA.rotateX', -90)
    mc.setAttr('spotLightA.translateY', 300)
    mc.setAttr('spotLightA.scale', 200, 200, 200, type="double3")
    mc.group('ambiantLightA', 'spotLightA', n='groupLightA')
    allModelPanel = mc.getPanel(type='modelPanel')
    if allModelPanel:
        for modelPanelName in allModelPanel:
            mc.modelEditor(modelPanelName,
                           e=True,
                           displayLights="all",
                           shadows=True)
else:
    mc.delete(sel)
    allModelPanel = mc.getPanel(type='modelPanel')
    if allModelPanel:
        for modelPanelName in allModelPanel:
            mc.modelEditor(modelPanelName,
                           e=True,
                           displayLights="default",
                           shadows=False)

mc.ls("|root_*", type="transform")[0]

## integration matte
import maya.cmds as mc
#Creates an Ambient Light soft lighting setup for rendering/test rendering
#Requires that your materials are MIA_materialX.  This requirement might
#change in the future.  Also, requires that they all be selected.  This requirement
#will likely not change.
#by-Wesley Wilson
#on-6/23/14

import maya.cmds as cmds
#name of the lambert to be created. All other names are driven from this variable.
LambertName = 'ambientShader_lambert'

#select materials and assign to a list variable
selectedMaterials = cmds.ls(sl=True)

#creates the new lambert and assigns it a color of white
newLambert = cmds.shadingNode('lambert',
                              name='%s' % LambertName,
                              asShader=True)
cmds.setAttr('%s.color' % LambertName, 1, 1, 1, typ='double3')

#creates an ambient light and turns its ambient shade off
cmds.ambientLight(n='%s_ambLight' % LambertName, ambientShade=0)

#takes selected materials and turns on AO and then connects the lambert to that material
for selected in selectedMaterials:
    cmds.setAttr('%s.ao_on' % selected, 1)
    cmds.setAttr('%s.ao_samples' % selected, 24)
    cmds.connectAttr('%s.color' % LambertName,
                     '%s.ao_ambient' % selected,
                     f=True)
import maya.cmds as cmds
import maya.mel as mel
import math

# ****************************
# ---------- SETUP ----------
# ****************************

# ----- Create Light -----

# Create ambient light

light = cmds.ambientLight(intensity=1.0)
cmds.ambientLight(light, e=True, ss=True, intensity=0.2, n='lightAmb')
cmds.move(0, 8, 0)

# Create directional light
light = cmds.directionalLight(rotation=(45, 30, 15), n='lightDir')
cmds.directionalLight(light, e=True, ss=True, intensity=0.0)

# Query it
cmds.ambientLight(light, q=True, intensity=True)
cmds.directionalLight(light, q=True, intensity=True)

# ----- Create Transparent Box -----

# Create the groundPlane
cmds.polyCube(w=5,
              h=2,
              d=5,
              sx=1,
Пример #17
0
def createSun(*args):
    cmds.ambientLight(name='sun_LGT', intensity=0)
    cmds.connectAttr('sun_LGT.translate', 'fabricVegetation.sunPos')

    print 'FVegetation: Created and connected sun location.'