Script Needed To lightmap all objects in a scene and save them. Paid Job

I have a 3DS Max script that takes all objects in a scene and exports them into separate 3DS files, appending unique numbers to each object's name to make the filenames unique.

I need this basic script modified to do the following steps for every object in the scene in addition to just saving it as 3DS file:

- Select the object and export it as 3DS file with the individual name. This name must be used as template for the following files

- Select the objct and render it to texture with certain fixed parameters to create a lightmap. The lightmap must be saved under the same name as the 3DS mesh (as TGA)

- Select this object, which now has a UVW mapper which was created by the render to texture process and collapse that modifier so that the texture coordinates go into the mesh in channel 1

- Save this mesh again as 3DS file with a suffix appended to the filename, for example _l to make clear this is the version with the lightmap coordinates

I will pay for this script, details negotiable. I am located in Los Angeles, USA.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
playerdark's picture

Thankis for the replies all.

Thankis for the replies all. It seems to me that what I need is not so easy. I did some research in the meantime and played around with the script I have. Keep in mind I have no clue of maxscript, I am a c++ programmer, but I was able to take over some things I found on the internet.

The closest I could find is a script by a guy in another forum. I post it here, since he made it public too so I assume it's ok. I ran this script and it comes close to creating a lightmap. However this "lightmap" does include the texture and the lighting itself is not very good.

Every source I could find points in the same direction: use of the not documented render modus "rendertype:#bakeselected" plus the fact that no real lightmap can be created. Everybody had the same problem with the included texture.

As for my project, I have found a product called "flatiron" which does lightmap rendering for multiple objects. It is not fully automated but it is available for scripting now, so in time I might be able to modify my basic script that exports all objects to use this plugin.

Anyway I will post the script that I found here, maybe it is of help for some of you who want to carry on researching this problem. It really amazed me that an issue like lightmapping is so scarcely represented since all gaming companies should have a need for it.

--------------
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
max modify mode --step 2

--------------------------------------------------------------------
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
)
--<< --------------------------------------------------------------------
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
bakeRender i --theOutPutFile:("d:\\"+(i.name)+".tga")--step 5
i.INodeBakeProperties.removeAllBakeElements() --step 6

)
select objs
)
-------------------------------------------------------
on interBBack pressed do
(
for i in objs do
(

set coordsys local
convertToMesh i --step 1
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

subburb's picture

jerome Prévost

jerome Prévost (Subburb)

Hi, PlayerDark.

i've made a script doing this kind of stuff, for my personnal use (3dsmax-->collada export-->Stonetrip Shiva/Quest3D import). The script actually make some of things you're requesting, but not full automated, and not polished.

i can have a look if you want, we can discuss about your wishes, just mail me at [email protected] ;)

jerome Prévost (Subburb)

playerdark's picture

I have a 3DS Max script that

I have a 3DS Max script that takes all objects in a scene and exports them into separate 3DS files, appending unique numbers to each object's name to make the filenames unique.

I need this basic script modified to do the following steps for every object in the scene in addition to just saving it as 3DS file:

- Select the object and export it as 3DS file with the individual name. This name must be used as template for the following files

- Select the objct and render it to texture with certain fixed parameters to create a lightmap. The lightmap must be saved under the same name as the 3DS mesh (as BMP)

- Select this object, which now has a UVW mapper which was created by the render to texture process and collapse that modifier so that the texture coordinates go into the mesh in channel 1

- Save this mesh again as 3DS file with a suffix appended to the filename, for example "_lightmap" to make clear this is the version with the lightmap coordinates

The existing script already selects each obect and exports it. The modifications to this script must add the following steps:

- For each object perform a "Render To Texture" operation in order to create a lightmap for it. the lightmap should be created with the following parameters, as you can see in the enclosed screenshots:
>Output directory to should be the same where the 3DS files go
>The rendersettings can be left on default
> Padding should be set to 4
> Mapping Coordinates should be set to "Use Automatic Unwrap" with channel 1
> The output should be Lightmap with 256*256 size. The output type should be BMP and not TGA as the screenshot shows!
> The targetmap slot should be diffuse color
> The filename should have a suffix appended, "LightingMap" will do fine
> ATTENTION: The filenameprefix in this example is prop1 because the object prop1 was selected. In fact, it should be prop1_0 using the modified object name which will also be the original filename as created by the masterscript. It is important that the basic filename contains the enumeration which is created by the script so that the lightmaps can be associated with their respective 3DS file later.

- The lightmap should be automatically saved in the given outputdirectory

- This procedure will create a "Automatic Flatten UVs" modifier in the object's stack as can be seen in the Result.jpg screenshot.

- The stack should now be collapsed so that the created UV coordinates go into the main mesh and replace the old coordinates

- This new mesh should now be saved under a filename that uses the same filename as the first save (for example prop1_0.3DS) but with a suffix that marks it as the mesh with the altered texture coordinates (for example prop1_0_lightmap.3DS). ATTENTION: If this is not possible, this step can be left out and I can perform an export with the original script manually into a second directory later. However, if possible this should be performed since it simplifies the task of editing a scene

These steps must be performed for every object, lights, planes and boxes can be left out if possible. ATTENTION: these objects must not be omitted from the ORIGINAL export process that already exists. It is not necessary to create lightmaps for these objects, but the original export must be performed. It does not matter if you include these objects in the lightmap process however, their output will be ignored.

It is also important that the filenames are all recognizable as belonging together by using the exact prefix. For example, an object with the objectname prop0 will create the following files:
prop0_0.3DS (original export)
prop0_0_lightmap.3DS (mesh with modified texture coordinates)
prop0_0LightingMap.BMP (the lightmap)

playerdark's picture

Hi Anton, thanks for

Hi Anton,

thanks for answering. I will post an exact description here since it might be interesting for others as well and I will send a zip file with a testscene and the rudimetary script I already have to your email.

The purpose of the whole thing is to be able to edit a game level in 3DS. I need to edit a city scene with houses, streets, decoration objects and so on, place lightsources in 3DS and then export each object as a separate 3DS file with the main texture coordinates and again with the texture coordinates. My converter reads in these3DS files, matches the models with the normal and with the lightmap texture coordinates and creates a 3D object in a proprietary format with both texture coordinates which is then later loaded into the game engine.

I use the 3DS format because my converters all use the lib3ds library which is quite easy to use, although it lacks some features but I am working around this and have been using it for 4 years now, so for the current project I want to stay with it

Anton Berg's picture

This sounds

This sounds interresting...
Is it possible to describe more exactly what you want to do, is there a example scene that I could test with? What is the main reason for using the 3ds format? what is the naming convention?

Please contact me on my email below if you dont want to be public.

OgmaSoul3D
Anton Berg
anton[at]os3d.se

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.