ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
SergaliciousAnimation.h
Go to the documentation of this file.
1#pragma once
2
3#include "../Animation.h"
4#include "../AnimationTracks/BlinkTrack.h"
5#include "../KeyFrameTrack.h"
6#include "../EasyEaseAnimator.h"
7#include "../../Objects/Background.h"
8#include "../../Objects/LEDStripBackground.h"
9#include "../../Morph/Commissions/SergaliciousFace.h"
10#include "../../Render/Scene.h"
11#include "../../Menu/SingleButtonMenu.h"
12#include "../../Signals/FunctionGenerator.h"
13#include "../../Signals/FFTVoiceDetection.h"
14#include "../../Sensors/APDS9960.h"
15#include "../../Sensors/MicrophoneFourier_DMA.h"
16#include "../../Render/ObjectAlign.h"
17
18#include "../../Materials/Animated/RainbowNoise.h"
19#include "../../Materials/Animated/RainbowSpiral.h"
20#include "../../Materials/Animated/SpectrumAnalyzer.h"
21#include "../../Materials/Animated/AudioReactiveGradient.h"
22#include "../../Materials/Animated/Oscilloscope.h"
23#include "../../Materials/MaterialAnimator.h"
24
25
26
27class SergaliciousAnimation : public Animation<4> {
28private:
29 SergaliciousFace pM;
30 Background background;
31 LEDStripBackground ledStripBackground;
32 EasyEaseAnimator<30> eEA = EasyEaseAnimator<30>(EasyEaseInterpolation::Overshoot, 1.0f, 0.35f);
33
34 //Materials
44
45 RGBColor gradientSpectrum[2] = {RGBColor(20, 69, 252), RGBColor(34, 243, 254)};
47
50
51 SpectrumAnalyzer sA = SpectrumAnalyzer(Vector2D(200, 100), Vector2D(100, 50), true, true);
54
55 //Animation controllers
58
65
69
73
75
77
79
80 ObjectAlign objA = ObjectAlign(Vector2D(0.0f, 0.0f), Vector2D(189.0f, 93.0f), Quaternion());
81
82 float offsetFace = 0.0f;
83 float offsetFaceSA = 0.0f;
84 float offsetFaceARG = 0.0f;
85 float offsetFaceOSC = 0.0f;
86 float backgroundBSOD = 0.0f;
87 uint8_t offsetFaceInd = 50;
88 uint8_t offsetFaceIndSA = 51;
89 uint8_t offsetFaceIndARG = 52;
90 uint8_t offsetFaceIndOSC = 53;
91 uint8_t backgroundBSODInd = 54;
92
94 eEA.AddParameter(pM.GetMorphWeightReference(SergaliciousFace::Happy), SergaliciousFace::Happy, 30, 0.0f, 1.0f);
95 eEA.AddParameter(pM.GetMorphWeightReference(SergaliciousFace::Idle), SergaliciousFace::Idle, 10, 0.0f, 1.0f);
96 eEA.AddParameter(pM.GetMorphWeightReference(SergaliciousFace::OwO), SergaliciousFace::OwO, 20, 0.0f, 1.0f);
97 eEA.AddParameter(pM.GetMorphWeightReference(SergaliciousFace::Squint), SergaliciousFace::Squint, 20, 0.0f, 1.0f);
98 eEA.AddParameter(pM.GetMorphWeightReference(SergaliciousFace::Loading), SergaliciousFace::Loading, 30, 0.0f, 1.0f);
99 eEA.AddParameter(pM.GetMorphWeightReference(SergaliciousFace::LoadMove), SergaliciousFace::LoadMove, 20, 0.0f, 1.0f);
100 eEA.AddParameter(pM.GetMorphWeightReference(SergaliciousFace::Sad), SergaliciousFace::Sad, 45, 0.0f, 1.0f);
101 eEA.AddParameter(pM.GetMorphWeightReference(SergaliciousFace::Heart), SergaliciousFace::Heart, 20, 0.0f, 1.0f);
102 eEA.AddParameter(pM.GetMorphWeightReference(SergaliciousFace::Question), SergaliciousFace::Question, 20, 0.0f, 1.0f);
103 eEA.AddParameter(pM.GetMorphWeightReference(SergaliciousFace::BSOD), SergaliciousFace::BSOD, 15, 0.0f, 1.0f);
104
105 eEA.AddParameter(pM.GetMorphWeightReference(SergaliciousFace::vrc_v_aa), SergaliciousFace::vrc_v_aa, 2, 0.0f, 1.0f);
106 eEA.AddParameter(pM.GetMorphWeightReference(SergaliciousFace::vrc_v_ee), SergaliciousFace::vrc_v_ee, 2, 0.0f, 1.0f);
107 eEA.AddParameter(pM.GetMorphWeightReference(SergaliciousFace::vrc_v_oo), SergaliciousFace::vrc_v_oo, 2, 0.0f, 1.0f);
108
109 eEA.AddParameter(&offsetFace, offsetFaceInd, 40, 0.0f, 1.0f);
110 eEA.AddParameter(&offsetFaceSA, offsetFaceIndSA, 40, 0.0f, 1.0f);
114 }
115
117 blink.AddParameter(pM.GetMorphWeightReference(SergaliciousFace::Blink));
118 blinkIdle.AddParameter(pM.GetMorphWeightReference(SergaliciousFace::BlinkIdle));
119 }
120
122 eEA.SetInterpolationMethod(SergaliciousFace::vrc_v_aa, EasyEaseInterpolation::Linear);
123 eEA.SetInterpolationMethod(SergaliciousFace::vrc_v_ee, EasyEaseInterpolation::Linear);
124 eEA.SetInterpolationMethod(SergaliciousFace::vrc_v_oo, EasyEaseInterpolation::Linear);
125
126 eEA.SetInterpolationMethod(SergaliciousFace::LoadMove, EasyEaseInterpolation::Cosine);
127 eEA.SetInterpolationMethod(SergaliciousFace::Sad, EasyEaseInterpolation::Cosine);
128 eEA.SetInterpolationMethod(SergaliciousFace::BSOD, EasyEaseInterpolation::Cosine);
129 }
130
149
151 blink.Update();
153 }
154
155 void Default(){//Default mouth
156 blink.Play();
158 }
159
160 void Happy(){
161 eEA.AddParameterFrame(SergaliciousFace::Happy, 1.0f);
162 blink.Pause();
164 }
165
166 void Idle(){
167 eEA.AddParameterFrame(SergaliciousFace::Idle, 1.0f);
168 blink.Pause();
169 blinkIdle.Play();
170 }
171
172 void OwO(){
173 eEA.AddParameterFrame(SergaliciousFace::OwO, 1.0f);
174 blink.Pause();
176 }
177
178 void Squint(){
179 eEA.AddParameterFrame(SergaliciousFace::Squint, 1.0f);
180 blink.Pause();
182 }
183
193
194 void Loading(){
195 eEA.AddParameterFrame(SergaliciousFace::Loading, 1.0f);
197 eEA.AddParameterFrame(SergaliciousFace::LoadMove, fGenLoadingRamp.Update());
198
199 blink.Pause();
201 }
202
203 void Sad(){
204 eEA.AddParameterFrame(SergaliciousFace::Sad, 1.0f);
205 blink.Play();
207 }
208
209 void Heart(){
210 eEA.AddParameterFrame(SergaliciousFace::Heart, 1.0f);
211 blink.Pause();
213 }
214
215 void Question(){
216 eEA.AddParameterFrame(SergaliciousFace::Question, 1.0f);
217 blink.Pause();
219 }
220
228
236
244
247 eEA.AddParameterFrame(SergaliciousFace::vrc_v_aa, MicrophoneFourier::GetCurrentMagnitude() / 2.0f);
248
251
252 eEA.AddParameterFrame(SergaliciousFace::vrc_v_ee, voiceDetection.GetViseme(voiceDetection.EE));
253 //eEA.AddParameterFrame(SergaliciousFace::vrc_v_oo, voiceDetection.GetViseme(voiceDetection.AH));
254 //eEA.AddParameterFrame(SergaliciousFace::vrc_v_oo, voiceDetection.GetViseme(voiceDetection.UH));
255 //eEA.AddParameterFrame(SergaliciousFace::vrc_v_aa, voiceDetection.GetViseme(voiceDetection.AR));
256 //eEA.AddParameterFrame(SergaliciousFace::vrc_v_oo, voiceDetection.GetViseme(voiceDetection.ER));
257 //eEA.AddParameterFrame(SergaliciousFace::vrc_v_aa, voiceDetection.GetViseme(voiceDetection.AH));
258 eEA.AddParameterFrame(SergaliciousFace::vrc_v_oo, voiceDetection.GetViseme(voiceDetection.OO));
259 }
260 }
261 }
262
264 switch(Menu::GetFaceColor()){
265 case 1: materialAnimator.AddMaterialFrame(redMaterial, 0.8f); break;
267 case 3: materialAnimator.AddMaterialFrame(whiteMaterial, 0.8f); break;
268 case 4: materialAnimator.AddMaterialFrame(greenMaterial, 0.8f); break;
269 case 5: materialAnimator.AddMaterialFrame(blueMaterial, 0.8f); break;
272 case 8: materialAnimator.AddMaterialFrame(rainbowSpiral, 0.8f); break;
273 case 9: materialAnimator.AddMaterialFrame(rainbowNoise, 0.8f); break;
274 default: break;
275 }
276 }
277
278public:
280 scene.AddObject(pM.GetObject());
281 scene.AddObject(background.GetObject());
282 scene.AddObject(ledStripBackground.GetObject());
283
284 LinkEasyEase();
286
288
290
291 pM.GetObject()->SetMaterial(&materialAnimator);
292 background.GetObject()->SetMaterial(&backgroundMaterial);
293 ledStripBackground.GetObject()->SetMaterial(&materialAnimator);
294
295 boop.Initialize(5);
296
297 MicrophoneFourier::Initialize(15, 8000, 50.0f, 120.0f);//8KHz sample rate, 50dB min, 120dB max
298 Menu::Initialize(11, 20, 500);//13 is number of faces
299
301
303 objA.SetMirrorX(true);
304 //objA.SetMirrorY(true);
305 }
306
309 };
310
311 uint8_t GetBrightness(){
312 return Menu::GetBrightness();
313 };
314
315 void FadeIn(float stepRatio) override {}
316 void FadeOut(float stepRatio) override {}
317
319 return pM.GetObject();
320 }
321
322 void Update(float ratio) override {
323 pM.Reset();
324
325 float xOffset = fGenMatXMove.Update();
326 float yOffset = fGenMatYMove.Update();
327
328 Menu::Update(ratio);
329
331
332 bool isBooped = Menu::UseBoopSensor() ? boop.isBooped() : 0;
333 uint8_t mode = Menu::GetFaceState();//change by button press
334
336 sA.SetHueAngle(ratio * 360.0f * 4.0f);
339
340 aRG.SetRadius((xOffset + 2.0f) * 2.0f + 25.0f);
341 aRG.SetSize(Vector2D((xOffset + 2.0f) * 10.0f + 50.0f, (xOffset + 2.0f) * 10.0f + 50.0f));
342 aRG.SetHueAngle(ratio * 360.0f * 8.0f);
343 aRG.SetRotation(ratio * 360.0f * 2.0f);
344 aRG.SetPosition(Vector2D(80.0f + xOffset * 4.0f, 48.0f + yOffset * 4.0f));
345
346 oSC.SetSize(Vector2D(200.0f, 100.0f));
347 oSC.SetHueAngle(ratio * 360.0f * 8.0f);
348 oSC.SetPosition(Vector2D(100.0f, 50.0f));
349
350 voiceDetection.SetThreshold(map(Menu::GetMicLevel(), 0, 10, 1000, 50));
351
353
354 if (isBooped){
355 Squint();
356 }
357 else{
358 if (mode == 0) Default();
359 else if (mode == 1) Happy();
360 else if (mode == 2) Idle();
361 else if (mode == 3) OwO();
362 else if (mode == 4) BSOD();
363 else if (mode == 5) Loading();
364 else if (mode == 6) Heart();
365 else if (mode == 7) Question();
366 else if (mode == 8) {
369 }
370 else if (mode == 9){
373 }
374 else {
377 }
378 }
379
381
382 eEA.Update();
383 pM.Update();
384
385 float menuRatio = Menu::ShowMenu();
386
387 rainbowNoise.Update(ratio);
388 rainbowSpiral.Update(ratio);
391
392 uint8_t faceSize = Menu::GetFaceSize();
393
394 float scale = menuRatio * 0.6f + 0.4f;
395 float faceSizeOffset = faceSize * 8.0f;
396
397 //objA.SetPlaneOffsetAngle(360.0f * ratio);
398 objA.SetEdgeMargin(2.0f);
399 objA.SetCameraMax(Vector2D(110.0f + faceSizeOffset, 93.0f).Multiply(scale));
400
401 objA.AlignObjects(scene.GetObjects(), 1);
402
403 pM.GetObject()->GetTransform()->SetPosition(Vector3D(xOffset, yOffset - 110.0f * offsetFace, 0.0f));
404 pM.GetObject()->UpdateTransform();
405 }
406};
A class for managing the Adafruit APDS9960 sensor.
Definition APDS9960.h:27
static bool Initialize(uint8_t threshold)
Initializes the APDS9960 sensor.
Definition APDS9960.cpp:14
static bool isBooped()
Checks if the sensor is "booped" (close proximity detected).
Definition APDS9960.cpp:43
void AddParameter(float *parameter)
Adds a parameter to the animation track.
void Play()
Starts or resumes playback of the animation track.
void Pause()
Pauses playback of the animation track.
float Update()
Updates the animation track and returns the current parameter value.
A material class for creating an audio-reactive gradient effect.
void SetRadius(float radius)
Sets the radius for circular gradient patterns.
void SetPosition(Vector2D offset)
Sets the position of the gradient.
void Update(float *readData)
Updates the gradient based on new audio data.
void SetSize(Vector2D size)
Sets the size of the gradient.
void SetRotation(float angle)
Sets the rotation angle of the gradient.
void SetHueAngle(float hueAngle)
Sets the hue angle for color adjustments.
A template class for animating eye blinking using keyframes.
Definition BlinkTrack.h:27
A template class for implementing advanced animation easing.
void AddParameterFrame(uint16_t dictionaryValue, float value) override
Adds a single frame value for a parameter.
void Update() override
Updates the animator, advancing all animations.
void SetInterpolationMethod(uint16_t dictionaryValue, InterpolationMethod interpMethod) override
Sets the interpolation method for a specific parameter.
void AddParameter(float *parameter, uint16_t dictionaryValue, uint16_t frames, float basis, float goal) override
Adds a parameter to the animator.
Detects visemes based on FFT voice analysis.
float GetViseme(MouthShape viseme)
Retrieves the probability of a specific viseme.
void SetThreshold(float threshold)
Sets the threshold for formant calculations.
void Update(float *peaks, float maxFrequency)
Updates the viseme probabilities based on new FFT data.
A class to generate various waveform functions with customizable parameters.
@ Sine
Sine waveform.
@ Triangle
Triangle waveform.
float Update()
Updates and calculates the next value of the waveform.
Creates a customizable gradient material for rendering.
void SetRotationAngle(float rotationAngle)
Sets the rotation angle for the gradient.
Animates transitions and blends between multiple materials.
void AddMaterial(Material::Method method, Material *material, uint16_t frames, float minOpacity, float maxOpacity)
Adds a material to the animation with specified properties.
void SetBaseMaterial(Material::Method method, Material *material)
Sets the base material for the animation.
void AddMaterialFrame(Material &material, float opacity)
Adds a specific frame for a material in the animation.
void Update()
Updates the animator, advancing the transitions.
@ Lighten
Chooses the lighter color.
Definition Material.h:40
@ Add
Adds colors together.
Definition Material.h:35
@ Replace
Replaces the base color.
Definition Material.h:44
static uint8_t GetFaceState()
Retrieves the current face state. In hardware mode, it is read from the MenuHandler.
Definition Menu.cpp:381
static uint8_t GetFaceColor()
Gets the current face color index.
Definition Menu.cpp:453
static uint8_t GetMicLevel()
Gets the current microphone level.
Definition Menu.cpp:417
static float ShowMenu()
Returns how much of the menu is shown, typically normalized (0.0 to 1.0).
Definition Menu.cpp:494
static Material * GetMaterial()
Provides a pointer to the material used for rendering the menu text.
Definition Menu.cpp:155
static uint8_t MirrorSpectrumAnalyzer()
Checks if the spectrum analyzer mirroring is toggled on or off.
Definition Menu.cpp:435
static uint8_t GetFaceSize()
Gets the current face size.
Definition Menu.cpp:444
static void Initialize(uint8_t faceCount, uint8_t pin, uint16_t holdingTime, Vector2D size=Vector2D(240, 50))
Initializes the Menu using a face count, input pin, holding time, and size.
Definition Menu.cpp:102
static uint8_t UseMicrophone()
Checks if the microphone usage is toggled on or off.
Definition Menu.cpp:408
static uint8_t UseBoopSensor()
Checks if the boop sensor usage is toggled on or off.
Definition Menu.cpp:426
static void Update(float ratio)
Updates the menu each frame, handling transitions, wiggle effects, and text generation.
Definition Menu.cpp:208
static uint8_t GetBrightness()
Gets the current brightness level. In hardware mode, it is read from the MenuHandler.
Definition Menu.cpp:390
static uint8_t GetAccentBrightness()
Gets the current accent brightness level.
Definition Menu.cpp:399
static float GetCurrentMagnitude()
Retrieves the current signal magnitude.
static float GetSampleRate()
Retrieves the current sampling rate.
static float * GetSamples()
Retrieves the raw input samples.
static float * GetFourierFiltered()
Retrieves the filtered FFT output data.
static void Initialize(uint8_t pin, uint32_t sampleRate, float minDB, float maxDB)
Initializes the microphone and FFT system with basic parameters.
static void Update()
Updates the microphone system, processing new samples and performing FFT.
Represents a 3D object with geometry, material, and transformation data.
Definition Object3D.h:28
Handles aligning and transforming 3D objects to fit within specified 2D camera bounds.
Definition ObjectAlign.h:24
void SetEdgeMargin(float edgeMargin)
Sets the margin to keep from the edges when aligning objects.
@ Stretch
Attempt to scale the object(s) to fill the entire area.
Definition ObjectAlign.h:43
void SetJustification(Justification jst)
Sets the justification mode for alignment.
void SetCameraMax(Vector2D camMax)
Updates the maximum bounds for the 2D camera region.
void AlignObjects(Object3D **objs, uint8_t numObjects)
Aligns multiple objects within the camera bounds, including scale factors.
void SetMirrorX(bool mirrorX)
Enables or disables mirroring along the X-axis for the aligned objects.
A dynamic oscilloscope material for visualizing audio signals.
void SetPosition(Vector2D offset)
Sets the position of the oscilloscope visualization.
void SetSize(Vector2D size)
Sets the size of the oscilloscope visualization.
void Update(float *data)
Updates the oscilloscope visualization based on new audio data.
void SetHueAngle(float hueAngle)
Sets the hue angle for color adjustments.
A mathematical construct representing a rotation in 3D space.
Definition Quaternion.h:30
Represents an RGB color and provides methods for manipulation.
Definition RGBColor.h:23
A dynamic material that creates a rainbow effect using simplex noise.
void Update(float ratio)
Updates the material animation based on the time ratio.
A dynamic material creating a colorful rainbow spiral animation.
void Update(float ratio)
Updates the material animation based on the time ratio.
FunctionGenerator fGenMatYMove
MaterialAnimator< 5 > backgroundMaterial
FunctionGenerator fGenMatS1Sleep
FunctionGenerator fGenMatRMenu
FunctionGenerator fGenMatM2Sleep
LEDStripBackground ledStripBackground
GradientMaterial< 2 > gradientMat
FunctionGenerator fGenMatM1Sleep
FunctionGenerator fGenRotation
EasyEaseAnimator< 30 > eEA
FunctionGenerator fGenMatXMenu
void FadeIn(float stepRatio) override
void FadeOut(float stepRatio) override
FunctionGenerator fGenMatYMenu
FunctionGenerator fGenMatXMove
MaterialAnimator< 10 > materialAnimator
void Update(float ratio) override
FFTVoiceDetection< 128 > voiceDetection
FunctionGenerator fGenLoadingRamp
AudioReactiveGradient aRG
A material that applies a single, solid RGB color to surfaces.
A material that visualizes audio data as a spectrum.
void SetMirrorYState(bool state)
Sets the mirroring state for the visualization.
void Update(float *readData)
Updates the spectrum visualization with new audio data.
void SetFlipYState(bool state)
Sets the flipping state for the visualization.
void SetHueAngle(float hueAngle)
Sets the hue adjustment angle for the spectrum colors.
Represents a 2D vector (X, Y) and provides methods for vector arithmetic.
Definition Vector2D.h:27
Represents a 3D vector (X, Y, Z) and provides methods for vector arithmetic.
Definition Vector3D.h:26
@ OO
Mouth shape corresponding to the "OO" sound.
@ EE
Mouth shape corresponding to the "EE" sound.