Lightmap renderer [MaxScript]-need help

Hi.
I started to script a automatic lightmap renderer.
as I’m new to max script, my scripts are more like photoshop actions to do a similar job automatic.

now I describe my problem:
so far script can auto unwrap all scene objects in their channel2 and pack them into one sheet. then it can assign mentalray as renderer and define parameters to render a good quality with GI.

next step is to start render to texture. but as I have separate objects into scene, I will get separate textures. unless I attach all objects and do render to texture. so I want to to clone whole scene objects, attach copy objects, and after RTT simply delete them. I could not find something useful in maxscript help. and this simple code sometimes run and sometimes do not run:
for example:

myObjs = select geometry
copy myObjs

I even gived that up and thought about rendering separate object and then combine textures manually.
here my problem is to select all objects in the scene, one by one. how can I access to objects that I don’t know their name? and after that how to make sure all objects processed?

With the two lines of code that you wrote what you have done is made an array of references to every object in the scene and then assigned the return value from the copy() method to a new variable. If you query myObjs you’ll see that it holds a value of OK.

You need to copy each object individually and join the copies together to make the new object. MaxScript has an attach() method that will join one object to another but only for Editable_mesh or Editable_poly objects.

The code below will find copy all geometry in the scene, convert the copies to be Editable_mesh objects and attach all of the copies to make one object.


fn makeNewObjFromGeo = (
	/*
		All geometry in the scene is copied as an 
		editable_mesh and joined together
		
		Arguments:	
			None
		Returns:
			(geo)newObj:	An editable mesh object
	*/
	
	local newObj
			
	for i = 1 to geometry.count do (
		if i == 1 then (
			newObj = convertToMesh( copy geometry[ i ] )
		) else (
			attach newObj ( convertToMesh( copy geometry[ i ] ) )
		)
	)

	return newObj
)

I had a similar problem on a past project at work, we had it in our budget to to buy a license of this plugin: http://flatiron.3d-plugin.com/

It allows you to bake to one map without having to combine the meshes.

But Jeff’s solution is solid. Just throwing that handy plugin out there. :):

thank you guys. I just finished version 0.1

Usage:

  • this Script will AutoUnwrap whole scene Objects-for this version- in their second UV channel and render LightMap according to this channel.

Instalation:

  • drag .mcr file into 3ds max viewport
  • go to customize-> Customize User Interface
  • drop down category and choose FSR_Tools
  • add FSR_Bake to your toolbar

tutorial:

  • create a plane and a teapot over it. (you can put how many models you wish)
  • Hit FSR_Bake Button in your toolbar
  • you can find your lightmap texture in …\Documents\3dsMax\sceneassets\images with “_lightmap.tga”

LightMapBaking Script.zip (1.62 KB)


I could not find anything for opening a “save as” window in max script help to save rendered texture every where I want.
any tips on this would be very helpful :slight_smile:

for next version, I want to open a “save as” window and do some pannels.

Nice :nod:

This first way will have full control over image quality settings and bit depths. However, you have no ability to omit unwanted file types. Users could select Animated formats like .MOV or .AVI

getBitmapSaveFileName()

Another way would be something like this:

-- A string variable to store your save file name/path
saveFileString = ""

-- The "Save As" prompt, set whatever file types you want available
result = getSaveFileName filename:"" caption:"Save As..." \
            types:("BMP Image File (*.bmp)|*.bmp|JPEG File (*.jpg)|*.jpg|PNG Image File (*.png)|*.png|Targa Image File (*.tga)|*.tga|TIF Image File (*.tif)|*.tif")

-- If user didn't hit cancel...
if (result != undefined) do 
(
    -- Write the resulting file name/path to your string variable.
    saveFileString = result
)

But keep in mind this way will NOT have settings for image quality, bit depth, etc.

thank you thedour. I choosed first method and it works fine :slight_smile:

Omid,

First off, Congratulations on your first MaxScript!

Looking through your code (thanks for sharing) I see that you are using $ quite a lot. As a general rule you should avoid using the $ selection shortcut within a MaxScript. If the user interacts with the scene and changes the selection from what the script is assuming to be current then bad things can happen. $ is useful for quick prototyping and doing interactive work in the MaxScript Listener but is not trustworthy for full tools. It’s much safer to assign the required selection or object to a variable and then reference that as necessary.

thanks Jeff.
actually it’s really hard for me to do that! I understand that I should assign a variable and then use that, but sometimes I can not use my variables and I don’t figured out why and when this happens. for this script I used $ for some automatic jobs during script. where users can not change selection! :wink:
my friend suggested me to use select by material button and I think that is a good Idea for generating lightmaps.
now I need some times to work with rollouts :slight_smile: