Sprite Render Script v0.6
by
Matt Spencer
If you find bugs, have comments or requests, email me.
Features
- Exports XML animation frame data. Includes origin for each frame (in pixel coordinates).
- Using "Sprite Points", you can store the per-frame positions of anything in the animation. These are stored in frame coordinates.
- You can save the sheet's render settings and render it again without re-entering the settings
- Frames are automatically cropped and placed into rows.
- Exports a 32-bit PNG or TGA, and an optional heightmap in a 24-bit grayscale bitmap. This heightmap can be used to generate a normal map.
- The script's default settings are easily set and restored.
- You can customize the data output format, or add custom attributes to the "Sprite Points" by modifying the "Custom.ms" script.
Instructions
You must render from a camera, so put at least one camera in the scene. You can use as many cameras as you'd like, and pick a different one for each sequence you render. Change the settings, and then hit "Render Sequence" for each individual animation sequence. The Sprite Sheet Viewer will automatically pop up and show you the results. When you're finished rendering the sheet, hit "Save Image and Data" to export the image and the XML data.
From the viewer, you can (continuously) delete the last sequence in the sheet, or all of them. You can press "View Sprite Sheet" anytime to see the sheet. To avoid re-entering the settings every time the sheet is rendered, save them using "Save Render List". Use "Render from File" to render the sheet again later.
Step by Step:
- Set the Sprite Sheet's width and height. This is the size of the exported image.
- If your sprite's frames need a small space between each packed frame, set the border 'padding' to something other than zero. Padding is measured in pixels. To tightly-pack rectangle sprites (for example, 64 x 64 frames in a 128 x 128 sheet), set the "padding" to 0. Also, make sure the rendered image touches the edges of the camera's frame, or it will be cropped.
- Now set the sequence's settings. All of these settings are included in the render list when its saved. First is the width and height of the frame. This is the size of the camera's initial render, the actual frame size will be smaller if it is cropped. (see tip #1)
- The sequence's name is optional and there for convenience. It's value is exported in the XML data.
- "Start" and "End" are the beginning and end of the sequence, in frames
- "Nth Frame" is the frame interval. At setting of 1 means every frame is rendered. A setting of 2 means the framerate is cut in half, etc. This is useful for lowering the effective framerate per-sequence. Sprite sheets can fill up quickly, and a high framerate isn't practical for larger sprites.
- You can optionally assign an "origin object". This object's position is converted into frame coordinates for each frame. If no object is selected, the camera's center is used (by default).
- A camera must be selected, or no rendering will happen.
- If you need to export custom data points with your animation, press "Create Point" to create any number of Sprite Points in the scene. Like the origin object, these points are converted to frame coordinates and stored with the animation data. When you select one of these points a rollout will appear at the bottom of the window, showing the editable properties of the point. These editable properties are exported with the point data, and allow custom values to be added to the exported XML file. If you know MaxScript, more properties can be added by modifying the custom attribute definition in "Custom.ms". (see tip #2)
- Now, press "Render Sequence" to render and bring up the sprite sheet.
(put an explanation of rendering layered, complex sprites with Sprite Points here)
Other Details
- Tip #1: Keeping a consistent, relative render-size between different objects will rely on a balance of three things: distance from the camera, and the camera's field of view, and the frame size. Using a wide camera angle and large frame size will avoid headaches when you need to render a character with a wide range of motion, and keep everything consistent.
- Tip #2: Sprite Points are a powerful way to tag custom data to your animations. Instead of rendering a running character in it's entirety, you can put parts of the character in different layers, and render those parts separately. You could render variations for those parts, and attach them dynamically to the others in-game. To attach them to the right positions in-game (and while animating), you need per-frame coordinates of where to attach each part. Creating a Sprite Point and linking it to the origin of an animated limb allows you to export the animated positions. (better explanation w/ images in next update)
- All of the settings in Max's Render dialog apply to the renders: Anti-aliasing, motion-blur, etc... If you change them, you must render a frame from that dialog before the settings apply.
- The render list that is saved with "Save Render List" stores the visible layers' names for each sequence. When "Render from File" is used, all layers are hidden and each sequence's visible layers are unhidden before rendering. The layer names must be the same as when the list was saved or the layer won't be hidden when rendering.
- The origin object and sprite points don't need to be in the frame to be included in the export data. If its in the scene, it will be stored with the sequence data. Even if a point is behind the camera, it'll be saved, but (obviously) the data won't be accurate.
- The "timestep" value that is exported is in milliseconds. Its based on the "Nth Frame" setting and on the Frame Rate (in the Time Configuration dialog). Playback speed doesn't affect the timestep.
For example:
if Nth Frame = 1, FPS = 30, then "timestep"= 33.
If Nth Frame = 2, FPS = 30, then "timestep"= 66
- If you change the size of the sheet while its open, close it and reopen again to get the new size.
- If you start a sequence at frame 0 and end at frame 1, you've rendered two frames: frame 0 and frame 1.
Planned Improvements (v0.7)
- make render settings save to XML, for easy hand-editing.
- option to make point coordinates relative to the origin (instead of just frame coords)
- include an option to turn cropping off
- include option to render columns instead of rows. (might help with space efficiency?)