Automated sprite rendering and cropping from 3DSmax

If you’re as lazy as me you want to be able to press one button (or run one .bat file) to get your game sprites rendered and processed right into the final format and directory, so you can see them in the game.

First, you need a model with animations. In this example, I’m using “Male NPC Pack” from Cubix Studio.

They make excellent stuff, easy to work with and very reasonably priced to boot.

Next, get Sprite Render Tool. It’s a neat little max script utility that automates the rendering of different angles.


I made a few additions to the script for my specific needs:

  • Always renders 0,1,2 etc even with frame skipping
  • Restores default settings upon most errors now (how they were before the script was run)
  • Added direction in text option (uses “left” in filename instead of the degrees)
  • Added “ignore directions that can be mirrored” option
  • Added way to reverse the rotation
  • Added “set_target_dir” command to batch commands
  • Add batch commands to change directions, nth frames, etc flexibly for certain anims
  • Automatically sets up batch.txt as the batchfile if found in the same dir as the model
  • Added dos_command_in_target_dir batch command, so I can do various dos-things on the fly

Here is my hacked up version if you want it:

Here is the Sprite Tool batch file used to render our three animations (walk, attack, idle) in all directions (actually 5, because we mirror some of them):

#help_batchfile usage: (outputfile) (startframe) (endframe)
set_target_dir "../../../bin/worlds/RT_TopViewRPGTest/script/char/man/art"
#Sure, I could just do *.png but who knows when a dir won't exist or something and it will run this in the
#wrong place Safety first.

dos_command_in_target_dir "del walk*.png"
dos_command_in_target_dir "del idle*.png"
dos_command_in_target_dir "del attack*.png"
dos_command_in_target_dir "del die*.png"

nth_frame 13
directions 8
idle_$.png 6 65
dos_command_in_target_dir "smartcropper idle"

nth_frame 3
directions 8
walk_$.png 67 99
dos_command_in_target_dir "smartcropper walk"

nth_frame 3
directions 8
attack_$.png 406 424
dos_command_in_target_dir "smartcropper attack"

Note: My script requires that you install the free Max plug-in HiddenDOSCommand. If you have 3DS Max 9 64 bit, here is a 64 bit version I compiled.

Now, one issue with my particular game engine is all the sprites in a single animation should all be the same size, yet be small as possible.

In the example batch file above, the “smartcropper attack” command does this.

SmartCropper is a tiny command-line utility that scans a sequence of images, then crops them all at the smallest combined enclosing rectangle.

That way, you don’t have to worry about making the camera tightly fit the subject in Max.

Looking at the output, you can see it cropped the images to the best fit per sequence.


Here is SmartCropper with source (with a MSVS 2005 project), you’d need ClanLib if you wanted to modify/compile it.

Download Smartcropper with source

And here they are in the test RPG level, “Smart shadows” have been enabled for them.


13 thoughts on “Automated sprite rendering and cropping from 3DSmax

  1. Hamumu

    I need to try that 8-way renderer again. I gave it ten minutes once and got nowhere, bewildered and disoriented. But if I could figure it out it sure would be easier than the manual rotate, change filename, render system I do now. Over and over. Can’t use the cropping in my current work, but it would sure be handy in whatever I do next, because I am SO done with this 8-bit nonsense.

  2. Seth Post author

    If you ever do need cropping for non-alpha things let me know, I could add a flag to specify an RGB colorkey to use instead of alpha.

    Here is the help text from the util in case anybody wanted to see how it worked:

    J:\Documents and Settings\Seth>smartcropper
    SmartCropper V1.00 by Seth A. Robinson
    Usage: smartcropper [Input file left-based substring] [Optional addition parms]

    Crops a sequence of images to the combined smallest enclosing rect.

    Input with alpha information should be used, such as .tga or .png. Output will always be .png.

    -p, –pad=number Clear pixels to be added around the border as padding
    -o, –output=file Sequence base name to write to, if not specified, originals will be overwritten!

  3. Shawn

    I recently worked on a project where we were generating tons of sprites, wish I had thought to use maxscript this way. I was doing a lot of stuff manually, and through Batch Actions in Photoshop.

    Thanks for posting the info, maybe I can use it in the future.

    Long live LORD. :P


  4. Kamer Ali Yuksel

    Hi Seth,

    I am also a developer, I need to create spherical Impostor textures of rigged characters for one of my project. I have previously rotated manually by hand and rendered each of the frames.

    You can see one over here:

    I now want to use method, but I have hard times to work with the script. I am really new into 3ds Max. Can you help me please, I really need them ASAP. I will be glad If you are using any Instant messenger for faster conversation.

    By the way, using Imagemagick to get the images into one file is pretty efficient.

    Such as,
    “montage -background “transparent” -depth 8 -type TrueColorMatte ??.png -geometry 4096×1024 -tile 1×4 -matte -transparent “transparent” -type TrueColorMatte -depth 8 ped_3.png”

  5. Seth Post author

    Hi Kamer,

    The minor changes to the maxscript was my first time playing with MEL as well, so I probably wouldn’t be of much help.

    I’m sure it’s possible to modify things to output the spherical versions you need though.

    ImageMagick is great I hear, I did try to use it a while back but couldn’t get it to crop images the way I wanted… maybe it’s possible though.

    As an example, I ran my utility SmartCropper on your ped.jpg and it made it smaller, see

  6. Mattias

    I just stumbled upon this post today and this seems like just the thing I need for a sports game I’m working on. However, I’ve been struggling with the script and my own particular setup in 3ds max 9 all night without success. I can set things up and run the script just fine, but the problem I’m having is that my main object does not rotate when the rendering restarts for another direction. :S My rotation object (an ice hockey player) consists of a number of grouped body part meshes (jersey, head, helmet, gloves, skates). The mesh has been rigged with biped + the Physique modifier and I also have some keyframed animation in the scene for the biped joints.
    The thing is, I also have a hockey stick object (linked to the player’s hand), and when the stick is included in the rotation object grouping the stick rotates just fine, but not the rigged player mesh. I find this very odd… just wondering if you ever had a similar issue with this? or any ideas?

    Hmm.. update.. not sure what I did, just some grouping and ungrouping, and now I found that it actually does rotate the object, after every directional change. But only for the first frame of each new direction. In every subsequent frame after that, the rendered version of the object has “snapped back” into its original keyframed position, while in the viewport it is still in its proper rotated position(s) :S

    I’m still somewhat of a newbie with 3ds max so maybe this is just something trivial.. just wanted to know if you have any clue about this whatsoever?


  7. Seth Post author

    Hmm… I haven’t seen those problems.. one thing you can try is attaching everything to a dummy that is at the rotational center, and naming the dummy “RotationObject”. Run the script with nothing selected, and it will use that as the rotation object.

    You might try clicking the option “don’t render frames that can be mirrored”, if it fixes the “snapback problem” you mentioned that means I introduced a bug when I added that perhaps…

  8. jason

    Please forgive me for being a total noob at this, but can someone right up a detailed walk through on doing this? I have no experience in 3ds and I need to create some sprite sheets for a programming class Im taking. I found some free 3d models and animations and I need to get sprite sheets out of these not knowing a thing about the program.

  9. jason

    I spent some time with the help file and got things running. The problem I am having is when i select the mesh to rotate, it doesnt. It will just show the same position how ever many directions i have, or it will rotate for the first frame only.

  10. Dan

    Great info, I don’t understand where to get “smart shadows” is that in 3ds or in your game engine?

  11. Maggie

    dear sir:

    I test the script on 3ds max 2010, it works like a charm.
    I LOVE this.
    Only one drawback, can I set particularly several frames to render, the response said: This time output is still not supported.

Leave a Reply

Your email address will not be published. Required fields are marked *