home *** CD-ROM | disk | FTP | other *** search
/ Maximum 3D 3 / m3d-p3.iso / 3DS_MAX / 3DSMAX.2_0 / SCRIPTS / BACKDROP.MS < prev    next >
Text File  |  1997-10-19  |  5KB  |  154 lines

  1. -- This creates a "Load Backdrops" utility in the utility panel
  2. -- This script is dependent on files "mapdef.dat" and "place.dat"
  3. -- which are provided in the same directory as this.
  4.  
  5. -- This is how you can run this script
  6. -- 1) Execute this script and open the 'Load Backdrops' utility
  7. -- 2) Click Maps File button and point to mapdef.dat
  8. -- 3) Click placement file and point to place.dat
  9. -- 4) Set the various options and click 'Load backdrops'
  10. -- 5) Some objects are created in the scene
  11. -- 6) Now render to see the backdrops
  12.  
  13. --Note: If you moved your treeart directory from scripts directory 
  14. --        then open mapdef.dat and edit the paths
  15.  
  16. -- backdrop loader utility
  17.  
  18. fn load_backdrops map_data placement_data offset_pos offset_scale =
  19. (
  20.     -- first build the proforma backdrop cross mesh & add box uvwmap
  21.  
  22.     local m = mesh vertices: #([10,0,0], [10,0,30], [-10,0,30], [-10,0,0], [0,-10,0], 
  23.                                 [0,10,0], [0,10,30], [0,-10,30]) \
  24.                     faces: #([1,2,3], [1,3,2], [1,3,4], [1,4,3], [5,7,8], [5,8,7], [5,6,7], [5,7,6]) \
  25.                     materialIDs: #(1, 1, 1, 1, 2, 2, 2, 2)
  26.     addModifier m (uvwMap maptype:5)  -- maptype is which radio button for now
  27.  
  28.     -- open map file, set up array to hold materials
  29.  
  30.     local f = openfile map_data
  31.     local mats = #(), n_mats = 0
  32.  
  33.     -- loop till end-of-file reading texturemap filename strings,
  34.     -- build a standard material from them and stick it in the mat. array
  35.  
  36.     while not eof f do          
  37.     (
  38.         local tm = bitmaptexture filename:(readvalue f)
  39.         local tm_op = bitmaptexture filename:(readvalue f)
  40.         n_mats += 1; mats[n_mats] = standardmaterial diffusemap:tm opacitymap:tm_op selfillum:40
  41.     )
  42.     close f
  43.  
  44.     -- open placement data file, set up array to hold created backdrop objects
  45.  
  46.     f = openfile placement_data
  47.     local items = #()
  48.     while not eof f do
  49.     (
  50.         -- read in name, pos, scale, rotation about z and instance proforma mesh there
  51.         -- add it to backdrop item array
  52.  
  53.         local name = readvalue f, pos = readvalue f + offset_pos,
  54.               scale = offset_scale * readvalue f, rot = quat (readvalue f) z_axis
  55.         local bd = instance m name:name scale:scale rotation:rot pos:pos \
  56.                                material:mats[random 1 n_mats]
  57.         append items bd
  58.     )
  59.     close f
  60.     delete m    -- drop propforma mesh
  61.  
  62.     #(items, mats)  -- return backdrops & materials
  63. )
  64.  
  65. utility backdropper "Load Backdrops"
  66. (
  67.     local maps_file, placement_file, backdrops, materials,
  68.           last_offset, last_scale
  69.  
  70.     group "files"
  71.     (
  72.         label mf "Maps file:" align:#left
  73.         button mapfile_btn "none" width:110
  74.         label pf "Placement file:" align:#left
  75.         button placefile_btn "none" width:110
  76.     )
  77.  
  78.     on mapfile_btn pressed do 
  79.     (
  80.         maps_file = getopenfilename caption:"choose maps definition file"
  81.         if maps_file != undefined do mapfile_btn.text = filenamefrompath maps_file
  82.     )
  83.  
  84.     on placefile_btn pressed do 
  85.     (
  86.         placement_file = getopenfilename caption:"choose placement definition file"
  87.         if placement_file != undefined do placefile_btn.text = filenamefrompath placement_file
  88.     )
  89.  
  90.     group "Adjustments"
  91.     (
  92.         spinner offsetx "Offset x:" range:[-1000, 1000, 0]
  93.         spinner offsety "Offset y:" range:[-1000, 1000, 0]
  94.         spinner offsetz "Offset z:" range:[-1000, 1000, 0]
  95.         spinner scalex "Scale x:" range:[-1000, 1000, 1]
  96.         spinner scaley "Scale y:" range:[-1000, 1000, 1]
  97.         spinner scalez "Scale z:" range:[-1000, 1000, 1]
  98.     )
  99.  
  100.     button load "Load backdrops"
  101.     button shuffle "Shuffle materials"
  102.     button del "Delete backdrops"
  103.  
  104.     on backdropper open do
  105.     (
  106.         backdrops = #(); materials = #()
  107.         last_offset = [0,0,0]; last_scale = [1,1,1]
  108.     )
  109.  
  110.     on load pressed do
  111.     (
  112.         local results = load_backdrops maps_file placement_file \
  113.                             [offsetx.value, offsety.value, offsetz.value] \
  114.                             [scalex.value, scaley.value, scalez.value]
  115.         backdrops = results[1]
  116.         materials = results[2]
  117.     )
  118.     
  119.     on shuffle pressed do
  120.         for b in backdrops do b.material = materials[random 1 materials.count]
  121.         
  122.     on del pressed do
  123.     (
  124.         delete backdrops; backdrops = #(); materials = #()
  125.     )
  126.  
  127.     on offsetx changed val do 
  128.     (
  129.         move backdrops [val - last_offset.x, 0, 0]; last_offset.x = val
  130.     )
  131.     on offsety changed val do 
  132.     (
  133.         move backdrops [0, val - last_offset.y, 0]; last_offset.y = val
  134.     )
  135.     on offsetz changed val do 
  136.     (
  137.         move backdrops [0, 0, val - last_offset.z]; last_offset.z = val
  138.     )
  139.  
  140.     on scalex changed val do 
  141.     (
  142.         scale backdrops [val/last_scale.x, 1, 1]; last_scale.x = val
  143.     )
  144.     on scaley changed val do 
  145.     (
  146.         scale backdrops [1, val/last_scale.y, 1]; last_scale.y = val
  147.     )
  148.     on scalez changed val do 
  149.     (
  150.         scale backdrops [1, 1, val/last_scale.z]; last_scale.z = val
  151.     )
  152. )   
  153.  
  154.