Keyframe setting comes inside two for loops.
Assign the vertical value to the translateY attribute.Set the balls X position to coincide with each of the faces of our ground plane.The idea here is for the ball to be completely white (1,1,1) on it’s uppermost position and completely blue (0,0,1) on its downermost part Calculate the color value which will be used ahead.Calculate their vertical position using a sin function.Create a new Polygon Sphere with radius 0.5 and name ballX where X stands for an index from 0 to 12.The last line connects the output color of the material we created to the surfaceShader of the Shading Group.ĪssignNewMaterial( ‘ground’ + str(i), (1, 1, 1), ‘lambert’, ‘ground.f’ )Īs we have 13 balls, we use a for from 0 to 12. Notice that it doesn’t take a tuple for argument, but three different numbers and a fourth argument defining that the last three are a vector of 3 double integers. Its first argument defines the type of material (lambert, blinn, anisotropic, etc), the second one is necessary for the system to understand it’s creating a real shading node, and the last one is the new material’s name.Īfter that, we set the color attribute.
The next line, creates a Material with the function shadingNode. The first line creates a Shading Group by calling the function sets, which returns nothing more than a set, in this case, an empty set for a while. As we’ll be creating lots of materials, we must define three functions in order to maintain the readability of the code.Ĭmds.sets( renderable=True, noSurfaceShader=True, empty=True, name=name + ‘SG’ )Ĭmds.shadingNode( type, asShader=True, name=name )Ĭmds.setAttr( name+”.color”, color, color, color, type=’double3′)Ĭmds.connectAttr(name+”.outColor”, name+”SG.surfaceShader”)
The link to the code without the z axis animation is: pythonMaya_xaxis.py and the link to the complete animation is: pythonMaya.py As WordPress has a lot of problems with syntax highlighting, you might think it’s better to follow the code through the original file. Note We will get to coding now and I’ll be explaining just the procedure to create and animate only the balls that stand over the x axis, you’ll notice that animating the other ones (over the z axis) will be a matter of parameter setting. Material (wood) -> Shading Group -> Object (table) The purpose of this post is not to discuss this, but it’s very important for you to understand that. It’s applied to a Shading Group and the objects are associated to the Shading Group. In Maya, one material (let’s say, wood) is not applied directly to an object (let’s say, a table). Looks pretty better than the other time, huh? Let’s get started.įirst of all, much of this new part is based on creating materials and changing their attributes, so before we turn into coding, it’s necessary to understand how Maya material system works.
If you have no idea of what am I talking about in here, please feel free to check the first part of this tutorial Python + Maya – Part 1.įor you to get a grasp of what we’ll be building this time, take a look at the video from the final output. After some new training, here comes the second part of the Python + Maya Linil Tutorial.