Making a flashlight with realistic light effects, and animated hotspot.
Tutorial By Atle Dreier.
First, make a cylinder, about 10 units radius, and 50 units
high.
On the end of that, create a cone, r1=10, r2=20, height=20, and
place it with the narrow end adjacent one end of the cylinder, to
create the body of the flashlight.
Next, apply an _edit mesh_ modifier to the cone, and select the
'front' of the flashlight, where the glass would be. Make sure
you have _sub-object/face_ selected! Delete the front face. Then
place a free spotlight inside the cone, facing out from the cone.
This simulates the lightbulb in our flashlight. Set the falloff
so that the light-cone just touches the edges of the cone, should
be about 80 degrees in our case.
Thats the model of the flashlight. Now let's do the cool part;
Enter the materials editor, and create a new map. You do this
byselecting a new material and clicking on the box next to
diffuse. Select noise as the map type.
Now you select _fractal_, set high threshold to about 0.8 and
size to about 40. Just leave the rest for now.
Now drag the diffusemap to the free spot's projectormap, and make
sure _projector_ is ticked.
Now group the flash, by selecting all three parts of it, and
click _group_ from the menu. Name it anything you like. Now the
flash is a single object that can be moved around.
If you create something for the flashlight to shine on, i.e. a
wall or something, you will instantly see why we put a noise
projectormap on the 'bulb'. At least I've never seen a flashlight
with completely uniform light!
Now we can do some other cool stuff with this flashlight.
Have you ever had one of those flashlights that when you twist
the front cone, with the bulb in it, you change the width of the
light-cone? Bet you have! We can easily simulate this in MAX,
using expressions and controllers. We simply tell MAX to alter
the hotspot, based on how much we twist the cone! Let me show you
how;
First, enter track-view, and open the cone/transform/rotation
track. Click on _assign controller_ from the toolbar. Select
_Euler XYZ_ as the controller, and click OK. This tells MAX that
we want the rotation of the cone as discrete XYZ rotations, in
stead of the TCB-rotation that is standard. This makes the
expression much easier to create.
Next we will create the expression for the fspot/object/hotspot;
Select _assign controller_ from the toolbar, and here we will use
_float expression_. Now right-click on the track itself. This
opens the expression-editor.
First we must create the variables we need, in this case the
twist of the cone. Type _twist_ in the dialog-box, and click
_create_. Make sure _scalar_ is selected as the type. Our new
scalar appears in the list. Select it from the list, and click
_assign to controller_. Select _cone/transform/Euler XYZ/X
rotation_ as the controller.
Next, type the expression in the window called... you guessed it:
Expression!
type: abs(twist/(pi/180))/2
Max uses this formula to calculate the value for hotspot.
(pi/180) is used to calculate from radians to degrees, and it is
halved to get a more useful range for the value, 0-90 in our
case. Close the expression editor, and the track view.
Now, select the spotlight, and click _show cone_, to make the
light-cona visible even when it is not selected. Now twist the
cone along it's X-axis, and watch the cone! Pretty neat, huh?