Category Archives: Maya

linkedChainPreview

Autogenerate Chainlinks Along Curve

Well modeling chains can be tedious, so here we go, a small script that creates a chained link for a provided curve

'''
Linked Chain

Creates a Torus like object, links them together as linked Chain and positions the chain along a curve

Example:
1. Select a curve in Maya
2. Execute command:

Poly_Linked_Chain(radius = 1, sectionradius =0.1, extrude = 1, variation = 20, name="chain").createChainForSelectedCurve()

Created on May 7, 2013

@author: Neal Buerger www.nealbuerger.com
'''
import pymel.core as pm
import random

class Poly_Linked_Chain:
    
    def __init__(self, **kwargs):
        """
        Accepts following Keywords:
        radius: of the Torus created (Default 1)
        sectionradius: of the Torus (Default 0.1)
        extrude: length of the torus extrusion (Default 0)
        variation: along the rotation of the linked elements (Default 0)
        name: name of the chain (Default chain)
        """
        
        self.radius = kwargs.get("radius" ,1)
        self.sectionradius = kwargs.get("sectionradius" ,0.1)
        self.extrude = kwargs.get("extrude" ,0)
        self.variation = kwargs.get("variation" ,0)
        if self.variation < 0:
            self.variation = abs(self.variation)
        if  self.variation > 45:
            self.variation = 45
        
        self.name = kwargs.get("name" , "chain")
        self.name = self.name + str(len(pm.ls(regex= "%s\d*" % self.name))+1)
        
  
   
    def createLink(self):
        """
        creates a Torus and extrudes half of it
        To be used as alternative to a provided geometry
        
        """
        basechain = pm.polyTorus(radius = self.radius, sr = self.sectionradius, tw= 0, sx = 20, sy = 20, ax = (0,1,0), ch = 1)[0]    
        if self.extrude is not 0:
            faces = []
            for j in basechain.vtx:
                if j.getPosition()[0] > 0:
                    faces.append(j.connectedFaces())
            pm.polyExtrudeFacet(faces, translateX=self.extrude)
        return basechain
        
    
    def makeChain(self, obj, linklenght, chainlenght, preserveObj = False):
        """
        Uses provided geometry to create a straight chain
        
        obj: object to be used for the chain
        linklenght: lenght of the obj
        chainlenght: number of links that are created
        """
        if preserveObj:
            obj = pm.duplicate(obj, un=True)[0]
        pm.move(obj, 0,0,0)
        chain = [obj]
            
        rotValue = 0
        for i in range(1, chainlenght):
            obj = pm.duplicate(chain[0])[0]
            rotValue += 90 + random.randint(-self.variation, self.variation)
            if rotValue >= 360:
                rotValue -= 360
            pm.rotate(obj, [rotValue, 0, 0])        
            distance = linklenght * i
            pm.move(obj, distance,0,0)
            chain.append(obj)
        return chain
    
    def rigChain(self, chain):
        """
        takes chain and adds joints and a smooth bind to rig it
        
        chain: list of objects 
        """
        pm.select(deselect = True)
        jnts = []
        for obj in chain:
            pos = obj.translateX.get(), obj.translateY.get(), obj.translateZ.get()
            jnt =  pm.joint(p = pos)
            jnts.append(jnt)
            pm.rename(jnt, self.name + "_joint%d" % len(jnts))
        linked = pm.polyUnite(chain, ch = 0)[0]
        self.name = pm.rename(linked, self.name)
        pm.skinCluster(linked, jnts[0])
        return jnts
    
    def addClusterHandles(self, crv):
        """
        Adds Cluster Handles to Curve for every cv
        """
        for i in crv.cv:
            pm.parent(pm.cluster(i), crv)
    
    def createChainForCurve(self, crv, obj = None, linklenght = 1):
        """
        Uses the Curve and creates a chain based on the object that is passed into the function
        
        crv = curve to be used
        obj = object to be used
        linklength = lenght of the obj
        """
                
        if obj is None:
            obj = self.createLink()
            linklenght = (2*(self.radius - self.sectionradius*2)+self.extrude)
        chainlenght = int(pm.PyNode(crv).length()/linklenght)
        chain = self.makeChain(obj = obj, linklenght = linklenght, chainlenght = chainlenght)
        jnts = self.rigChain(chain)
        
        ik = pm.ikHandle( startJoint=jnts[0], endEffector=jnts[-1], solver='ikSplineSolver', createCurve=False, curve=crv)[0]
        pm.rename(ik, self.name + "_ikHandle")
            
        ctrlgrp = pm.group(jnts[0], ik, n = "%sctrl_grp" % self.name)
        ctrlgrp.v.set(False)
        pm.group(crv, self.name, ctrlgrp, n = "%s_grp" % self.name)
        
        self.addClusterHandles(crv)
        pm.select(deselect = True)
        
        return self.name
    
    
    def createChainForSelectedCurve(self):
        """
        Creates Chains for selected curves
        """
        return [self.createChainForCurve(i) for i in pm.ls(sl =True, tr=True) if pm.nodeType(i.getShape()) == "nurbsCurve"]
        
    
    def deleteRig(self, name):
        """
        Removes Rig from geometry
        
        name: name of geometry
        """
        parent = pm.PyNode(name).getParent()
        pm.delete(name, ch = True)
        pm.parent(name, w = True)
        pm.delete(parent)
        
        
maya-2014-banner-lockup-286x66

Maya 2014 and Bonus Tool Update

Maya 2014 Trial Download

The new version of Maya has been released and it has the NEX modelling tool-set integrated.

Download: http://www.autodesk.com/products/autodesk-maya/free-trial

Bonus Tools 2014

As usual a new updated version of the bonus tools is available.

More information: http://area.autodesk.com/bonus_tools

Download (from Autodesk Exchange): http://apps.exchange.autodesk.com/MAYA/Detail/Index?id=appstore.exchange.autodesk.com%3aautodeskmayabonustools2014%3aen

BevelHardEdges

Polygon Bevel Hard Edges Script

When working with polygons, it is helpful to bevel all hard edges to have a non-CG look.

This basic script bevels the hard edges on all selected objects.

import pymel.core as pm

def obj_is_poly(obj):
    #Evaluates if Object is Polygon
    return pm.nodeType(obj) is "mesh"

def bevelHardEdges(obj, offset = 0.5, segments = 1):
    if obj_is_poly(obj):
        pm.select(obj)
        pm.polySelectConstraint( m=3, t=0x8000, sm=1 ) # to get hard edges
        pm.polyBevel(offset = offset, segments = segments,autoFit = True, offsetAsFraction = True, fillNgons = True)

def bevelHardEdgesOnSelected():
    for item in pm.selected():
        bevelHardEdges(item.getShape())

bevelHardEdgesOnSelected()

Using the mia_photometric_light

 

Left Normal Spotlight, Right IES Light

Left Normal Spotlight, Right IES Light

 

The Illumination Engineering Society (or short IES) standard format file stores information about the distribution of light from a particular source.  The distribution of light is dependent on the various reflective materials used in the light bulb.

To enhance the realism in mental ray renders the mia_photometric_light node can process IES files.

How to obtain IES Files?

There are several sampling methods available to sample existing light bulbs. However most light bulb manufactures offer free downloads of IES Profiles.

Phillips Light bulbs:

http://www.usa.lighting.philips.com/connect/tools_literature/photometric_data_1_a.wpd

Or for full overkill a couple of IES files collections:

http://www.c4dcafe.com/ipb/files/file/804-whthawks-ies-light-collection/

http://mayazest.blogspot.de/2012/02/free-light-ies-files.html

Tools to Preview and Modifiy IES Files

IES Creator by Rip 3D: http://www.rip3d.net/web/en.html#/free/downloads

A great tutorial on the subject of creating, manipulating IES-files can be found here:

http://jamiecardoso-mentalray.blogspot.de/2012/12/creating-customised-ies-web-lights-for.html

Maya Setup

Install Maya 2013 SP2 several bugs were fixed concerning the mia_photometric_light node. Download it from here: http://usa.autodesk.com/adsk/servlet/ps/dl/item?siteID=123112&id=20537489&linkID=9242259

The mia_photometric_light attribute editor is slightly confusing. A more easier interface provides this template:

http://www.creativecrash.com/maya/downloads/scripts-plugins/interface-display/c/mia_photometric_light-ae-template

Download and copy the file to ..\Documents\maya\2013\scripts

How to use IES Files?

  1. Create a spotlight and position it. (Never scale the light, it creates odd errors)
  2. In the mental ray section create a new Light Shader > mia_photographic_light
  3. Define your IES Profile (If no profile is defined the node acts as a pointlight)
  4. The easiest way to set the Intensity mode is to use the Light Profile itself.
IESLightingImage

Applied IES-light

Note: Depending on the scale of your scene you have to  set “Maya Units to meter Scale” (when using cm as unit set it to 100)