ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
ArtleckAnimationV2.h
Go to the documentation of this file.
1#pragma once
2
3#include "../Animation.h"
4#include "../KeyFrameTrack.h"
5#include "../EasyEaseAnimator.h"
6#include "../../Objects/Background.h"
7#include "../../Morph/ArtleckFace.h"
8#include "../../Render/Scene.h"
9#include "../../Signals/FunctionGenerator.h"
10#include "../../Sensors/MenuButtonHandler.h"
11#include "../../Sensors/BoopSensor.h"
12
13#include "../../Materials/Animated/SpectrumAnalyzer.h"
14#include "../../Materials/Animated/RainbowNoise.h"
15#include "../../Materials/Animated/RainbowSpiral.h"
16
17#include "../../Materials/CombineMaterial.h"
18
19#include "../AnimationTracks/BlinkTrack.h"
20
21#include "../../Signals/FFTVoiceDetection.h"
22
23class ArtleckAnimationV2 : public Animation<2> {
24private:
25 ArtleckFace pM;
26 Background background;
27 EasyEaseAnimator<20> eEA = EasyEaseAnimator<20>(EasyEaseInterpolation::Overshoot, 1.0f, 0.35f);
28
29 //Materials
35
36 RGBColor gradientSpectrum[2] = {RGBColor(255, 255, 0), RGBColor(255, 128, 0)};
38
40
41 SpectrumAnalyzer sA = SpectrumAnalyzer(A0, Vector2D(200, 100), Vector2D(100, 50), true, true);
42
43 //Animation controllers
45
52
53 BoopSensor boop;
54 float rainbowFaceMix = 0.0f;
55 float angryFaceMix = 0.0f;
56 float sadFaceMix = 0.0f;
57 float purpleFaceMix = 0.0f;
58 uint8_t rainbowFaceIndex = 50;
59 uint8_t angryFaceIndex = 51;
60 uint8_t sadFaceIndex = 52;
61 uint8_t purpleFaceIndex = 53;
62
64
66 eEA.AddParameter(pM.GetMorphWeightReference(ArtleckFace::Anger), ArtleckFace::Anger, 60, 0.0f, 1.0f);
67 eEA.AddParameter(pM.GetMorphWeightReference(ArtleckFace::Sadness), ArtleckFace::Sadness, 60, 0.0f, 1.0f);
68 eEA.AddParameter(pM.GetMorphWeightReference(ArtleckFace::Surprised), ArtleckFace::Surprised, 60, 0.0f, 1.0f);
69 eEA.AddParameter(pM.GetMorphWeightReference(ArtleckFace::Doubt), ArtleckFace::Doubt, 60, 0.0f, 1.0f);
70 eEA.AddParameter(pM.GetMorphWeightReference(ArtleckFace::Frown), ArtleckFace::Frown, 60, 0.0f, 1.0f);
71 eEA.AddParameter(pM.GetMorphWeightReference(ArtleckFace::LookUp), ArtleckFace::LookUp, 60, 0.0f, 1.0f);
72 eEA.AddParameter(pM.GetMorphWeightReference(ArtleckFace::LookDown), ArtleckFace::LookDown, 60, 0.0f, 1.0f);
73
74 eEA.AddParameter(pM.GetMorphWeightReference(ArtleckFace::vrc_v_ee), ArtleckFace::vrc_v_ee, 2, 0.0f, 1.0f);
75 eEA.AddParameter(pM.GetMorphWeightReference(ArtleckFace::vrc_v_ih), ArtleckFace::vrc_v_ih, 2, 0.0f, 1.0f);
76 eEA.AddParameter(pM.GetMorphWeightReference(ArtleckFace::vrc_v_dd), ArtleckFace::vrc_v_dd, 2, 0.0f, 1.0f);
77 eEA.AddParameter(pM.GetMorphWeightReference(ArtleckFace::vrc_v_rr), ArtleckFace::vrc_v_rr, 2, 0.0f, 1.0f);
78 eEA.AddParameter(pM.GetMorphWeightReference(ArtleckFace::vrc_v_ch), ArtleckFace::vrc_v_ch, 2, 0.0f, 1.0f);
79 eEA.AddParameter(pM.GetMorphWeightReference(ArtleckFace::vrc_v_aa), ArtleckFace::vrc_v_aa, 2, 0.0f, 1.0f);
80 eEA.AddParameter(pM.GetMorphWeightReference(ArtleckFace::vrc_v_oh), ArtleckFace::vrc_v_oh, 2, 0.0f, 1.0f);
81 eEA.AddParameter(pM.GetMorphWeightReference(ArtleckFace::vrc_v_ss), ArtleckFace::vrc_v_ss, 2, 0.0f, 1.0f);
82
85 eEA.AddParameter(&sadFaceMix, sadFaceIndex, 40, 0.0f, 1.0f);
87 }
88
90 blink.AddParameter(pM.GetMorphWeightReference(ArtleckFace::Blink));
91 }
92
94 eEA.SetInterpolationMethod(ArtleckFace::Sadness, EasyEaseInterpolation::Cosine);
95 eEA.SetInterpolationMethod(rainbowFaceIndex, EasyEaseInterpolation::Cosine);
96 eEA.SetInterpolationMethod(angryFaceIndex, EasyEaseInterpolation::Cosine);
97 eEA.SetInterpolationMethod(sadFaceIndex, EasyEaseInterpolation::Cosine);
98 eEA.SetInterpolationMethod(purpleFaceIndex, EasyEaseInterpolation::Cosine);
99
100 eEA.SetInterpolationMethod(ArtleckFace::vrc_v_ee, EasyEaseInterpolation::Linear);
101 eEA.SetInterpolationMethod(ArtleckFace::vrc_v_ih, EasyEaseInterpolation::Linear);
102 eEA.SetInterpolationMethod(ArtleckFace::vrc_v_dd, EasyEaseInterpolation::Linear);
103 eEA.SetInterpolationMethod(ArtleckFace::vrc_v_rr, EasyEaseInterpolation::Linear);
104 eEA.SetInterpolationMethod(ArtleckFace::vrc_v_ch, EasyEaseInterpolation::Linear);
105 eEA.SetInterpolationMethod(ArtleckFace::vrc_v_aa, EasyEaseInterpolation::Linear);
106 eEA.SetInterpolationMethod(ArtleckFace::vrc_v_oh, EasyEaseInterpolation::Linear);
107 eEA.SetInterpolationMethod(ArtleckFace::vrc_v_ss, EasyEaseInterpolation::Linear);
108 }
109
118
119public:
121 scene.AddObject(pM.GetObject());
122 scene.AddObject(background.GetObject());
123
124 LinkEasyEase();
126
128
129 SetMaterials();
130
131 pM.GetObject()->SetMaterial(&faceMaterial);
132
133 MenuButtonHandler::Initialize(20, 7, 500);//7 is number of faces
134 boop.Initialize(5);
135
136 background.GetObject()->SetMaterial(&sA);//sA);
137 }
138
140 blink.Update();
141 }
142
143 void Default(){}
144
145 void Angry(){
146 eEA.AddParameterFrame(ArtleckFace::Anger, 1.0f);
148 }
149
150 void Sad(){
151 eEA.AddParameterFrame(ArtleckFace::Sadness, 1.0f);
152 eEA.AddParameterFrame(ArtleckFace::Frown, 1.0f);
154 }
155
156 void Surprised(){
157 eEA.AddParameterFrame(ArtleckFace::Surprised, 1.0f);
159 }
160
161 void Doubt(){
162 eEA.AddParameterFrame(ArtleckFace::Doubt, 1.0f);
163 }
164
165 void Frown(){
166 eEA.AddParameterFrame(ArtleckFace::Frown, 1.0f);
167 }
168
169 void LookUp(){
170 eEA.AddParameterFrame(ArtleckFace::LookUp, 1.0f);
171 }
172
173 void LookDown(){
174 eEA.AddParameterFrame(ArtleckFace::LookDown, 1.0f);
175 }
176
178 pM.GetObject()->Disable();
179 background.GetObject()->Enable();
180 }
181
182 void FadeIn(float stepRatio) override {}
183 void FadeOut(float stepRatio) override {}
184
186 return pM.GetObject();
187 }
188
206
207 void Update(float ratio) override {
208 pM.Reset();
209 pM.GetObject()->Enable();
210 background.GetObject()->Disable();
211
212 bool isBooped = MenuButtonHandler::UseBoopSensor() ? boop.isBooped() : 0;
213 uint8_t mode = MenuButtonHandler::GetFaceState();//change by button press
214
217 sA.SetHueAngle(ratio * 360.0f * 4.0f);
218 sA.SetMirrorYState(MenuButtonHandler::MirrorSpectrumAnalyzer());
219 sA.SetFlipYState(!MenuButtonHandler::MirrorSpectrumAnalyzer());
220
222
223 if (isBooped && mode != 6){
224 Angry();
225 }
226 else{
227 if (mode == 0) Default();
228 else if (mode == 1) Surprised();
229 else if (mode == 2) Doubt();
230 else if (mode == 3) Frown();
231 else if (mode == 4) LookUp();
232 else if (mode == 5) Sad();
234 }
235
237
238 eEA.Update();
239 pM.Update();
240
241 rainbowNoise.Update(ratio);
242 rainbowSpiral.Update(ratio);
243
244 faceMaterial.SetOpacity(2, rainbowFaceMix);//set face to spiral
245 faceMaterial.SetOpacity(3, angryFaceMix);//set face to angry
246 faceMaterial.SetOpacity(4, sadFaceMix);//set face to sad
247 faceMaterial.SetOpacity(5, purpleFaceMix);//set face to purple
248
249 pM.GetObject()->GetTransform()->SetRotation(Vector3D(0.0f, 0.0f, -15.0f));
250 pM.GetObject()->GetTransform()->SetPosition(Vector3D(82.5f + fGenMatXMove.Update(), -25.0f + fGenMatYMove.Update(), 600.0f));
251 pM.GetObject()->GetTransform()->SetScale(Vector3D(-0.85f, 0.70f, 0.8f));
252
253 pM.GetObject()->UpdateTransform();
254 }
255};
void AddParameter(float *parameter)
Adds a parameter to the animation track.
float Update()
Updates the animation track and returns the current parameter value.
FunctionGenerator fGenMatHue
FunctionGenerator fGenMatYMove
CombineMaterial< 6 > faceMaterial
SpectrumAnalyzer sA
EasyEaseAnimator< 20 > eEA
SimpleMaterial redMaterial
RainbowSpiral rainbowSpiral
SimpleMaterial blueMaterial
BlinkTrack< 1 > blink
GradientMaterial< 2 > gradientMat
FunctionGenerator fGenMatPos
FunctionGenerator fGenScale
FunctionGenerator fGenRotation
void FadeIn(float stepRatio) override
void FadeOut(float stepRatio) override
FunctionGenerator fGenMatXMove
SimpleMaterial purpleMaterial
void Update(float ratio) override
FFTVoiceDetection< 128 > voiceDetection
A template class for animating eye blinking using keyframes.
Definition BlinkTrack.h:27
Combines multiple materials with specified blending methods and opacities.
void SetOpacity(uint8_t index, float opacity)
Sets the opacity for a specific material.
void AddMaterial(Method method, Material *material, float opacity)
Adds a new material to the combination.
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 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.
@ 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 float GetCurrentMagnitude()
Retrieves the current signal magnitude.
static float GetSampleRate()
Retrieves the current sampling rate.
static float * GetFourierFiltered()
Retrieves the filtered FFT output data.
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
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.
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
@ ER
Mouth shape corresponding to the "ER" sound.
@ OO
Mouth shape corresponding to the "OO" sound.
@ AH
Mouth shape corresponding to the "AH" sound.
@ UH
Mouth shape corresponding to the "UH" sound.
@ AR
Mouth shape corresponding to the "AR" sound.
@ EE
Mouth shape corresponding to the "EE" sound.