LIGHTS - SPOT

WOW! It's beautiful!

This lesson is the first of a serie about: lights in Director.

Director doesn't respect all the lights that you install in 3ds max like you are thinking that it does. Better to create a new system of lights by program, in Director.

There are many types of lights. We will talk, in this lesson about a "charming" type: the spot. Lights of this type cast their light from a particular point and within the cone defined by the light's forward direction and the spotAngle property.

To create a spot it's easy. In the method setupobjects of the setupscript put the lines:

  
-- Creating spot light
  myworld.newLight("spot1", #spot)
  sp1 = myworld.light("spot1")
  sp1.color = rgb(255, 255, 192)
  sp1.spotangle=80
  sp1.transform.position = vector(47, 10, 536)

The name of the spot is spot1. But, defining properties, we will need to use the "complete-reference-of-the-object": myworld.light("spot1"). So: we create a variable: sp1 to simplify.

We can't define the intensity of the light. But a funny resource is: we can put the cone-of-light in the direction of an object.

In our exercice, first: in 3ds max we create two "3D stars" with the names, defined inside 3ds max: star1 - the red and star2 - the yellow.

To put the cone-of-light in direction of star1 we use the lines of code:

 
 pstar1=myworld.model("star1").worldposition
 sp1.pointAt(pstar1)

TRICKS

It's not easy to discover the position (coordinates) where to "install" the spot. The trick is: use the avatar walking. In the timestep script we write the statement:

put myworld.model("avatar").worldposition

Opening the window: Message we , using the avatar walking to the point that we like to know, we can read the coordinates in the Message window.

Another trick that I use are the "auxiliary spheres".

Lights are not visible objects. I create a sphere only to help to define its position and effects. You can do it in 3 ds max - it's easyer - but I create it using Director comands and put it in the world - look in the figure: it's between the stars - the little one. And after this we can define the position of the spot using the sphere: The code to create an auxiliary sphere (in the setupscript) is:

  --create aux-sphere
  myworld.newModelResource("ls", #sphere, #front)
  as = myworld.modelResource("ls")
  as.radius = 10.0
  myworld.newModel("ls", as)
  asm = myworld.model("ls")
  --using the aux-sphere like a reference
  asm.transform.position = vector(47, 10, 536)
  sp1.transform.position = asm.transform.position

There are another auxiliary sphere (the big one) in the point (0,0,0) - a very important point. Look in the figure.


CHANGING THE FOCUS

Only for fun, in the demo we can change the focus of the spot to each one of the stars. It's a code created in the control method of the avatarobj script :

 
 if keypressed("2") then 
    pstar2=myworld.model("star2").worldposition
    myworld.light("spot1").pointAt(pstar2)
    
  end if

  if keypressed("1") then 
    pstar1=myworld.model("star1").worldposition
    myworld.light("spot1").pointAt(pstar1)
    
  end if

Play the demo. Now we have a new stair! Look! You can go there walking, to see the effects of the lights. Press the keys 1 or 2 of the PC keyboard to change the direction of the light.




PREVIOUS LESSON NEXT LESSON
T. CONTENTS HOMEPAGE