ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
NukudeFaceAnimation.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 "../Morph/NukudeFace.h"
7#include "../Render/Scene.h"
8#include "../Materials/GradientMaterial.h"
9#include "../Materials/SimplexNoise.h"
10#include "../Math/FunctionGenerator.h"
11#include "../Sensors/SerialSync.h"
12#include "../Sensors/MicrophoneSimple.h"
13#include "../Sensors/ButtonHandler.h"
14#include "../Materials/NormalMaterial.h"
15
16#include "Flash/ImageSequences/Rainbow.h"
17
18class NukudeFaceAnimation : public Animation{
19private:
20 NukudeFace pM;
22
23 RGBColor spectrum[4] = {RGBColor(0, 255, 0), RGBColor(255, 0, 0), RGBColor(0, 255, 0), RGBColor(0, 0, 255)};
26
28
30 RainbowSequence gif = RainbowSequence(Vector2D(200, 145), Vector2D(100, 70), 60);
31
34
37
39 bool talk = true;
40
42 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::Anger), NukudeFace::Anger, 40, 0.0f);
43 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::Sadness), NukudeFace::Sadness, 90, 0.0f);
44 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::Surprised), NukudeFace::Surprised, 30, 0.0f);
45 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::Doubt), NukudeFace::Doubt, 60, 0.0f);
46 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::Frown), NukudeFace::Frown, 90, 0.0f);
47 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::LookUp), NukudeFace::LookUp, 60, 0.0f);
48 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::LookDown), NukudeFace::LookDown, 60, 0.0f);
49 }
50
52 blink.AddParameter(pM.GetMorphWeightReference(NukudeFace::Blink));
53 mouth.AddParameter(pM.GetMorphWeightReference(NukudeFace::vrc_v_aa));
54 }
55
57 blink.AddKeyFrame(0.0f, 0.0f);
58 blink.AddKeyFrame(2.75f, 0.0f);
59 blink.AddKeyFrame(3.0f, 1.0f);
60 blink.AddKeyFrame(3.25f, 0.0f);
61 blink.AddKeyFrame(9.75f, 0.0f);
62 blink.AddKeyFrame(10.0f, 1.0f);
63 blink.AddKeyFrame(10.25f, 0.0f);
64 blink.AddKeyFrame(10.75f, 0.0f);
65 blink.AddKeyFrame(11.0f, 1.0f);
66 blink.AddKeyFrame(11.25f, 0.0f);
67 blink.AddKeyFrame(15.0f, 0.0f);
68 }
69
71 mouth.AddKeyFrame(0.0f, 0.0f);
72 mouth.AddKeyFrame(1.5f, 1.0f);
73 mouth.AddKeyFrame(4.0f, 0.0f);
74 }
75
76public:
77 NukudeFaceAnimation() : Animation(1) {
78 scene->AddObject(pM.GetObject());
79
82
85
86 pM.GetObject()->SetMaterial(&gif);
87
90 }
91
93 blink.Update();
94 mouth.Update();
95 }
96
97 void Default(){
98 pM.Reset();
99 blink.Play();
100 mouth.Play();
101
102 talk = true;
103 }
104
105 void Angry(){
106 pM.Reset();
107 blink.Play();
108 mouth.Play();
109
110 eEA.AddParameterFrame(NukudeFace::Anger, 1.0f);
111
112 talk = true;
113 }
114
115 void Sad(){
116 pM.Reset();
117 blink.Play();
118 mouth.Play();
119
120 eEA.AddParameterFrame(NukudeFace::Sadness, 1.0f);
121
122 talk = true;
123 }
124
125 void Surprised(){
126 pM.Reset();
127 blink.Play();
128 mouth.Play();
129
130 eEA.AddParameterFrame(NukudeFace::Surprised, 1.0f);
131
132 talk = true;
133 }
134
135 void Doubt(){
136 pM.Reset();
137 blink.Play();
138 mouth.Play();
139
140 eEA.AddParameterFrame(NukudeFace::Doubt, 1.0f);
141
142 talk = true;
143 }
144
145 void Frown(){
146 pM.Reset();
147 blink.Play();
148 mouth.Play();
149
150 eEA.AddParameterFrame(NukudeFace::Frown, 1.0f);
151
152 talk = true;
153 }
154
155 void LookUp(){
156 pM.Reset();
157 blink.Play();
158 mouth.Play();
159
160 eEA.AddParameterFrame(NukudeFace::LookUp, 1.0f);
161
162 talk = true;
163 }
164
165 void LookDown(){
166 pM.Reset();
167 blink.Play();
168 mouth.Play();
169
170 eEA.AddParameterFrame(NukudeFace::LookDown, 1.0f);
171
172 talk = true;
173 }
174
175 void FadeIn(float stepRatio) override {}
176 void FadeOut(float stepRatio) override {}
177
179 return pM.GetObject();
180 }
181
182 float offset = 0.0f;
183
184
185 void Update(float ratio) override {
186 pM.GetObject()->Enable();//Due to Spyro track
187
188 #ifndef RIGHTFACE
190
191 //update offset only 2% of the time
192 if(SerialSync::GetRatio() < 0.02f){
193 if(ratio > SerialSync::GetRatio()) offset = ratio - 1.0f - SerialSync::GetRatio();
194 else offset = ratio - SerialSync::GetRatio();
195 }
196
197 //adjust current frame sync to new esp32
198 ratio = fmod(ratio - offset, 1.0f);//override input to synchronize from esp
199
200 uint8_t mode = SerialSync::GetMode();
201 float mouthMove = SerialSync::GetMouthMove();
202 #else
203 float mouthMove = mic.Update();
204 uint8_t mode = (uint8_t)(ratio * 8.0f);//ButtonHandler::GetValue();
205 SerialSync::SetMouthMove(mouthMove);
209 #endif
210
211 if (mode == 0) Angry();
212 else if (mode == 1) Sad();
213 else if (mode == 2) Surprised();
214 else if (mode == 3) Doubt();
215 else if (mode == 4) Frown();
216 else if (mode == 5) LookUp();
217 else if (mode == 6) LookDown();
218 else Default();
219
221
222 if(talk) pM.SetMorphWeight(NukudeFace::vrc_v_aa, mouthMove);
223 eEA.Update();
224 pM.Update();
225
226 float x = sinf(ratio * 3.14159f / 180.0f * 360.0f * 2.0f) * 3.0f;
227 float y = cosf(ratio * 3.14159f / 180.0f * 360.0f * 3.0f) * 3.0f;
228
229 float linSweep = ratio > 0.5f ? 1.0f - ratio : ratio;
230 float sShift = linSweep * 0.002f + 0.005f;
231
232 gNoiseMat.SetGradientPeriod(0.5f + linSweep * 6.0f);
233 gNoiseMat.HueShift(ratio * 360 * 2);
234 sNoise.SetScale(Vector3D(sShift, sShift, sShift));
235 sNoise.SetZPosition(x * 4.0f);
236
237 float shift = fGenMatPos.Update();
238
239 gif.SetPosition(Vector2D(20.0f + shift, 135.0f + shift));
240 gif.SetSize(Vector2D(-440, 350));
241 gif.SetRotation(15.0f);
242 gif.Update();
243
244 pM.GetObject()->GetTransform()->SetRotation(Vector3D(0.0f, 0.0f, 0.0f));
245 pM.GetObject()->GetTransform()->SetPosition(Vector3D(x + 72.5f, y - 22.5f, 600.0f));
246 pM.GetObject()->GetTransform()->Scale(Vector3D(1.0f, 1.0f, 1.0f));
247
248 pM.GetObject()->UpdateTransform();
249 }
250};
Declares the EasyEaseAnimator template class for advanced animation easing.
Declares the KeyFrameTrack template class for managing keyframe-based animations.
static void Initialize(uint8_t pin, uint8_t maxValue, uint16_t holdingToggle)
Initializes the ButtonHandler with specified parameters.
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 AddParameter(float *parameter, uint16_t dictionaryValue, uint16_t frames, float basis, float goal) override
Adds a parameter to the animator.
A class to generate various waveform functions with customizable parameters.
@ Sine
Sine 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.
void SetGradientPeriod(float gradientPeriod)
Sets the gradient's period of repetition.
@ Cosine
Smooth cosine interpolation.
@ Cosine
Smooth cosine interpolation.
A template class for managing animations with multiple parameters and keyframes.
void AddParameter(float *parameter)
Adds a parameter to the track.
void Play()
Resumes the animation.
void AddKeyFrame(float time, float value)
Adds a keyframe to the track.
float Update()
Updates the animation track and computes the new parameter value.
A simple class for processing microphone signals.
float Update()
Updates the microphone reading and processes the signal.
A material that visualizes surface normals as RGB colors.
NormalMaterial normalMaterial
FunctionGenerator fGenMatPos
FunctionGenerator fGenScale
FunctionGenerator fGenRotation
void FadeIn(float stepRatio) override
void FadeOut(float stepRatio) override
void Update(float ratio) override
GradientMaterial gNoiseMat
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
static void SetMouthMove(float ratio)
static void SetMode(uint8_t mode)
static uint8_t GetMode()
static void SetRatio(float ratio)
static void Send()
static void Initialize()
Definition SerialSync.cpp:6
static float GetRatio()
static void Read()
static float GetMouthMove()
A material class for rendering Simplex Noise.
void SetScale(Vector3D noiseScale)
Sets the scale for noise generation.
void SetZPosition(float zPosition)
Sets the Z-position for 3D noise generation.
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