Skip to content

Adding GIF Materials

Coela Can't! edited this page Aug 20, 2021 · 2 revisions

Image Sequence Material

The Image Sequence material allows you to use a converted animated GIF as a material mapped with the frontal perspective to an Object3D instance. To create an Image Sequence material, open the ProtoTracerImageConverter project. Change the top lines of the python code to match your input file name, output file name, palettized picture output name, and class name:

inputFile = "Example Files\\Noise.gif"
outputFile = "Output\\Noise.h"
outputPic = "Output\\Pictures\\Noise"
name = "Noise"

Created Image Sequence Header

Running this Python code will create a file similar to the following which you can import and use as a material:

#pragma once

#include "..\..\Animation\ImageSequence.h"

class Rainbow2Sequence : public ImageSequence{
private:
	static const uint8_t frame0000[];
	static const uint8_t frame0001[];
	static const uint8_t frame0002[];
	static const uint8_t frame0003[];
	static const uint8_t frame0004[];
	static const uint8_t frame0005[];
	static const uint8_t frame0006[];
	static const uint8_t frame0007[];
	static const uint8_t frame0008[];
	static const uint8_t frame0009[];
	static const uint8_t frame0010[];
	static const uint8_t frame0011[];

	static const uint8_t* sequence[12];

	static const uint8_t rgbColors[];

	Image image = Image(frame0000, rgbColors, 12, 10, 256);

public:
	Rainbow2Sequence(Vector2D size, Vector2D offset, float fps) : ImageSequence(&image, sequence, (unsigned int)12, fps) {
		image.SetSize(size);
		image.SetPosition(offset);
	}
};

const uint8_t Rainbow2Sequence::frame0000[] PROGMEM = {...};
const uint8_t Rainbow2Sequence::frame0001[] PROGMEM = {...};
const uint8_t Rainbow2Sequence::frame0002[] PROGMEM = {...};
const uint8_t Rainbow2Sequence::frame0003[] PROGMEM = {...};
const uint8_t Rainbow2Sequence::frame0004[] PROGMEM = {...};
const uint8_t Rainbow2Sequence::frame0005[] PROGMEM = {...};
const uint8_t Rainbow2Sequence::frame0006[] PROGMEM = {...};
const uint8_t Rainbow2Sequence::frame0007[] PROGMEM = {...};
const uint8_t Rainbow2Sequence::frame0008[] PROGMEM = {...};
const uint8_t Rainbow2Sequence::frame0009[] PROGMEM = {...};
const uint8_t Rainbow2Sequence::frame0010[] PROGMEM = {...};
const uint8_t Rainbow2Sequence::frame0011[] PROGMEM = {...};

const uint8_t* Rainbow2Sequence::sequence[] = {frame0000,frame0001,frame0002,frame0003,frame0004,frame0005,frame0006,frame0007,frame0008,frame0009,frame0010,frame0011};
const uint8_t Rainbow2Sequence::rgbColors[] PROGMEM = {...};

Image Sequence Material Usage

The created C++ file can be included and instantiated. The default constructer takes two Vecto2D objects as parameters. The first specifies the XY size in millimeters, the second is the position offset from origin, the third is the frame rate in frames per second. The material can be applied to any number of objects and its parameters can be changed:

#include "Flash\ImageSequences\Rainbow2.h"

Rainbow2 gif = Rainbow2(Vector2D(200, 145), Vector2D(20, 40), 30);

object3D.SetMaterial(&gif);

gif.SetPosition(Vector2D(20.0f, 135.0f));
gif.SetSize(Vector2D(-200.0f, 200.0f));
gif.SetRotation(15.0f);
gif.SetHueAngle(90.0f);

gif.Update();