Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :: Pad Animation
- :: Author: Stewie410 <[email protected]>
- :: Client: user/kevin5609
- :: Desc: Take any given animation with individual frames in a directory, and pad it out.
- :: Each frame must have the same base name and extension
- :: Now including CMD args, see :showHelp for more information
- :: Date: 2018-04-21
- :: Env: Windows 7 x64 Professional
- :: Tested: Win7x64 Pro
- :: Win10x64 Pro
- @echo off
- setlocal enableextensions
- set me=%~nx0
- set medir=%~dp0
- :: ----------------------------------------- ::
- :: -- User Defined Vars -- ::
- :: ----------------------------------------- ::
- :: Note: All path and name definitions are CASE-SENSITIVE
- :: Define the full path to your animation
- set pathToAnimation=%userprofile%\Desktop\Animation
- :: Define the baseline name for your animation's files, eg back-button
- set animationBaselineName=menu-back
- :: Define the type file, eg png
- set filetype=png
- :: Define the number of frames to start with (count starts at 0, eg 0-16 == 17 frames)
- :: Ignore the non-numbered files
- set initialFileCount=20
- :: Define the frame number to start counting at
- :: Example: If you have 20 frames (file-name-0 to file-name-19), but you want to
- :: start at the fifth frame, set startCountingAt=4
- set startCountingAt=0
- :: Define the padding offset
- :: If you want 2x as many frames, paddingOffset==2
- set paddingOffset=2
- :: ----------------------------------------- ::
- :: -- End User Defined Vars -- ::
- :: ----------------------------------------- ::
- :: Argument Processing
- :argLoop
- if not "%~1."=="." (
- if /i "%~1"=="/f" if not "%~2."=="." set animationBaselineName=%~2
- if /i "%~1"=="/t" if not "%~2."=="." set filetype=%~2
- if /i "%~1"=="/d" if not "%~2."=="." set pathToAnimation=%~2
- if /i "%~1"=="/n" if not "%~2."=="." set initialFileCount=%~2
- if /i "%~1"=="/p" if not "%~2."=="." set paddingOffset=%~2
- if /i "%~1"=="/h" set showHelp=1
- if /i "%~1"=="/?" set showHelp=1
- shift
- goto :argLoop
- )
- if defined showHelp goto :showHelp
- :: Other vars
- set hd=@2x
- set dir=%pathToAnimation:"=%
- set name=%animationBaselineName:"=%
- set ext=%filetype:"=%
- if "%ext:~0,1%"=="." set ext=%ext:~1%
- set /a "endCount=initialFileCount*paddingOffset"
- set /a "endCount=endCount-2"
- :: --
- :: Run
- :: Error handles
- if "%paddingOffset%" leq "1" goto :eof
- if not exist "%pathToAnimation%" goto :eof
- :: Space the files out
- cd "%pathToAnimation%"
- set cnt=%initialFileCount%
- :spaceLoop
- if %cnt% gtr %startCountingAt% (
- call :space %cnt%
- set /a "cnt-=1"
- goto :spaceLoop
- )
- :: Pad each frame
- set cnt=%startCountingAt%
- :padLoop
- if %cnt% leq %endCount% (
- call :dupe %cnt%
- set /a "cnt=cnt+1"
- goto :padLoop
- )
- :: Exit
- cd "%medir%"
- goto :eof
- :: Subs
- :: Space out the frames based on the paddingOffset variable
- :space
- if "%~1."=="." goto :eof
- if %~1 leq 0 goto :eof
- if %~1 gtr %initialFileCount% goto :eof
- if defined i set "i="
- if defined o set "o="
- set i=%~1
- set /a "o=i*paddingOffset"
- if exist "%name%-%i%.%ext%" ren "%name%-%i%.%ext%" "%name%-%o%.%ext%"
- if exist "%name%-%i%@2x.%ext%" ren "%name%-%i%@2x.%ext%" "%name%-%o%@2x.%ext%"
- goto :eof
- :: Duplicate the files to make up the now empty space in the animation
- :dupe
- if "%~1."=="." goto :eof
- if %~1 lss 0 goto :eof
- if %~1 gtr %endCount% goto :eof
- if defined i set "i="
- if defined o set "o="
- set i=%~1
- set /a "o=i+1"
- if not exist "%name%-%i%.%ext%" if exist "%name%-%i%@2x.%ext%" goto :hd
- if not exist "%name%-%i%.%ext%" goto :eof
- if exist "%name%-%o%.%ext%" goto :eof
- copy /y "%name%-%i%.%ext%" "%name%-%o%.%ext%"
- :hd
- if not exist "%name%-%i%@2x.%ext%" goto :eof
- if exist "%name%-%o%@2x.%ext%" goto :eof
- copy /y "%name%-%i%@2x.%ext%" "%name%-%o%@2x.%ext%"
- goto :eof
- :remOuterQuotes
- if "%~1."=="." goto :eof
- set tmp=###%1###
- set tmp=%tmp:###"=%
- set tmp=%tmp:"###=%
- set tmp=%tmp:###=%
- goto :eof
- :showHelp
- echo padAnimation [/f name][/t type][/d path][/n int][/p int][/h][/?]
- echo.
- echo padAnimation aims to increase the length of a simple animation by duplicating each frame.
- echo This assumes that each frame is a separate file, and each frame shares a similar naming scheme:
- echo.
- echo %animationBaselineName%-0.ext
- echo %animationBaselineName%-1.ext
- echo %animationBaselineName%-2.ext
- echo [...]
- echo.
- echo This script was initially written to increase the animation length for skin animations within osu!
- echo As such, it will also look for and attempt to duplicate files with an "@2x" suffix.
- echo.
- echo.
- echo /f name Define the name to be used in the given file.
- echo Filename must be encapsulated in double-quotes if any non-alphanumeric characters are used
- echo eg: filename
- echo "%animationBaselineName%"
- echo.
- if "%filetype:~0,1%"=="." set filetype=%filetype:~1%
- echo /t type Define the filetype of each frame
- echo Filetype must be encapsulated in double-quotes if a leading period (.) is included
- echo eg: %filetype%
- echo ".%filetype%"
- echo.
- echo /d path Define the full path to your animation.
- echo eg: %pathToAnimation%
- echo.
- echo /n int Define the initial count of frames, where the count starts at zero (0)
- echo.
- echo /p int Define the number of offset for padding.
- echo If you want duplicate each frame once, your offset will be 2.
- echo eg: in = 10 (frame-0 to frame-9)
- echo out = 20 (frame-0 to frame-19)
- echo p = 2
- echo.
- echo /h? Display this help information
- goto :eof
Advertisement
Add Comment
Please, Sign In to add comment