ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
ArtleckAnimation.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/ProtoArtleckMorph.h"
7#include "../../Render/Scene.h"
8#include "../../Materials/GradientMaterial.h"
9#include "../../Materials/SimplexNoise.h"
10#include "../../Signals/FunctionGenerator.h"
11#include "../../Sensors/MicrophoneSimple_MAX9814.h"
12#include "../../Sensors/ButtonHandler.h"
13#include "../../Sensors/BoopSensor.h"
14#include "../../Materials/NormalMaterial.h"
15
16#include "../../Materials/CombineMaterial.h"
17
18
19class ProtogenArtleckAnimation : public Animation{
20private:
21 float colorMix;
22
23 ProtoArtleck pM;
24 EasyEaseAnimator<20> eEA = EasyEaseAnimator<20>(EasyEaseInterpolation::Overshoot, 1.0f, 0.5f);
25
26 RGBColor noiseSpectrum[4] = {RGBColor(0, 255, 0), RGBColor(255, 0, 0), RGBColor(0, 255, 0), RGBColor(0, 0, 255)};
29
30 RGBColor gradientSpectrum[2] = {RGBColor(255, 255, 0), RGBColor(255, 128, 0)};
32
34
35 //default face material with gradient + simplex noise
38
39 //for combining angry face with default material
42
43
46
50
52 BoopSensor boop;
53 bool talk = true;
54
56 eEA.AddParameter(pM.GetMorphWeightReference(ProtoArtleck::Anger), ProtoArtleck::Anger, 30, 0.0f, 1.0f);
57 eEA.AddParameter(pM.GetMorphWeightReference(ProtoArtleck::Sadness), ProtoArtleck::Sadness, 30, 0.0f, 1.0f);
58 eEA.AddParameter(pM.GetMorphWeightReference(ProtoArtleck::Surprised), ProtoArtleck::Surprised, 30, 0.0f, 1.0f);
59 eEA.AddParameter(pM.GetMorphWeightReference(ProtoArtleck::Doubt), ProtoArtleck::Doubt, 30, 0.0f, 1.0f);
60 eEA.AddParameter(pM.GetMorphWeightReference(ProtoArtleck::Frown), ProtoArtleck::Frown, 30, 0.0f, 1.0f);
61 eEA.AddParameter(pM.GetMorphWeightReference(ProtoArtleck::LookUp), ProtoArtleck::LookUp, 30, 0.0f, 1.0f);
62 eEA.AddParameter(pM.GetMorphWeightReference(ProtoArtleck::LookDown), ProtoArtleck::LookDown, 30, 0.0f, 1.0f);
63
64 eEA.AddParameter(pM.GetMorphWeightReference(ProtoArtleck::vrc_v_ou), ProtoArtleck::vrc_v_ou, 30, 0.0f, 1.0f);
65 eEA.AddParameter(pM.GetMorphWeightReference(ProtoArtleck::vrc_v_aa), ProtoArtleck::vrc_v_aa, 30, 0.0f, 1.0f);
66
67 eEA.AddParameter(&colorMix, 99, 90, 0.0f, 1.0f);
68 }
69
71 blink.AddParameter(pM.GetMorphWeightReference(ProtoArtleck::Blink));
72 mouth.AddParameter(pM.GetMorphWeightReference(ProtoArtleck::vrc_v_aa));
73 }
74
76 blink.AddKeyFrame(0.0f, 0.0f);
77 blink.AddKeyFrame(2.75f, 0.0f);
78 blink.AddKeyFrame(3.0f, 1.0f);
79 blink.AddKeyFrame(3.25f, 0.0f);
80 blink.AddKeyFrame(9.75f, 0.0f);
81 blink.AddKeyFrame(10.0f, 1.0f);
82 blink.AddKeyFrame(10.25f, 0.0f);
83 blink.AddKeyFrame(10.75f, 0.0f);
84 blink.AddKeyFrame(11.0f, 1.0f);
85 blink.AddKeyFrame(11.25f, 0.0f);
86 blink.AddKeyFrame(15.0f, 0.0f);
87 }
88
90 mouth.AddKeyFrame(0.0f, 0.0f);
91 mouth.AddKeyFrame(1.5f, 1.0f);
92 mouth.AddKeyFrame(4.0f, 0.0f);
93 }
94
96 eEA.SetInterpolationMethod(ProtoArtleck::Sadness, EasyEaseInterpolation::Cosine);
97 eEA.SetInterpolationMethod(ProtoArtleck::vrc_v_ou, EasyEaseInterpolation::Cosine);
98 eEA.SetInterpolationMethod(99, EasyEaseInterpolation::Cosine);
99 }
100
101public:
102 ProtogenArtleckAnimation() : Animation(1) {
103 scene->AddObject(pM.GetObject());
104
105 LinkEasyEase();
107
111
112 pM.GetObject()->SetMaterial(&faceMaterial);
113 noiseMaterial.SetFirstLayerOpacity(0.4f);
114
115 ButtonHandler::Initialize(20, 6);//6 is number of faces
116 boop.Initialize(5);
117 }
118
120 blink.Update();
121 mouth.Update();
122 }
123
124 void Default(){
125 pM.Reset();
126 blink.Play();
127 mouth.Play();
128
129 talk = true;
130 }
131
132 void Angry(){
133 pM.Reset();
134 blink.Play();
135 mouth.Play();
136
137 eEA.AddParameterFrame(ProtoArtleck::Anger, 1.0f);
138 eEA.AddParameterFrame(99, 1.0f);
139
140 talk = true;
141 }
142
143 void Sad(){
144 pM.Reset();
145 blink.Play();
146 mouth.Play();
147
148 eEA.AddParameterFrame(ProtoArtleck::Sadness, 1.0f);
149
150 talk = true;
151 }
152
153 void Surprised(){
154 pM.Reset();
155 blink.Play();
156 mouth.Play();
157
158 eEA.AddParameterFrame(ProtoArtleck::Surprised, 1.0f);
159
160 talk = true;
161 }
162
163 void Doubt(){
164 pM.Reset();
165 blink.Play();
166 mouth.Play();
167
168 eEA.AddParameterFrame(ProtoArtleck::Doubt, 1.0f);
169 eEA.AddParameterFrame(ProtoArtleck::vrc_v_ou, 1.0f);
170
171 talk = true;
172 }
173
174 void Frown(){
175 pM.Reset();
176 blink.Play();
177 mouth.Play();
178
179 eEA.AddParameterFrame(ProtoArtleck::Frown, 1.0f);
180 eEA.AddParameterFrame(ProtoArtleck::vrc_v_ou, 1.0f);
181
182 talk = true;
183 }
184
185 void LookUp(){
186 pM.Reset();
187 blink.Play();
188 mouth.Play();
189
190 eEA.AddParameterFrame(ProtoArtleck::LookUp, 1.0f);
191
192 talk = true;
193 }
194
195 void LookDown(){
196 pM.Reset();
197 blink.Play();
198 mouth.Play();
199
200 eEA.AddParameterFrame(ProtoArtleck::LookDown, 1.0f);
201
202 talk = true;
203 }
204
205 void FadeIn(float stepRatio) override {}
206 void FadeOut(float stepRatio) override {}
207
209 return pM.GetObject();
210 }
211
212 float offset = 0.0f;
213
214 void Update(float ratio) override {
215 bool isBooped = boop.isBooped();
216 float mouthMove = mic.Update();
217 //uint8_t mode = (uint8_t)(ratio * 8.0f);//change sequentially
218 uint8_t mode = ButtonHandler::GetValue();//change by button press
219
220 if (isBooped){
221 Angry();
222 }
223 else{
224 if (mode == 0) Default();
225 else if (mode == 1) Surprised();
226 else if (mode == 2) Doubt();
227 else if (mode == 3) Frown();
228 else if (mode == 4) LookUp();
229 else if (mode == 5) Angry();
230 else Sad();
231 }
232
234
235 if(talk) eEA.AddParameterFrame(ProtoArtleck::vrc_v_aa, mouthMove);
236
237 eEA.Update();
238 pM.Update();
239
240 float x = sinf(ratio * 3.14159f / 180.0f * 360.0f * 2.0f) * 2.25f;
241 float y = cosf(ratio * 3.14159f / 180.0f * 360.0f * 3.0f) * 2.25f;
242
243 float linSweep = ratio > 0.5f ? 1.0f - ratio : ratio;
244 float sShift = linSweep * 0.002f + 0.005f;
245
246 gNoiseMat.SetGradientPeriod(0.5f + linSweep * 6.0f);
247 gNoiseMat.HueShift(ratio * 360 * 2);
248 sNoise.SetScale(Vector3D(sShift, sShift, sShift));
249 sNoise.SetZPosition(x * 4.0f);
250
251 faceMaterial.SetFirstLayerOpacity(colorMix);
252
253 Serial.println(colorMix);
254
255 pM.GetObject()->GetTransform()->SetRotation(Vector3D(0.0f, 0.0f, 0.0f + 15.0f));
256 pM.GetObject()->GetTransform()->SetPosition(Vector3D(x + 90.0f, y + 115.0f, 600.0f));
257 //pM.GetObject()->GetTransform()->SetScale(Vector3D(-0.65f, -0.65f, 0.5f));
258 pM.GetObject()->GetTransform()->SetScale(Vector3D(-0.85f, -0.65f, 0.5f));
259
260 pM.GetObject()->UpdateTransform();
261 }
262};
static void Initialize(uint8_t pin, uint8_t maxValue, uint16_t holdingToggle)
Initializes the ButtonHandler with specified parameters.
static uint8_t GetValue()
Retrieves the current value of the button.
Combines multiple materials with specified blending methods and opacities.
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.
A class to generate various waveform functions with customizable parameters.
@ Sine
Sine 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.
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.
Abstract base class for rendering materials.
Definition Material.h:27
@ Lighten
Chooses the lighter color.
Definition Material.h:40
@ Replace
Replaces the base color.
Definition Material.h:44
A simple class for processing microphone signals.
float Update()
Updates the microphone reading and processes the signal.
Represents a 3D object with geometry, material, and transformation data.
Definition Object3D.h:28
EasyEaseAnimator< 20 > eEA
CombineMaterial noiseMaterial
FunctionGenerator fGenMatPos
FunctionGenerator fGenScale
FunctionGenerator fGenRotation
void FadeIn(float stepRatio) override
GradientMaterial gradientMat
void FadeOut(float stepRatio) override
void Update(float ratio) override
Represents an RGB color and provides methods for manipulation.
Definition RGBColor.h:23
A material that applies a single, solid RGB color to surfaces.
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 3D vector (X, Y, Z) and provides methods for vector arithmetic.
Definition Vector3D.h:26