Light Maps with 3DSMax and VRay — III

Other posts of the serie

  1. Light Maps with 3DS­Max and VRay — III (Octo­ber 28, 2010)
  2. Light Maps with 3DS­Max and VRay  —  II (Octo­ber 28, 2010)
  3. Light Maps with 3DS­Max and VRay — I (Octo­ber 28, 2010)

In the first part of this tuto­ri­al, I focused on mod­el­ing, light­ing and VRay setup in 3DS Max. In this part we will cre­ate the map­ping coor­di­nates for the light maps. Down­load the sam­ple movie:

Lightmaps Demo (6914 down­loads)

and save it in “C:\lightMapsTutorial\”.
Open Direc­tor and load “lightmapsDemo.dir”. Import “geometry.w3d” in slot 1 of castlib “Inter­nal”. Import “lights.w3d” in slot 2 of castlib “Inter­nal”.
Import all pre­vi­ous­ly ren­dered images (light maps) from “C:\lightMapsTutorial\”. Check Stage(24 bits), uncheck Trim White Space and check Same Set­tings for Remain­ing Images.
Open the mes­sage win­dow and type in it :

generateLightMap( member(1), member(2) )

Wait until the “Scene Setup” script* com­pletes the pro­cess­ing — when fin­ished, it will out­put in the mes­sage win­dow

--"LightMapText Created"

The pro­cess­ing may take a few moments, depend­ing of the machine.
Place the “geom­e­try” cast­mem­ber in the score chan­nel 1, frame 2 . Select the sprite, set its width to 535 and set its height to 276.
Cre­ate a behav­ior script, name it “Scene Setup” and paste the fol­low­ing code in it:

show code
-- Scene Setup behaviour script
property _cnt
property _rad
property _init
property _scene, _camera

on beginSprite( me )
  _movie.puppetTempo( 60 )
  _cnt = 0
  _rad = 200
  _init = FALSE
  setupWorld()
  t = timeout().new( "setup", 10, #setup, me )
  t = VOID
end beginSprite

on exitFrame( me )
  b = _camera.overlay[1].blend
  if( b > 0 ) then
    b = b - 1
    _camera.overlay[1].blend = b
  end if
  me.moveCamera()
  _movie.go( _movie.frame )
end exitFrame

on setup( me, atimer )
  _scene = sprite( me.spritenum ).member

  _camera = _scene.camera[ 1 ]
  _camera.fieldOfView = 30
  _camera.colorBuffer.clearValue = rgb( "#AEBAC7" )
  _camera.fog.decayMode = #linear
  _camera.fog.color = rgb( "#AEBAC7" )
  _camera.fog.enabled = true
  _camera.fog.near = 300
  _camera.fog.far = 400

  repeat with s = 1 to _scene.texture.count
    tx = _scene.texture[ s ]
    tx.renderFormat = #rgba8880
  end repeat

  repeat with s = 1 to _scene.shader.count
    shd = _scene.shader[ s ]
    shd.useDiffuseWithTexture = true
    shd.emissive = shd.diffuse
    if( shd.name contains "sphere" ) then
      shd.specular = rgb( "FFFFFF" )
      shd.shininess = 80
    end if
  end repeat
  flshader = _scene.shader( "floor" )
  flshader.textureList[1] = _scene.texture( "DefaultTexture" )
  flshader.textureTransformList[1].scale = vector( 0.025, 0.025, 1 )
  _init = TRUE
  atimer.forget()
end setup

on moveCamera( me )
  if( not _init ) then return
  _cnt = _cnt + 1
  x = sin( me.degreesToRadians( _cnt )) * _rad
  y = cos( me.degreesToRadians( _cnt )) * _rad
  _camera.transform.position = vector( x, y, 100 )
  _camera.pointAt( _scene.model("box1"), vector(0,0,1) )
end moveCamera

on degreesToRadians ( me, degreeValue )
  return degreeValue * PI/180
end degreesToRadians


Attach “Scene Setup” behav­iour to the sprite on chan­nel 1, frame 2.
Run the movie — you should see the cam­era orbit­ing around the scene ( like in the demo below ).
Light Maps demo

Below are the com­plete files:

Lightmaps — com­plete (2023 down­loads)

*Note: The orig­i­nal ver­sion of this script can be found on http://www.dubane.com/cons/max2004/helpers/lightmapping.html

 
Comments

Very clear/helpful