ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
ProtobottAnimation.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/NukudeFace.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 ProtobottAnimation : public Animation<2> {
24private:
25 NukudeFace pM;
26 Background background;
27 EasyEaseAnimator<20> eEA = EasyEaseAnimator<20>(EasyEaseInterpolation::Overshoot, 1.0f, 0.35f);
28
29 //Materials
34
35 RGBColor gradientSpectrum[2] = {RGBColor(255, 0, 0), RGBColor(255, 255, 0)};
37
39
40 SpectrumAnalyzer sA = SpectrumAnalyzer(A0, Vector2D(200, 100), Vector2D(100, 50), true, true);
41
42 //Animation controllers
44
51
52 BoopSensor boop;
53 float rainbowFaceMix = 0.0f;
54 float angryFaceMix = 0.0f;
55 float sadFaceMix = 0.0f;
56 uint8_t rainbowFaceIndex = 50;
57 uint8_t angryFaceIndex = 51;
58 uint8_t sadFaceIndex = 52;
59
61
63 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::Anger), NukudeFace::Anger, 60, 0.0f, 1.0f);
64 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::Sadness), NukudeFace::Sadness, 60, 0.0f, 1.0f);
65 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::Surprised), NukudeFace::Surprised, 60, 0.0f, 1.0f);
66 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::Doubt), NukudeFace::Doubt, 60, 0.0f, 1.0f);
67 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::Frown), NukudeFace::Frown, 60, 0.0f, 1.0f);
68 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::LookUp), NukudeFace::LookUp, 60, 0.0f, 1.0f);
69 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::LookDown), NukudeFace::LookDown, 60, 0.0f, 1.0f);
70
71 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::vrc_v_ee), NukudeFace::vrc_v_ee, 2, 0.0f, 1.0f);
72 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::vrc_v_ih), NukudeFace::vrc_v_ih, 2, 0.0f, 1.0f);
73 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::vrc_v_dd), NukudeFace::vrc_v_dd, 2, 0.0f, 1.0f);
74 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::vrc_v_rr), NukudeFace::vrc_v_rr, 2, 0.0f, 1.0f);
75 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::vrc_v_ch), NukudeFace::vrc_v_ch, 2, 0.0f, 1.0f);
76 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::vrc_v_aa), NukudeFace::vrc_v_aa, 2, 0.0f, 1.0f);
77 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::vrc_v_oh), NukudeFace::vrc_v_oh, 2, 0.0f, 1.0f);
78 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::vrc_v_ss), NukudeFace::vrc_v_ss, 2, 0.0f, 1.0f);
79
80 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::HideBlush), NukudeFace::HideBlush, 30, 1.0f, 0.0f);
81
84 eEA.AddParameter(&sadFaceMix, sadFaceIndex, 40, 0.0f, 1.0f);
85 }
86
88 blink.AddParameter(pM.GetMorphWeightReference(NukudeFace::Blink));
89 }
90
92 eEA.SetInterpolationMethod(NukudeFace::HideBlush, EasyEaseInterpolation::Cosine);
93 eEA.SetInterpolationMethod(NukudeFace::Sadness, EasyEaseInterpolation::Cosine);
94 eEA.SetInterpolationMethod(rainbowFaceIndex, EasyEaseInterpolation::Cosine);
95 eEA.SetInterpolationMethod(angryFaceIndex, EasyEaseInterpolation::Cosine);
96 eEA.SetInterpolationMethod(sadFaceIndex, EasyEaseInterpolation::Cosine);
97
98 eEA.SetInterpolationMethod(NukudeFace::vrc_v_ee, EasyEaseInterpolation::Linear);
99 eEA.SetInterpolationMethod(NukudeFace::vrc_v_ih, EasyEaseInterpolation::Linear);
100 eEA.SetInterpolationMethod(NukudeFace::vrc_v_dd, EasyEaseInterpolation::Linear);
101 eEA.SetInterpolationMethod(NukudeFace::vrc_v_rr, EasyEaseInterpolation::Linear);
102 eEA.SetInterpolationMethod(NukudeFace::vrc_v_ch, EasyEaseInterpolation::Linear);
103 eEA.SetInterpolationMethod(NukudeFace::vrc_v_aa, EasyEaseInterpolation::Linear);
104 eEA.SetInterpolationMethod(NukudeFace::vrc_v_oh, EasyEaseInterpolation::Linear);
105 eEA.SetInterpolationMethod(NukudeFace::vrc_v_ss, EasyEaseInterpolation::Linear);
106 }
107
115
116public:
118 scene.AddObject(pM.GetObject());
119 scene.AddObject(background.GetObject());
120
121 LinkEasyEase();
123
125
126 SetMaterials();
127
128 pM.GetObject()->SetMaterial(&faceMaterial);
129
130 MenuButtonHandler::Initialize(20, 7, 1000);//8 is number of faces
131 boop.Initialize(5);
132
133 background.GetObject()->SetMaterial(&sA);//sA);
134 }
135
137 blink.Update();
138 }
139
140 void Default(){}
141
142 void Angry(){
143 eEA.AddParameterFrame(NukudeFace::Anger, 1.0f);
145 }
146
147 void Sad(){
148 eEA.AddParameterFrame(NukudeFace::Sadness, 1.0f);
149 eEA.AddParameterFrame(NukudeFace::Frown, 1.0f);
151 }
152
153 void Surprised(){
154 eEA.AddParameterFrame(NukudeFace::Surprised, 1.0f);
155 eEA.AddParameterFrame(NukudeFace::HideBlush, 0.0f);
157 }
158
159 void Doubt(){
160 eEA.AddParameterFrame(NukudeFace::Doubt, 1.0f);
161 }
162
163 void Frown(){
164 eEA.AddParameterFrame(NukudeFace::Frown, 1.0f);
165 }
166
167 void LookUp(){
168 eEA.AddParameterFrame(NukudeFace::LookUp, 1.0f);
169 }
170
171 void LookDown(){
172 eEA.AddParameterFrame(NukudeFace::LookDown, 1.0f);
173 }
174
176 pM.GetObject()->Disable();
177 background.GetObject()->Enable();
178 }
179
180 void FadeIn(float stepRatio) override {}
181 void FadeOut(float stepRatio) override {}
182
184 return pM.GetObject();
185 }
186
204
205 void Update(float ratio) override {
206 pM.Reset();
207 pM.GetObject()->Enable();
208 background.GetObject()->Disable();
209
210 bool isBooped = MenuButtonHandler::UseBoopSensor() ? boop.isBooped() : 0;
211 uint8_t mode = MenuButtonHandler::GetFaceState();//change by button press
212
215 sA.SetHueAngle(ratio * 360.0f * 4.0f);
216 sA.SetMirrorYState(MenuButtonHandler::MirrorSpectrumAnalyzer());
217 sA.SetFlipYState(!MenuButtonHandler::MirrorSpectrumAnalyzer());
218
220
221 if (isBooped && mode != 6){
222 Surprised();
223 }
224 else{
225 if (mode == 0) Default();
226 else if (mode == 1) Angry();
227 else if (mode == 2) Doubt();
228 else if (mode == 3) Frown();
229 else if (mode == 4) LookUp();
230 else if (mode == 5) Sad();
232 }
233
235
236 pM.SetMorphWeight(NukudeFace::BiggerNose, 1.0f);
237 pM.SetMorphWeight(NukudeFace::MoveEye, 1.0f);
238
239 eEA.Update();
240 pM.Update();
241
242 rainbowNoise.Update(ratio);
243 rainbowSpiral.Update(ratio);
244
246
247 faceMaterial.SetOpacity(2, rainbowFaceMix);//set face to spiral
248 faceMaterial.SetOpacity(3, angryFaceMix);//set face to angry
249 faceMaterial.SetOpacity(4, sadFaceMix);//set face to sad
250
251 pM.GetObject()->GetTransform()->SetRotation(Vector3D(0.0f, 0.0f, -7.5f));
252 pM.GetObject()->GetTransform()->SetPosition(Vector3D(125.0f + fGenMatXMove.Update(), -22.5f + fGenMatYMove.Update(), 600.0f));
253 pM.GetObject()->GetTransform()->SetScale(Vector3D(-1.05f, 0.585f, 0.8f));
254
255 pM.GetObject()->UpdateTransform();
256 }
257};
void AddParameter(float *parameter)
Adds a parameter to the animation track.
float Update()
Updates the animation track and returns the current parameter value.
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.
void HueShift(float hueDeg)
Shifts the hue of the gradient by a specified degree.
@ 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
FunctionGenerator fGenMatHue
FunctionGenerator fGenMatYMove
SpectrumAnalyzer sA
EasyEaseAnimator< 20 > eEA
SimpleMaterial redMaterial
RainbowSpiral rainbowSpiral
SimpleMaterial blueMaterial
CombineMaterial< 5 > faceMaterial
BlinkTrack< 1 > blink
GradientMaterial< 2 > gradientMat
FunctionGenerator fGenMatPos
FunctionGenerator fGenScale
FunctionGenerator fGenRotation
void FadeIn(float stepRatio) override
void FadeOut(float stepRatio) override
FunctionGenerator fGenMatXMove
void Update(float ratio) override
FFTVoiceDetection< 128 > voiceDetection
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.