Renders a sprite sheet from 3DS Max and kicks it to Unity
--Sprite Sheet Renderer by Corey Wolff | |
--Currently this is setup to use automatically spit out a sprite sheet to a specific location based on the | |
--CreateProject and CreateAsset script I made. It also wants to then have Unity chop up the sprite sheet. | |
--If people are intersted I could modify this to be a more generic version. | |
studioLib() | |
drvLibGame() | |
fn GetImageSize _frameRange = ( --Returns the size (in frames) that the image should be. The image is always a square | |
_stillTesting = true | |
i = 1 | |
while _stillTesting == true do ( | |
if(i*i < _frameRange) then ( | |
i +=1 | |
) | |
else( | |
_stillTesting = false | |
) | |
) | |
return i | |
) | |
fn PasteFrame _destination _source _theX _theY = ( --Pastes frame from teh source (single frame) to the destination (sprite sheet) | |
for i = 0 to _source.height do ( | |
setPixels _destination [_theX,_theY+i] (getPixels _source [0,i] _source.width) | |
) | |
) | |
fn RenderSheet _theWidth _theHeight _theStartFrame _theEndFrame _jump _path = ( --renders at each frame, and calculates the offset | |
_columnRow = GetImageSize (_theEndFrame - _theStartFrame) --find the smallest square to fit all the images | |
_finalFrame = bitmap (_columnRow * _theWidth) (_columnRow * _theHeight) filename: _path --generate the final image (currently blank) | |
f = 0 --theFame | |
for i = _theStartFrame to _theEndFrame by _jump do ( | |
slidertime = i | |
_tempRender = render vfb:false | |
_y = f/_columnRow --the y pos | |
_x = f- _y*_columnRow --the x pos | |
PasteFrame _finalFrame _tempRender (_x*_theWidth) (_y*_theHeight) | |
f+=1 | |
) | |
return _finalFrame | |
) | |
_cellWidth = 200 | |
_cellHeight = 200 | |
_startFrame = 5 | |
_endFrame = 30 | |
_columnRow = GetImageSize (_endFrame - _startFrame) | |
_theBits = filterstring mfn "_" | |
_imageSaveLocation = prjDrv + @"\" + _theBits[1] + @"\Unity\Assets\FX\" + _theBits[3] + @"\" | |
_imageSaveName = _theBits[3] + "_SS" | |
_SSDialog | |
try(destroydialog _ssDialog) catch() | |
Rollout _ssDialog "Render Sprite Sheet"( | |
spinner _cellWidth "Frame Width" range:[0,1000,50] type:#integer | |
spinner _cellHeight "Frame Height" range:[0,1000,50] type:#integer | |
spinner _startFrame "Start Frame" range:[0,1000,0] type:#integer | |
spinner _endFrame "End Frame" range:[1,1000,25] type:#integer | |
button _doTheThing "Render" | |
on _doTheThing pressed do (CustomArgs | |
renderWidth = _cellWidth.value | |
renderHeight = _cellHeight.value | |
_theBits = filterstring mfn "_" | |
_imageSaveLocation = prjDrv + @"\" + _theBits[1] + @"\Unity\Assets\Art\FX\" + _theBits[3] + @"\" --get the path for the sprite sheet | |
_imageSaveName = _theBits[3] + "_SS.png" --The name of the actual file | |
_unityLoc = @"Assets\Art\FX\" + _theBits[3] + @"\" + _imageSaveName --where it's going in unity | |
_numFrames = _endFrame.value - _startFrame.value --getting values ot pass to unity | |
_columns = GetImageSize _numFrames | |
_theMap = (RenderSheet _cellWidth.value _cellHeight.value _startFrame.value _endFrame.value 1 (_imageSaveLocation + _imageSaveName)) --the actual sprite sheet | |
makedir _imageSaveLocation | |
save _theMap | |
display _theMap | |
_theCommand = ("\"C:\Program Files (x86)\Unity\Editor\Unity.exe\" -batchmode -quit -executeMethod CustPipeline.MakeIntoSS -CustomArgs:ThePath="+_unityLoc+";Width="+_cellWidth.value as string+";Height="+_cellHeight.value as string+";Frames="+_numFrames as string+";Columns="+_columns as string) | |
print _theCommand | |
DOSCommand _theCommand | |
) | |
) | |
createDialog _ssDialog | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment