Jump to: Board index » General » Fusion

Macro for creating an animation from a sprite sheet

Learn about 3D compositing, animation, broadcast design and VFX workflows.
  • Author
  • Message
Offline

theflowstate

  • Posts: 5
  • Joined: Thu Jul 21, 2022 2:17 am
  • Real Name: Eric Hibbs

Macro for creating an animation from a sprite sheet

PostMon Mar 20, 2023 1:45 am

Hey y'all,

I'm trying to create a fusion macro / effect that operates on a sprite sheet and turns it into an animation.
I'm starting with this image:
Gruz Mother - Sleeping.png
The source sprite sheet
Gruz Mother - Sleeping.png (137.06 KiB) Viewed 948 times


And would like the following control interface:
Sprite Width (px): width of a single sprite
Sprite Height (px): height of a single sprite
Buffer (px): width buffer between sprites (seen in the example as blue lines)
Number of sprites in sheet
How many frames before moving to the next sprite
Animation style: Play Once, Loop, Ping-Pong

The desired output would be displaying each sprite in the sheet in sequence.

I've been a programmer for about 15 years so this feels like it should be an almost trivial problem to solve.

However, I'm really struggling with converting pixel measurements into expression values for Transforms, Masking Rectangles, etc.

As far as I can tell, the following math should work, but I have no idea where to get half these variable values.

Code: Select all
MaskWidth = SingleSpriteWidth / (FullImageWidth - (BufferWidth * (NumberSprites - 1))

Code: Select all
TransformCenterX = MaskWidth / (2 + (CurrentSpriteIndex * BufferWidth))


Second issue: I know I need a Loader, a Rect mask, and a Transform. However, given that the math changes drastically based on the configuration of the nodes, I can't figure out where the mask should go (should it mask the loader directly, or an Xf node with the loader as input).

Any help would be very much appreciated

Edit: Oh and I just had the thought - maybe I should be directly using the image as a mediaIn instead of a Loader?? I can't express how frustrating it is to have the entire algorithm in my head and be stuck on the most basic steps because there's no documentation available.
Offline

Sander de Regt

  • Posts: 3497
  • Joined: Thu Nov 13, 2014 10:09 pm

Re: Macro for creating an animation from a sprite sheet

PostMon Mar 20, 2023 1:24 pm

Definitely stick to loaders, they're way more flexible.

If you've been programming for as long as you have, you will be able to get the hang of it easily.

As for documentation, I'm not an expert or a coder and I have done a couple of macros already.
There is documentation for fuses, there is a scripting guide and if you join the forum over at www.steakunderwater.com there are a couple of dedicated fuse, macro and other programming related subsections that deal specfically with the kind of questions you're dealing with.

I don't know how sprite sheets work, but in your case I would probably use a crop tool instead of masks and transforms, since all sprites are the exact same size I suppose? Are they all aligned left to right or are ther multiple rows of sprites?

In your case you could have a very basic setup of what you're looking for (minus the loop/ping pong section) in less than 10 minutes without hardly having to do any *real* programming at all.
What are the pixel values and the buffer width of the image you provided?

Set the pixel values in the x/y size of a crop tool, add an integer slider to the tool to control the buffer width and one integerslder to switch between the images and then use an expression in the offset values of the crop tool that goes something like this (in pseudocode)

X-offset = ((size in x pixels+buffer size in pixesl)*imagenumberslider))

and then you can animate the imagenumber slider to control which image you're viewing.
It's almost faster to do then it is to type this out.
Sander de Regt

ShadowMaker SdR
The Netherlands
Offline

Sander de Regt

  • Posts: 3497
  • Joined: Thu Nov 13, 2014 10:09 pm

Re: Macro for creating an animation from a sprite sheet

PostMon Mar 20, 2023 2:27 pm

I don't know if this Fuse might already suit your needs. I haven't used it. Just searched for 'sprite sheet' on WSL

https://www.steakunderwater.com/wesuckl ... ite#p27654
Sander de Regt

ShadowMaker SdR
The Netherlands
Offline
User avatar

Bryan Ray

  • Posts: 2478
  • Joined: Mon Nov 28, 2016 5:32 am
  • Location: Los Angeles, CA, USA

Re: Macro for creating an animation from a sprite sheet

PostMon Mar 20, 2023 5:14 pm

I'd be delighted to know someone was actually using that thing! I made it as a bit of a lark. I just tested it on the provided strip, and it seems to need some improvements (which I do not have the time to make). I'm not at all sure what's going on, but adding any kind of transform or crop afterward really makes things screwy. I did a little cropping on the input to get the critter centered up, but trying to crop away the blue line afterward broke it.

And trying to Merge a black mask over the top also broke it. I did get a good result by using my mask to Gain it by 0, but then trying to Merge it over another image results in more nonsense. So I wouldn't say the tool is ready to go, alas.

Anybody who wants to take a crack at improving it is welcome to do so, of course!
Bryan Ray
http://www.bryanray.name
http://www.sidefx.com
Offline

Sander de Regt

  • Posts: 3497
  • Joined: Thu Nov 13, 2014 10:09 pm

Re: Macro for creating an animation from a sprite sheet

PostMon Mar 20, 2023 7:20 pm

I think that for a single left to right strip my macro suggestion would be a quick way to get started, but you should always listen to Bryan, because we all become wiser from doing so.
Sander de Regt

ShadowMaker SdR
The Netherlands
Offline
User avatar

Pieter Van Houte

  • Posts: 631
  • Joined: Wed Nov 05, 2014 1:04 am

Re: Macro for creating an animation from a sprite sheet

PostTue Mar 21, 2023 12:34 am

Sander de Regt wrote:you should always listen to Bryan, because we all become wiser from doing so.


That should be a console tip ;)
Support We Suck Less on Patreon -> https://www.patreon.com/wesuckless

https://www.steakunderwater.com/wesuckless
Offline
User avatar

Bryan Ray

  • Posts: 2478
  • Joined: Mon Nov 28, 2016 5:32 am
  • Location: Los Angeles, CA, USA

Re: Macro for creating an animation from a sprite sheet

PostTue Mar 21, 2023 12:44 am

lol. I hardly think so! Sanity check me the same way you would ChatGPT because sometimes I just make stuff up. :lol:
Bryan Ray
http://www.bryanray.name
http://www.sidefx.com

Return to Fusion

Who is online

Users browsing this forum: No registered users and 40 guests