Notifications
Clear all

[Closed] Baking gives "Error creating bitmap"

Oh crap, I just think I solved this damn problem that I’ve been struggling with since February!!

Changing my script into using “fileType”, didn’t do any good – although it must have eliminated one of two errors (thanks magicm).

Here’s how, while searching for my question on the discreet forums, I found Bobo’s archive of old Maxscript threads. I never found my post, but I found an excellent post by Bobo explaining some of the workings of texture baking. I hope it’s OK for Bobo that I quote his post here:

–Before calling the renderer, you will also have to enable baking
–for the object:
li.bakeEnabled = true
–You will also have to set a valid filename and type for the element
–to avoid getting an invalid path error message:
lm.fileName = (GetDir #image + “/MyBakeTest”)
lm.fileType = “.tga”

–Now you can call the renderer with an UNDOCUMENTED
–(come on, shoot me :o) switch:
render rendertype:#bakeSelected
–Right after that, you should remove the bake elements
–and disable baking again. At least in max 5.1, trying to
–render twice without removing the elements causes crashes.
–Have not tested in max 6.
li.removeAllBakeElements()
li.bakeEnabled = false
Take a look at the MacroScript that implements the Render To Texture function shipping with max 5 and 6 – most of the tricks are hidden in it…
(Disclaimer: The above might not work at all ;o)

Cheers,
Bobo

Note that Bobo writes that the “fileType” shouldn’t be the filename, although I believe that to be erroneous?

The clue here is: “removeAllBakeElements()”! When I did that on the object I was rendering – I got no more error messages! For some reason, the “Render to Texture” macroscript errors out on my machine, so I never got to see if any of the objects had bake information from before. Anyhow – when the old info is gone, everything is OK again.

Yey to Bobo and yey to me!!

Cheers, Rune

this bake textrue script is still hard to control . i am so tired to try again and again . my god .
not get what i want .

im using max5.1 , also sometime use max6 , but the command #bakeselected cant run normally . i just want bake a group of object automaticly . use completeMap . and send the result baked map to one of my specified dir , it is so hard to write the script , the biggest stone in the way is how to press the “render” button on the rollout of bake texture …

if anybody tell me how to give max a command to press the “render” button ,thanks a loooooooot .

and now i have to read the macro_baketextrue scripts just like bobo tell us , “all is in this script ” … my god . let me try to eat all the code of the macro…

maybe i can find the way in some days . god bless me .

now i think the key is the modifier ” unwarp_uvw()” . and in macro_bakeTexture script the most important thing is how to control this modifier .

the codes below maybe useful , copy from the macro_bakeTexture :

 
-- If the object doesn't have a modifier applied, create one and flatten it
   if (hasModifier == false) and objectIsBakable( curObj ) and (skipObject == false ) then
   (
	-- create a new autoflatten unwrapper
	--format "Create new unwrap_uvw
"
	unwrapMod = unwrap_UVW()
	
	unwrapMod.setAlwaysEdit ( false )
	unwrapMod.setMapChannel ( curObj.bakeChannel )
	unwrapMod.setFlattenAngle ( commonBakeProps.sThresholdAngle.value )
	unwrapMod.setFlattenSpacing( commonBakeProps.sSpacing.value )
	--unwrapMod.setFlattenNormalize( commonBakeProps.cNormalize.checked )
	unwrapMod.setFlattenNormalize( true )
	unwrapMod.setFlattenRotate( commonBakeProps.cRotate.checked )
	unwrapMod.setFlattenFillHoles( commonBakeProps.cFillHoles.checked )
	unwrapMod.setApplyToWholeObject( true )
	unwrapMod.name = "Automatic Flatten UVs"
	
	-- add it to the object
	-- add directly to the object to avoid groupness
	undo on (
	 addModifier( curObj )( unwrapMod )
	)
	
	-- #([1,0,0],[-1,0,0],[0,1,0],[0,-1,0],[0,0,1],[0,0,-1]) \
	-- #([0,0,1],[0,0,-1]) \
	--  2 \
   -- & flatten things
	unwrapMod.flattenMap \
	 commonBakeProps.sThresholdAngle.value \
	 #([1,0,0],[-1,0,0], [0,1,0],[0,-1,0], [0,0,1],[0,0,-1]) \
	 commonBakeProps.sSpacing.value \
	 true \
	 2 \
	 commonBakeProps.cRotate.checked \
	 commonBakeProps.cFillHoles.checked
	-- or use instead of true: commonBakeProps.cNormalize.checked \
	
   ) -- end, create new unwrapper


the below is my bake code . it works well . but with a little bugs .
how to use the bakeprogram :
1,select some objects .
2, just press the “bake now” button .
3,create 2 or more bitmaps at ” d:” .

my question :
question A: when bake the objects, the maps generated by the script has a lighter margin,and if u bake it more times ,the light margin will be more light . why ? it is also be in the first bitmap.

question B: why the generated bitmap is not exactly same as show in the VFB ? when bake i opened the VFB option ,and the map in VFB is very good . but the saved bitmap file is not same as in VFB ?

note : some codes is copyleft from Cgtalk , and some is copy from macro_bakeTexture.mcr .thanks ur all .

the codes are too long as i cant attach here ,have to make a rar file . please download .

im still going on …

rollout crystalBake "crystal bake"
(
local defaultRenderSet
local bakeMapSize=512
local objs=#()
local objs_1=#()  --normal objects .
local objs_2=#() --blend material objects .
local objName="lanhaibo"
local fileSaveDir="d:\\"
local bakeFileType=".tga"
local outputFile=""
---------------------------------------------------------------------
spinner interBakeMapSize "mapSize:" range:[10,60000,512] type:#integer
button  interBakeMapSizeSet1 "1024" 
edittext interBakeDir text:"d:\\"
edittext interBakeFileType text:".tga"
button interBakeFileTypeJpg "set to .jpg"
button interBakeFileTypeTga "set to .tga"
--button  interLoadDir "select dir by hand"
button  interBakeNow "bake now" 
-----------------------------------------------------------------------
fn addMyUVW obj =
 (
 unwrapMod = unwrap_UVW()
 
 unwrapMod.setAlwaysEdit  off 
 unwrapMod.setMapChannel  1 --this should be 1. 
 --and at the bake process we should use 3 , other of 1 . 
 unwrapMod.setFlattenAngle  45.0 
 unwrapMod.setFlattenSpacing 0.03 
 --unwrapMod.setFlattenNormalize( commonBakeProps.cNormalize.checked )
 unwrapMod.setFlattenNormalize on
 unwrapMod.setFlattenRotate  on
 unwrapMod.setFlattenFillHoles on
 unwrapMod.setApplyToWholeObject on
 unwrapMod.name = "lanhaibo next UVW"
	 
 addModifier obj  unwrapMod 
	 
 unwrapMod.flattenMap 45.0 \
	  #([1,0,0],[-1,0,0], [0,1,0],[0,-1,0], [0,0,1],[0,0,-1]) \
	  0.03  true  2 true  true
 
 )
------------------------------------------------------------------------------------
fn bakeLanhaibo objLan padding:16 CMName:"completeMap" CMType:".tga" \
	  cmSize:512  outputDir:"c:\\" =\
 (
 -- create test object
 --Sphere radius:25 smooth:on segs:32 mapCoords:on pos:[0,0,0] isSelected:on
 --box smooth:on  mapcoords:on isSelected:on
 --convertTo objLan editable_mesh
 
 unwrapMod = unwrap_UVW()
 
 unwrapMod.setAlwaysEdit  off 
 unwrapMod.setMapChannel  3
 unwrapMod.setFlattenAngle  45.0 
 unwrapMod.setFlattenSpacing 0.03 
 --unwrapMod.setFlattenNormalize( commonBakeProps.cNormalize.checked )
 unwrapMod.setFlattenNormalize on
 unwrapMod.setFlattenRotate  on
 unwrapMod.setFlattenFillHoles on
 unwrapMod.setApplyToWholeObject on
 unwrapMod.name = "lanhaibo Flatten UVs"
	 
 addModifier objLan  unwrapMod 
	 
 unwrapMod.flattenMap 45.0 \
	  #([1,0,0],[-1,0,0], [0,1,0],[0,-1,0], [0,0,1],[0,0,-1]) \
	  0.03  true  0 true  true
 ------------------------------------------------------------
 
 -- create bake element
 bakeCompleteMap =completeMap()
 bakeCompleteMap.outputSzX = bakeCompleteMap.outputSzY = cmSize
 bakeCompleteMap.fileType = cmType --"C:\	est.tga" -- I have NO idea why this works ??
 
 bakeCompleteMap.shadowsOn = on 
 
 -- set bake properties
 objLan.INodeBakeProperties.bakeEnabled = on
 objLan.INodeBakeProperties.flags = 1
 objLan.INodeBakeProperties.bakeChannel = 3
 objLan.INodeBakeProperties.nDilations = 16 -- default is 2
 --------------------------------------------------------------------
 --just like the second fn bakelanhaibo2 , changed the position of the command .
 -- add the completeMap after setting the normal values .
 ------------------
 --have tested . delete the upper 4 setting , it also works , yes , use the 
 --default setting . without any margin created in the map. 
 -- so  i got it !
 -- joy 
 --------------------------------------------------------------------- 
 objLan.INodeBakeProperties.addBakeElement bakeCompleteMap
 
 
 --objLan.INodeBakeProperties.renderWidth
 --objLan.INodeBakeProperties.renderHeight
 -- bake! .. show vfb and undisplay when done
 --undisplay (
 renderedMap=render rendertype:#bakeSelected outputSize:[cmSize,cmSize] \
  vfb:on outputFile:(outputDir+cmName+cmType) \ 
  filterMaps:on  antiAliasFilter:(catmull_rom()) --ProgressBar:on
 --"c:\	est.tga"
 --)
 --removeBakeElements
 objLan.iNodeBAkeProperties.removeAllBakeElements()
	-- open saved file
  )
---------------------------------------------------------------------------------
--the bakeLanhaibo2 is the copy of bakeLanhaibo . just for program test .changed the padding value .
------------------------------------------------------------------------------------
fn bakeLanhaibo2 objLan padding:16 CMName:"completeMap" CMType:".tga" \
	  cmSize:512  outputDir:"c:\\" =\
 (
 unwrapMod = unwrap_UVW()
 
 unwrapMod.setAlwaysEdit  off 
 unwrapMod.setMapChannel  3
 unwrapMod.setFlattenAngle  45.0 
 unwrapMod.setFlattenSpacing 0.03 
 --unwrapMod.setFlattenNormalize( commonBakeProps.cNormalize.checked )
 unwrapMod.setFlattenNormalize on
 unwrapMod.setFlattenRotate  on
 unwrapMod.setFlattenFillHoles on
 unwrapMod.setApplyToWholeObject on
 unwrapMod.name = "lanhaibo Flatten UVs"
	 
 addModifier objLan  unwrapMod 
	 
 unwrapMod.flattenMap 45.0 \
	  #([1,0,0],[-1,0,0], [0,1,0],[0,-1,0], [0,0,1],[0,0,-1]) \
	  0.03  true  0 true  true
 ------------------------------------------------------------
 
 -- create bake element
 bakeCompleteMap =completeMap()
 bakeCompleteMap.outputSzX = bakeCompleteMap.outputSzY = cmSize
 bakeCompleteMap.fileType = cmType --"C:\	est.tga" -- I have NO idea why this works ??
 bakeCompleteMap.enabled = on
 bakeCompleteMap.shadowsOn = on 
 
 
 -- set bake properties
 
 objLan.INodeBakeProperties.bakeEnabled = on
 objLan.INodeBakeProperties.flags = 1
 objLan.INodeBakeProperties.bakeChannel = 3
 objLan.INodeBakeProperties.nDilations = padding
 ----------------------------------------------------------------------
 --this change works now !
 -- first set the normal settings like : bakeEnabled ,use channel , edge padding 
 --then add the completeMap to the bake element slot  . and then the padding 
 --works now . 
 --at first function i havent change this position . so anything maybe as
 --default . padding not works .
 
 -----------------------------------------------------------------------
 objLan.INodeBakeProperties.addBakeElement bakeCompleteMap
 ----------------------------------------------------------------------
 --objLan.INodeBakeProperties.renderWidth
 --objLan.INodeBakeProperties.renderHeight
 -- bake! .. show vfb and undisplay when done
 --undisplay (
 renderedMap=render rendertype:#bakeSelected outputSize:[cmSize,cmSize] \
  vfb:on filterMaps:on  antiAliasFilter:(catmull_rom()) --progressBar:on
--outputFile:cmType--(outputDir+cmName+cmType)--"c:\	est.tga"
 --)
 --removeBakeElements
 objLan.iNodeBAkeProperties.removeAllBakeElements()
	-- open saved file
 --shelllaunch (outputDir+cmType)
 )
 
fn LanDeleteModifiers obj namePattern:"lanhaibo"=
 (
  local theModifiers=#()
  theModifiers=obj.modifiers
  if theModifiers[1]==undefined then messagebox "object has no modifiers"
  else 
   (
 
  for i=1 to  theModifiers.count  do 
   (
   if ( findString theModifiers[1].name  namePattern )!=undefined  do \
	 
   ( deleteModifier obj 1 )
   
   )
  )
 )
fn addMyMaterial obj theMapDirName =
 (
  local  Mymaterial=standardMaterial()
  local myMap=bitmaptexture fileName:theMapDirName
  
  
  --myMaterial.adTextureLock=on
  myMaterial.name=obj.name
  myMaterial.diffuseMap=myMap
  --myMaterial.selfIllumAmount=100.0
  myMaterial.selfillumMap=myMap
  myMaterial.showInViewPort=on
  obj.material=myMaterial
  
 )
fn myobjs =
(
 if selection[1]==undefined then messagebox "nothing selected"
 else 
 (
 mySelection=for i in selection \ 
  where (superclassof i)==geometryclass collect i
 if mySelection[1]==undefined do messagebox "pls select objects"
 
 )
 return  myselection
)
--bakeLanhaibo $
-----------------------------------------------------------------------
on interBakeDir changed val do fileSaveDir=val
on interBakeDir entered val do fileSaveDir=val
on interBakeFileType changed val do bakeFileType=val
on interBakeFileType entered val do BakeFileType=val 
on interBakeFileTypeJpg pressed do (interBakeFileType.text=".jpg";bakeFileType=".jpg")
on interBakeFileTypeTga pressed do (interBakeFileType.text=".tga";bakeFileType=".tga")
--on interLoadDir pressed do fileSaveDir=
on interBakeMapSize changed val do BakeMapSize=val
on interBakeMapSize entered	 do bakeMapSize=interBakeMapSize.value
on interBakeMapSizeSet1 pressed do 
 (
 bakeMapSize=1024
 interBakeMapSize.value=1024
 )
on interBakeNow pressed do 
 (
 -------------------------------------------------------------
  try 
  (
  
  objs=myobjs()
  
  objs_1=objs
  --objs_1=for i in objs where (classof i.material!=blend ) collect i
  objs_2=for i in objs where (classof i.material==blend ) collect i
  ---------------------------------------------------------------------
  --bake the normal objects group .
 
   
  for i in objs_1 do 
   (
   select i --note : u mast select the object to get bake function work ,
   -- it is because the render #bakeselected .need select the bake object .lanhaibo .
   
   max modify mode -- u mast open the modify mode to let the bake work . why ? lanhaibo.
   
   bakeLanhaibo i CMName:(i.name)  CMType:bakeFileType \ 
		cmSize:bakeMapSize  outputDir:fileSaveDir 
   
   --note: in this place the cMName cant be changed to other name . must be (i.name) now . 
   --should be checked tomorrow . 
   ------------------------------------------------------------------
   --this command is for padding 16.		--
   bakeLanhaibo2 i cmType:(fileSaveDir+(i.name)+"PAD"+bakeFileType) --"d:\\lanhaibo.tga"	  --
   ------------------------------------------------------------------
 
   
   lanDeleteModifiers i -- next step , delete lanhaibo  modifier . 
   
   addMyUVW  i  --add my uvw , the same of bake . alternate the save UVW coordinate .
   --cause cant find the save UVWS command . only a save() function ., not enough .
   
   addMyMaterial i ( fileSaveDir + i.name + bakeFileType)
   -----------------------------------------------------------
   --material change , if not do this . object will be all white .why ??lanhaibo
   i.Material.selfIllumAmount=100.0
   i.Material.selfillumMap=undefined
   i.Material.showInViewPort=on
		 ----------------------------------------------------------------------------
   
   --convertToMesh i
   
   ------------------------------------------------------------------
   -- show map in view port command: material.showInViewPort=on
   --------------------------------------------------------------------
   --i.material.showinviewport
   
   )
  
  )catch messagebox "please select objects to bake"
 
 )

on crystalBake open do 
 (
 defaultRenderSet=renderers.current
 --defaultRenderSet.antiAliasFilter
 myRenderSet=default_scanline_renderer()
 myRenderSet.mapping=on
 myRenderSet.shadows=on
 myRenderSet.autoReflect=on
 myRenderSet.antiAliasing=on
 myRenderSet.antiAliasFilter=catmull_rom()
 
 renderers.current=myRenderSet
 

 
 )
on crystalBake close do 
 (
 renderers.current=defaultRenderSet
 )
 
)createdialog crystalBake

no message followed . Get what i want by myself .:banghead: going on …

the code maybe so long and nobody have time to read it . so shortly the main body of it is :

1, add a unwrap_UVW modifier to a object . and flatten it .
2, use “render #bakeselected …” command to render the flatten object texture map .

  1. i have search 2 days for the question :
    why the rendered map has a lighten edge. a little light. and the light seems not affected by unwrap_uvw setting and the render setting options .

maybe i have not find the key option of unwrap_UVW or render , keep going on …

wish somebody show me the key , that i can save my time , and time is more important than anthing ,…:curious:

by the way > i have attached a jpg file to show the question . but i dont know how to show it


addition : links here look at the thin white line in the edge of the bitmap .i have set the “edge padding” to 16 ,so u can see the padding part of the map ,the white line is between the main map part and the padding map part . dont know why .: http://storage.msn.com/x1pnp_rgmi5o50Au-yO-FfowlcbsxGmW9Rl1Fwr_whq1c61R-AgKCQoTfHs2kEvH_jXECgspkgbx9CK8rPeymiu5F4QxFY1HAkWugw9cipzEDCDv_TY6QdWo_PKl4GrFdxXacUEZS3o5OM

–pls give some advise :

  rollout bakeNew "bakeNew"
(
local objs=#()
local Mps=#()
local defaultRenderSet
----------------------------------------------
button interCreateBox " create a box" --this is only for easy create a box to test .
button interBake  " bake "  --run bake.
button interBBack "Bake Back"  --this is for my work . bake at channel 3 and use the bake output map back it to channel 1.
----------------------------------------------
fn selectObjs =
 (
 local tempArray=#()
 try (
 if selection[1]==undefined then messagebox "pls select objects"
 else 
   (
   if selection[2]==undefined then 
	(
	if (superclassof selection[1])!=geometryclass then messagebox "not geometry"
	else tempArray[1]=selection[1]
	)
   else tempArray=for i in selection where (superclassof i)==geometryclass collect i
   )
   
  )catch messagebox "pls select objects"
 
 return tempArray
 )
-------------------------------------------------
fn addMaterial obj MapPath:"" =
 (
 local tempMat=standardMaterial()
 local theMap=bitMapTexture fileName:MapPath filtering:1
 
 tempMat.name=obj.name
 tempMat.diffuseMap=theMap
 --tempMat.selfillumMap=theMap
 tempMat.selfIllumAmount=100.0
 tempMat.showInViewPort=on
 
 obj.material=tempMat
 obj.material.showInViewPort=on
 return tempMat
 )
-------------------------------------------------
fn addUVW obj theMapChannel:1=
 (
 local unwrapMod = unwrap_UVW()
  
 unwrapMod.setAlwaysEdit  off 
 unwrapMod.setMapChannel  theMapChannel
 unwrapMod.setFlattenAngle  45.0
 unwrapMod.setFlattenSpacing 0.00 
 unwrapMod.setFlattenNormalize on
 unwrapMod.setFlattenRotate  on
 unwrapMod.setFlattenFillHoles on
 unwrapMod.setApplyToWholeObject on
 unwrapMod.name = "lanhaibo_UVW"
 
 addmodifier obj unwrapMod 
 unwrapMod.flattenMap 45.0 \
	  #([1,0,0],[-1,0,0], [0,1,0],[0,-1,0], [0,0,1],[0,0,-1]) \
	  0.03  true  0 true  true
 return obj
 )
---------------------------------------
fn completeMapElement theFileType:".tga" cmSize:512 =
 (
 bakeC=completeMap()
 bakeC.enabled=on 
 bakeC.outputSzX=bakeC.outputSzY=cmSize--element size . && mapSize of bakeRender
 bakeC.fileType= theFileType
 bakeC.shadowsOn=on
 return bakeC 
 )
----------------------------------------
fn addElement obj theElement theChannel:3 thePadding:16 =
 (
 obj.InodeBakeproperties.addBakeElement theElement
 obj.InodeBakeproperties.bakeEnabled=on
 obj.InodeBakeproperties.bakeChannel=theChannel
 obj.InodeBakeproperties.nDilations=thePadding
 return obj
 ) 
----------------------------------------
fn bakeRender obj MapSize:512 theOutPutFile:"d:\\lanhaibo.tga" =
 (
 render renderType:#bakeSelected outputsize:[mapSize,mapSize] \ 
   vfb:on filterMaps:on antiAliasFilter:(catmull_rom()) \ 
   outputFile:theOutPutFile
 
 )
-----------------------------------------------
on interCreateBox pressed do (box prefix:"lanhaibo" isSelected:on )
-----------------------------------------------------
on interBake pressed do 
 (
 
 objs=selectObjs()
 for i in objs do 
  ( 
 
  set coordsys local
  select i 		   --step 1 <must select it>
  max modify mode 		 --step 2 <must open modify mode>
  
  --------------------------------------------------------------------
  if i.modifiers[1]==undefined then \
  addUVW i theMapChannel:3 \
  else 
   (
   if (findString (i.modifiers[1].name)\
	 "lanhaibo")==undefined do \
	addUVW i theMapChannel:3	 --step 3 <add uvwmap modifier>
   )
  --------------------------------------------------------------------
  addElement i (completeMapElement theFileType:("d:\\"+(i.name)+".tga")) \
			   --step 4 <add bake element> 
  bakeRender i --theOutPutFile:("d:\\"+(i.name)+".tga")--step 5 <bake>
  i.INodeBakeProperties.removeAllBakeElements()  --step 6 <remove the bake element>
  
  )
select  objs
 )
-------------------------------------------------------
on interBBack pressed do
 (
 for i in objs do 
  (
  
   set coordsys local
   convertToMesh i --step 1 <collapse the object . delete the modifier>
   addUVW i theMapChannel:1
   addMaterial i MapPath:("d:\\"+(i.name)+".tga" )
   
  )
 
 )
--------------------------------------------------------
on bakeNew open do 
 (
 defaultRenderSet=renderers.current
 --defaultRenderSet.antiAliasFilter
 myRenderSet=default_scanline_renderer()
 myRenderSet.mapping=on
 myRenderSet.shadows=on
 myRenderSet.autoReflect=on
 myRenderSet.antiAliasing=on
 myRenderSet.antiAliasFilter=catmull_rom()--has set in fn.bakeRender
 
 renderers.current=myRenderSet
 )
on BakeNew close do 
 (
 renderers.current=defaultRenderSet
 
 )

)createdialog bakeNew 

sorry for i changed the code , to add a lightingMap and a diffuseMap , it seems not work too .the lighting line still there , , maybe it is because something other setting .

thanks for ur help , thanks .

  rollout bakeNew "bakeNew"
(
local objs=#()
local Mps=#()
local defaultRenderSet
----------------------------------------------
button interCreateBox " create a box"
button interBake  " bake "
button interBBack "Bake Back"
----------------------------------------------
fn selectObjs =
 (
 local tempArray=#()
 try (
 if selection[1]==undefined then messagebox "pls select objects"
 else 
   (
   if selection[2]==undefined then 
	(
	if (superclassof selection[1])!=geometryclass then messagebox "not geometry"
	else tempArray[1]=selection[1]
	)
   else tempArray=for i in selection where (superclassof i)==geometryclass collect i
   )
   
  )catch messagebox "pls select objects"
 
 return tempArray
 )
-------------------------------------------------
fn addMaterial obj MapPath:"" =
 (
 local tempMat=standardMaterial()
 local theMap=bitMapTexture fileName:MapPath filtering:1
 
 tempMat.name=obj.name
 tempMat.diffuseMap=theMap
 --tempMat.selfillumMap=theMap
 tempMat.selfIllumAmount=100.0
 tempMat.showInViewPort=on
 
 obj.material=tempMat
 obj.material.showInViewPort=on
 return tempMat
 )
-------------------------------------------------
fn addUVW obj theMapChannel:1=
 (
 local unwrapMod = unwrap_UVW()
  
 unwrapMod.setAlwaysEdit  off 
 unwrapMod.setMapChannel  theMapChannel
 unwrapMod.setFlattenAngle  45.0
 unwrapMod.setFlattenSpacing 0.00 
 unwrapMod.setFlattenNormalize on
 unwrapMod.setFlattenRotate  on
 unwrapMod.setFlattenFillHoles on
 unwrapMod.setApplyToWholeObject on
 unwrapMod.name = "lanhaibo_UVW"
 
 addmodifier obj unwrapMod 
 unwrapMod.flattenMap 45.0 \
	  #([1,0,0],[-1,0,0], [0,1,0],[0,-1,0], [0,0,1],[0,0,-1]) \
	  0.03  true  0 true  true
 return obj
 )
---------------------------------------
fn completeMapElement theFileType:".tga" cmSize:512 =
 (
 bakeC=completeMap()
 bakeC.enabled=on 
 bakeC.outputSzX=bakeC.outputSzY=cmSize--element size . && mapSize of bakeRender
 bakeC.fileType= theFileType
 bakeC.shadowsOn=on
 return bakeC 
 )
fn lightingMapElement theFileType:".tga" cmSize:512 =
 (
 bakeC=lightingMap()
 bakeC.enabled=on 
 bakeC.outputSzX=bakeC.outputSzY=cmSize--element size . && mapSize of bakeRender
 bakeC.fileType= theFileType
 bakeC.shadowsOn=on
 return bakeC 
 )
fn diffuseMapElement theFileType:".tga" cmSize:512 =
 (
 bakeC=lightingMap()
 bakeC.enabled=on 
 bakeC.outputSzX=bakeC.outputSzY=cmSize--element size . && mapSize of bakeRender
 bakeC.fileType= theFileType
 bakeC.shadowsOn=on
 return bakeC 
 )

----------------------------------------
fn addElement obj theElement theChannel:3 thePadding:16 =
 (
 obj.InodeBakeproperties.addBakeElement theElement
 obj.InodeBakeproperties.bakeEnabled=on
 obj.InodeBakeproperties.bakeChannel=theChannel
 obj.InodeBakeproperties.nDilations=thePadding
 return obj
 ) 
----------------------------------------
fn bakeRender obj MapSize:512 theOutPutFile:"d:\\lanhaibo.tga" =
 (
 render renderType:#bakeSelected outputsize:[mapSize,mapSize] \ 
   vfb:on filterMaps:on antiAliasFilter:(catmull_rom()) \ 
   outputFile:theOutPutFile
 
 )
-----------------------------------------------
on interCreateBox pressed do (box prefix:"lanhaibo" isSelected:on )
-----------------------------------------------------
on interBake pressed do 
 (
 
 objs=selectObjs()
 for i in objs do 
  ( 
 
  set coordsys local
  select i 		   --step 1 <must select it>
  max modify mode 		 --step 2 <must open modify mode>
  
  --------------------------------------------------------------------
  if i.modifiers[1]==undefined then \
  addUVW i theMapChannel:3 \
  else 
   (
   if (findString (i.modifiers[1].name)\
	 "lanhaibo")==undefined do \
	addUVW i theMapChannel:3	 --step 3 <add uvwmap modifier>
   )
--<<  --------------------------------------------------------------------
  addElement i (lightingMapElement theFileType:("d:\\"+(i.name)+"lighting"+".jpg"))
  addElement i (diffuseMapElement theFileType:("d:\\"+(i.name)+"diffuse"+".jpg"))
-->>  ----------------------------------------------------------------------
  addElement i (completeMapElement theFileType:("d:\\"+(i.name)+".tga")) 
			   --step 4 <add bake element> 
  bakeRender i --theOutPutFile:("d:\\"+(i.name)+".tga")--step 5 <bake>
  i.INodeBakeProperties.removeAllBakeElements()  --step 6 <remove the bake element>
  
  )
select  objs
 )
-------------------------------------------------------
on interBBack pressed do
 (
 for i in objs do 
  (
  
   set coordsys local
   convertToMesh i --step 1 <collapse the object . delete the modifier>
   addUVW i theMapChannel:1
   addMaterial i MapPath:("d:\\"+(i.name)+".tga" )
   
  )
 
 )
--------------------------------------------------------
on bakeNew open do 
 (
 defaultRenderSet=renderers.current
 --defaultRenderSet.antiAliasFilter
 myRenderSet=default_scanline_renderer()
 myRenderSet.mapping=on
 myRenderSet.shadows=on
 myRenderSet.autoReflect=on
 myRenderSet.antiAliasing=on
 myRenderSet.antiAliasFilter=catmull_rom()--has set in fn.bakeRender
 
 renderers.current=myRenderSet
 )
on BakeNew close do 
 (
 renderers.current=defaultRenderSet
 
 )

)createdialog bakeNew 
Page 2 / 2