Wireframes & toon shaders

July 18th, 2010

Using Maya’s toon shaders, it is easy to create a retro, Tron style, sci-fi appearance.

Select a poly and from the Rendering menu set, select Toon > Assign fill shader > Solid colour, and set the Out colour to black from teh attribute panel.

With the poly select now select Toon > Assign outline > Add new toon outline.

Set Profile Lines > Profile color > Green

Goto Screenspace width control, enable it and set both min and max pixel width to be 1

Set Crease Lines > Crease colour to be green

Uncheck Crease lines > Hard creases only, and set Crease angle min\max to be 0 (zero)

If you like, you can also attacha brush to the wireframe lines; this allows you to add glow for even more sci-fi awesomeness!

Spherical spirals

March 2nd, 2010

Messing around with MEL again, I wanted to create a spiral path that wrapped around a sphere. Now I know how to create a 2d spiral (See previous post), and mapping this into 3 dimensions shouldn’t be too hard with handy polar coordinates.

The difference between 2d and 3d polar coordinates is an additional angle, phi, which defines the inclination of our point.

Unlike the 2d spiral where the radius increased by a fixed amount every 2pi radians, the radius on a spherical spiral remains constant; every single point will be mapped to a location on the surface of a sphere with a radius of r.

Previously, theta, went from 0 to xpi radians, where x was twice the number of revolutions our spiral went (a single revolution being 2pi).

This value of theta, together with the radius, r, defines completely a single point in 2d space, on an x\y plane, with theta being the angle around the origin.

Mapping this all onto a 3d sphere introduces the use of phi, which determines the declination of the point in 3d space, along an arc running from +z to -z (Note that for 3d polar coordinates z is considered vertical). The value of phi runs from +pi/2 (+z) to -pi/2), -z.

Spiral sphere created in MEL

Spiral sphere created in MEL

This maps out to the spiral sphere shown above.

The code for this is not much more complex than for the 2d spiral: sphereSpiral.mel

Try altering the values for revolutions, resolutions and radius to get different effects.

Spiral galaxy creation

February 15th, 2010

Following the maxim work smart, not hard, I thought about the spiral galaxy Iw as trying to make in Maya. As this will be used solely as a backdrop to a larger image, there was no need to have this in 3d, so I looked up some photoshop tutorials on galaxy creation.

Spiral galaxy created in Photoshop

Spiral galaxy created in Photoshop

This was done following the neat tutorial at http://blog.hexagonstar.com/galaxy-tutorial/

Good work! Now to just work on playing with the settings to get a more stylised, super high res, galaxy of my own to mess around with.

Script timing

January 24th, 2010

Currently playing around with writing greebling MEL scripts. Greebles are created through iterative extruding of polygon faces. I’ve found this can be ridiculously intensive for my computer (Q9550\4GB). Certainly turning off the undo queue helps, as does deleting the construction history for objects which are being greebled, but still I can easily create a script, which despite performing maybe 200 extrusion operations, takes 5 minutes to complete.

I figured the best way to produce optimised code was to begin timing different versions of the script. Took me a short while to track down, but there is a useful timerX function available within MEL, enabling you to time the execution of particular script areas.

Hopefully this should highlight any bottle necks in my greebling scripts!

Spirals, Galaxies and A-level maths

June 27th, 2009

I want an opening shot looking down on a spiral galaxy, not unlike our own. I figured a spiral was a good starting block for this. With a spiral EP curve, I could attach paint effects and guide particles in a typical, galactic, spirally fashion.

A friend has pointed out to me several times that when modelling in 3d, it’s how it looks that is important, not the degree of accuracy in the behind-the-scenes modelling. Knowing this, I should just draw a spiral freehand. However, I found it much more satisfying (and time consuming) working out to automatically create mathematically precise spirals using MEL.

Initially, I searched the web for a spiral script – surely someone else would have had need to create neat, precise spirals in Maya before? I found a few scripts, but none of them really worked how I wanted them to work. Further, I thought it would be interesting to understand the maths underlying spiral creation. Firing up Google, and with my handy copy of Complete Maya Programming to hand, I set to work.

Things I needed to know

An Archimedes spiral is a spiral whose consecutive turns are all a constant distance from one another.

Maya uses the Cartesian coordinate system; A given point is defined by 3 dimensions: x, y, z. Together, these three values represent a points unique position in 3d space. For a 2d shape, such as a flat spiral, we can safely ignore the z value, which would otherwise give our spiral depth.

Polar coordinates are an alternate coordinate system, where a point is represented in 2d space by the equation p = (r, Θ). R is the distance of the point from the origin, Θ represents the angle (in radians) around the axis perpendicular to the 2d plane. (3d polar coordinates use a 3rd value, Φ, which specifies a rotation around the x\z axis).

Why are we talking about polar geometry? Well, an Archimedes spiral can be described using the polar equation r=Θ. Actually, the exact equation is r(Θ) = a + bΘ, but for our purposes we will assume a = 0 and b=1, which helps simplify the equation.

a is a fixed value, and specifies the initial turn of the spiral. It is between 0 and 2π radians.
b represents the distance between consecutive turns
r represents the distance of the point from the origin.
Θ represents the angle around the origin, in radians.

How can we convert this equation into a Cartesian function?

We can ignore a and assume a value of 0, negating its presence in the equation. This gives us r(Θ) = bΘ

b is a fixed value, we can assume this to be 1, and modify as necessary. This reduce the equation further to r(Θ) = Θ (The polar equivalent of y = x!)

Θ is calculated in radians within the polar equation. To plot a spiral, we need to calculate a set number of points per revolution (4 minimum). The more points we calculate, the more accurate the spiral, although the more intensive for Maya to work with. Working in degrees gives us nice whole nunbers to work in – a full turn of spiral covers 360 degrees, at a coordinate every 10 degrees, that produces 36 points per turn. I decided on a point every 20 degrees (18 points per turn). It is easy then run through a loop, incrementing the counter by 20, and then converting this to radians for our formula.

So a point is calculated in radians with the formula p = (r, Θ) – as Θ increases, so does r (as r=Θ). As we calculate the varying degrees, by stepping through our loop, we can plot the points in a polar view, and will need to convert them to Cartesian coordinates in order to plot them within Maya.

Polar coordinates can be converted to Cartesian coordinates using p = (r cos(Θ), r sin(Θ), 0) (Note that the z value of 0 merely indicates that we are creating a 2d spiral.)

This gives us x = r cos(Θ), y = r sin(Θ) which can be easily plotted to a spiral using MEL.

Sample archimedes spiral, drawn in Maya

Sample archimedes spiral, drawn in Maya

Archimedes spiral MEL script for Maya

Download mySpiral.mel (version 1.0) (Right click to download)

This file is commented so you can easily experiment with different values – try them and see what you get. I plan on giving this script a front end though, so can try different values much more easily.

Adventures in Maya

June 27th, 2009

Welcome to my blog, Outside Context Problem!

This is a place for me to store stream of conciousness ramblings, notes, updates and thoughts as I work through a personal project of mine; creating a short animation based on the book Excession by Ian M Banks, using Autodesk’s Maya.