ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
BetaProject.h
Go to the documentation of this file.
1#pragma once
2
3#include "../Templates/ProtogenProjectTemplate.h"
4#include "../../Assets/Models/FBX/BetaFront3.h"
5#include "../../Assets/Models/FBX/BetaRear.h"
6#include "../../Assets/Models/FBX/Standby.h"
7#include "../../Assets/Models/OBJ/LEDStripBackground.h"
8#include "../../Assets/Models/FBX/NukudeFlat.h"
9#include "../../Assets/Models/OBJ/RectangularPrism.h"
10#include "../../Assets/Models/OBJ/Spyro.h"
11
12#include "../../Animation/KeyFrameTrack.h"
13
14#include "../../Camera/CameraManager/Implementations/WS35Beta.h"
15#include "../../Controller/WS35BetaController.h"
16
18private:
21 BetaFront pM;
22 BetaRear rear;
23 Standby standby;
24 LEDStripBackground ledStripBackground;
25
27
31
32 const __FlashStringHelper* faceArray[15] = {F("DEFAULT"), F("SAD"), F("HEART"), F("DEAD"), F("ANGRY"), F("CRASH"), F("FRUSTRA"), F("DIZZY"), F("SHOCKED"), F("STANDBY"), F("GENTLE"), F("AUDIO1"), F("AUDIO2"), F("AUDIO3")};
33
39
40 int standbyIndex = 200;
41 float showStandby = 0.0f;
42
43 void LinkControlParameters() override {
44 AddParameter(BetaFront::BlushEye, pM.GetMorphWeightReference(BetaFront::BlushEye), 40);
45 AddParameter(BetaFront::HideBlush, pM.GetMorphWeightReference(BetaFront::HideBlush), 10, IEasyEaseAnimator::InterpolationMethod::Cosine, true);
46 AddParameter(BetaFront::HideEyeBrow, pM.GetMorphWeightReference(BetaFront::HideEyeBrow), 10, IEasyEaseAnimator::InterpolationMethod::Cosine);
47 AddParameter(BetaFront::HideSecondEye, pM.GetMorphWeightReference(BetaFront::HideSecondEye), 10, IEasyEaseAnimator::InterpolationMethod::Cosine);
48 AddParameter(BetaFront::OwOMouth, pM.GetMorphWeightReference(BetaFront::OwOMouth), 60);
49 AddParameter(BetaFront::SadEye, pM.GetMorphWeightReference(BetaFront::SadEye), 70, IEasyEaseAnimator::InterpolationMethod::Cosine);
50 AddParameter(BetaFront::SadEyeBrow, pM.GetMorphWeightReference(BetaFront::SadEyeBrow), 80, IEasyEaseAnimator::InterpolationMethod::Cosine);
51 AddParameter(BetaFront::SadMouth, pM.GetMorphWeightReference(BetaFront::SadMouth), 90, IEasyEaseAnimator::InterpolationMethod::Cosine);
52 AddParameter(BetaFront::FlatMouth, pM.GetMorphWeightReference(BetaFront::FlatMouth), 50);
53 AddParameter(BetaFront::DeadEye, pM.GetMorphWeightReference(BetaFront::DeadEye), 1);
54 AddParameter(BetaFront::HeartEye, pM.GetMorphWeightReference(BetaFront::HeartEye), 30);
55 AddParameter(BetaFront::AlphaGenCircle,pM.GetMorphWeightReference(BetaFront::AlphaGenCircle), 90, IEasyEaseAnimator::InterpolationMethod::Cosine);
56 AddParameter(BetaFront::HideAll,pM.GetMorphWeightReference(BetaFront::HideAll), 90);
57 AddParameter(BetaFront::AngryEyeMouth,pM.GetMorphWeightReference(BetaFront::AngryEyeMouth), 30);
58 AddParameter(BetaFront::CrashEmoticon,pM.GetMorphWeightReference(BetaFront::CrashEmoticon), 90);
59 AddParameter(BetaFront::FrustratedEye,pM.GetMorphWeightReference(BetaFront::FrustratedEye), 40);
60 AddParameter(BetaFront::FrustratedMouth,pM.GetMorphWeightReference(BetaFront::FrustratedMouth), 40);
61 AddParameter(BetaFront::DizzyEye,pM.GetMorphWeightReference(BetaFront::DizzyEye), 60);
62 AddParameter(BetaFront::DizzyMouth,pM.GetMorphWeightReference(BetaFront::DizzyMouth), 60);
63 AddParameter(BetaFront::ShockedEye,pM.GetMorphWeightReference(BetaFront::ShockedEye), 20);
64 AddParameter(BetaFront::ShockedMouth2,pM.GetMorphWeightReference(BetaFront::ShockedMouth), 20);
65 AddParameter(BetaFront::GentleEye,pM.GetMorphWeightReference(BetaFront::GentleEye), 90);
66 AddParameter(BetaFront::GentleMouth,pM.GetMorphWeightReference(BetaFront::GentleMouth), 90);
68
69 AddBlinkParameter(pM.GetMorphWeightReference(BetaFront::ClosedEye));
70
71 AddViseme(Viseme::MouthShape::EE, pM.GetMorphWeightReference(BetaFront::vrc_v_ee));
72 AddViseme(Viseme::MouthShape::AH, pM.GetMorphWeightReference(BetaFront::vrc_v_aa));
73 AddViseme(Viseme::MouthShape::UH, pM.GetMorphWeightReference(BetaFront::vrc_v_dd));
74 AddViseme(Viseme::MouthShape::AR, pM.GetMorphWeightReference(BetaFront::vrc_v_rr));
75 AddViseme(Viseme::MouthShape::ER, pM.GetMorphWeightReference(BetaFront::vrc_v_ch));
76 AddViseme(Viseme::MouthShape::OO, pM.GetMorphWeightReference(BetaFront::vrc_v_oh));
77 AddViseme(Viseme::MouthShape::SS, pM.GetMorphWeightReference(BetaFront::vrc_v_ss));
78
79 botFinLR1.AddParameter(rear.GetMorphWeightReference(BetaRear::Move1));
80 botFinLR2.AddParameter(rear.GetMorphWeightReference(BetaRear::Move2));
81 botFinLR3.AddParameter(rear.GetMorphWeightReference(BetaRear::Move3));
82 botFinLR4.AddParameter(rear.GetMorphWeightReference(BetaRear::Move4));
83 botFinLR5.AddParameter(rear.GetMorphWeightReference(BetaRear::Move5));
84 }
85
87 botFinLR1.AddKeyFrame(0.0f, 0.0f);
88 botFinLR2.AddKeyFrame(0.0f, 0.0f);
89 botFinLR3.AddKeyFrame(0.0f, 0.0f);
90 botFinLR4.AddKeyFrame(0.0f, 0.0f);
91 botFinLR5.AddKeyFrame(0.0f, 1.0f);
92
93 botFinLR1.AddKeyFrame(0.5f, 1.0f);
94 botFinLR2.AddKeyFrame(0.5f, 0.0f);
95 botFinLR3.AddKeyFrame(0.5f, 0.0f);
96 botFinLR4.AddKeyFrame(0.5f, 0.0f);
97 botFinLR5.AddKeyFrame(0.5f, 0.0f);
98
99 botFinLR1.AddKeyFrame(1.0f, 0.0f);
100 botFinLR2.AddKeyFrame(1.0f, 1.0f);
101 botFinLR3.AddKeyFrame(1.0f, 0.0f);
102 botFinLR4.AddKeyFrame(1.0f, 0.0f);
103 botFinLR5.AddKeyFrame(1.0f, 0.0f);
104
105 botFinLR1.AddKeyFrame(1.5f, 0.0f);
106 botFinLR2.AddKeyFrame(1.5f, 0.0f);
107 botFinLR3.AddKeyFrame(1.5f, 1.0f);
108 botFinLR4.AddKeyFrame(1.5f, 0.0f);
109 botFinLR5.AddKeyFrame(1.5f, 0.0f);
110
111 botFinLR1.AddKeyFrame(2.0f, 0.0f);
112 botFinLR2.AddKeyFrame(2.0f, 0.0f);
113 botFinLR3.AddKeyFrame(2.0f, 0.0f);
114 botFinLR4.AddKeyFrame(2.0f, 1.0f);
115 botFinLR5.AddKeyFrame(2.0f, 0.0f);
116
117 botFinLR1.AddKeyFrame(2.5f, 0.0f);
118 botFinLR2.AddKeyFrame(2.5f, 0.0f);
119 botFinLR3.AddKeyFrame(2.5f, 0.0f);
120 botFinLR4.AddKeyFrame(2.5f, 0.0f);
121 botFinLR5.AddKeyFrame(2.5f, 1.0f);
122 }
123
131
132
133 void Default(){
135
136 AddParameterFrame(BetaFront::HideSecondEye, 1.0f);
137 }
138
139 void OwO(){
141 AddParameterFrame(BetaFront::BlushEye, 1.0f);
142 AddParameterFrame(BetaFront::HideBlush, 0.0f);
143 AddParameterFrame(BetaFront::HideEyeBrow, 1.0f);
144 AddParameterFrame(BetaFront::HideSecondEye, 1.0f);
145 AddParameterFrame(BetaFront::OwOMouth, 1.0f);
146
148 }
149
150 void Sad(){
152 AddParameterFrame(BetaFront::SadEye, 1.0f);
153 AddParameterFrame(BetaFront::SadEyeBrow, 1.0f);
154 AddParameterFrame(BetaFront::SadMouth, 1.0f);
155 AddParameterFrame(BetaFront::HideSecondEye, 1.0f);
156
158 }
159
160 void Dead(){
162 AddParameterFrame(BetaFront::FlatMouth, 1.0f);
163 AddParameterFrame(BetaFront::DeadEye, 1.0f);
164 AddParameterFrame(BetaFront::HideSecondEye, 1.0f);
165
167 }
168
169 void Heart(){
171 AddParameterFrame(BetaFront::HeartEye, 1.0f);
172 AddParameterFrame(BetaFront::HideEyeBrow, 1.0f);
173 AddParameterFrame(BetaFront::OwOMouth, 1.0f);
174 AddParameterFrame(BetaFront::HideSecondEye, 1.0f);
175
177 }
178
179 void OwO2(){
181 AddParameterFrame(BetaFront::HideBlush, 0.0f);
182 AddParameterFrame(BetaFront::HideEyeBrow, 0.0f);
183
185 }
186
189 AddParameterFrame(BetaFront::HideBlush, 0.0f);
190 AddParameterFrame(BetaFront::HideEyeBrow, 0.0f);
191 AddParameterFrame(BetaFront::AlphaGenCircle, 1.0f);
192 AddParameterFrame(BetaFront::HideSecondEye, 0.0f);
193
195 }
196
197 void AngryFace(){
199
200 AddParameterFrame(BetaFront::HideBlush, 1.0f);
201 AddParameterFrame(BetaFront::HideEyeBrow, 1.0f);
202 AddParameterFrame(BetaFront::AngryEyeMouth, 1.0f);
203 AddParameterFrame(BetaFront::HideSecondEye, 0.0f);
204
206 }
207
208 void Crash(){
210
211 AddParameterFrame(BetaFront::HideBlush, 0.0f);
212 AddParameterFrame(BetaFront::CrashEmoticon, 1.0f);
213
215
217 }
218
221
222 AddParameterFrame(BetaFront::HideBlush, 1.0f);
223 AddParameterFrame(BetaFront::HideSecondEye, 1.0f);
224 AddParameterFrame(BetaFront::FrustratedEye, 1.0f);
225 AddParameterFrame(BetaFront::FrustratedMouth, 1.0f);
226
228 }
229
230 void Dizzy(){
232
233 AddParameterFrame(BetaFront::HideBlush, 1.0f);
234 AddParameterFrame(BetaFront::HideSecondEye, 0.0f);
235 AddParameterFrame(BetaFront::DizzyEye, 1.0f);
236 AddParameterFrame(BetaFront::DizzyMouth, 1.0f);
237
239 }
240
241 void Shocked(){
243
244 AddParameterFrame(BetaFront::HideBlush, 0.0f);
245 AddParameterFrame(BetaFront::HideSecondEye, 0.0f);
246 AddParameterFrame(BetaFront::ShockedEye, 1.0f);
247 AddParameterFrame(BetaFront::ShockedMouth2, 1.0f);
248
250 }
251
252 void StandbyF(){
254 //HideFace
255 AddParameterFrame(BetaFront::HideBlush, 0.0f);
256 AddParameterFrame(BetaFront::HideAll, 1.0f);
258
260 }
261
262 void Gentle(){
264
265 AddParameterFrame(BetaFront::HideBlush, 1.0f);
266 AddParameterFrame(BetaFront::HideSecondEye, 1.0f);
267 AddParameterFrame(BetaFront::GentleEye, 1.0f);
268 AddParameterFrame(BetaFront::GentleMouth, 1.0f);
269
271 }
272
280
284
288
292
293public:
294 BetaProject() : ProtogenProject(&cameras, &controller, 4, Vector2D(), Vector2D(192.0f, 105.0f), 22, 23, 14){
295 scene.AddObject(pM.GetObject());
296 scene.AddObject(rear.GetObject());
298 scene.AddObject(standby.GetObject());
299
300 pM.GetObject()->SetMaterial(GetFaceMaterial());
301 rear.GetObject()->SetMaterial(GetFaceMaterial());
302 ledStripBackground.GetObject()->SetMaterial(GetFaceMaterial());
303 standby.GetObject()->SetMaterial(&greenMaterial);
304
307
309
310 SetCameraRear(Vector2D(251.11f, 49.43f), Vector2D(408.9f, 215.2f));
311
312 SetWiggleSpeed(5.0f);
313 SetMenuWiggleSpeed(0.0f, 0.0f, 0.0f);
314 SetMenuOffset(Vector2D(2.5f, -3.0f));
315 SetMenuSize(Vector2D(240, 64));
316 }
317
318 void Update(float ratio) override {
319 pM.Reset();
320 rear.Reset();
321
322 Menu::Update(ratio);
323
324 uint8_t mode = Menu::GetFaceState();//change by button press
325
328
329 SelectFace(mode);
330
332
333 pM.Update();
334 rear.Update();
335 standby.Update();
336
337 AlignObjectFace(pM.GetObject(), 180.0f, 2.0f, true);
338 AlignObjectFace(standby.GetObject(), fGen.Update(), 2.0f, 0.0f);
339 AlignObjectRear(rear.GetObject(), -25.0f, 2.0f, false);
340
341 pM.GetObject()->GetTransform()->SetPosition(GetWiggleOffset() + Vector3D(-20.0f * *pM.GetMorphWeightReference(BetaFront::CrashEmoticon), 0.0f, 0.0f));
342 pM.GetObject()->UpdateTransform();
343
344 standby.GetObject()->GetTransform()->SetPosition(Vector3D(0.0f, fGen3.Update(), 0.0f));
345 standby.GetObject()->GetTransform()->SetScaleOffset(standby.GetObject()->GetCenterOffset());
346 standby.GetObject()->GetTransform()->SetScale(Vector3D(showStandby * fGen2.Update(), showStandby, showStandby));
347 standby.GetObject()->GetTransform()->SetRotationOffset(standby.GetObject()->GetCenterOffset());
348 standby.GetObject()->GetTransform()->SetRotation(Vector3D(0.0f, 0.0f, fGen2.Update() * 15.0f + 15.0f));
349 standby.GetObject()->UpdateTransform();
350
351 Serial.println(showStandby);
352
353 rear.GetObject()->GetTransform()->SetPosition(GetWiggleOffset());
354 rear.GetObject()->UpdateTransform();
355
356 //Serial.print(rear.GetObject()->GetCenterOffset().ToString()); Serial.print('\n');
357 }
358
359 void SelectFace(uint8_t code) {
360 if (IsBooped()) {
361 OwO();
362 return;
363 }
364
365 switch(code) {
366 case 0: Default(); break;
367 case 1: Sad(); break;
368 case 2: Heart(); break;
369 case 3: Dead(); break;
370 case 4: AngryFace(); break;
371 case 5: Crash(); break;
372 case 6: Frustrated(); break;
373 case 7: Dizzy(); break;
374 case 8: Shocked(); break;
375 case 9: StandbyF(); break;
376 case 10: Gentle(); break;
377 case 11: AudioReactiveGradientFace(); break;
378 case 12: OscilloscopeFace(); break;
379 default: SpectrumAnalyzerFace(); break;
380 }
381 }
382};
void SelectFace(uint8_t code)
SimpleMaterial greenMaterial
Definition BetaProject.h:26
void LinkControlParameters() override
Links external or user-defined control parameters (pure virtual to be implemented).
Definition BetaProject.h:43
KeyFrameTrack< 1, 10 > botFinLR2
Definition BetaProject.h:35
void OscilloscopeCallback() override
Callback invoked when the Oscilloscope face is enabled/updated.
BetaRear rear
Definition BetaProject.h:22
void UpdateKeyFrameTracks()
KeyFrameTrack< 1, 10 > botFinLR4
Definition BetaProject.h:37
void SpectrumAnalyzerCallback() override
Callback invoked when the Spectrum Analyzer face is enabled/updated.
KeyFrameTrack< 1, 10 > botFinLR1
Definition BetaProject.h:34
KeyFrameTrack< 1, 10 > botFinLR3
Definition BetaProject.h:36
LEDStripBackground ledStripBackground
Definition BetaProject.h:24
WS35BetaCameraManager cameras
Definition BetaProject.h:19
float showStandby
Definition BetaProject.h:41
void Gentle()
WS35BetaController controller
Definition BetaProject.h:20
void AlphaGenCircle()
void AddBotFinKeyFrames()
Definition BetaProject.h:86
void Update(float ratio) override
Updates the project state based on the given ratio.
void Frustrated()
void StandbyF()
void Shocked()
void Default()
void UpdateKeyframeTracks()
KeyFrameTrack< 1, 10 > botFinLR5
Definition BetaProject.h:38
BetaFront pM
Definition BetaProject.h:21
FunctionGenerator fGen2
Definition BetaProject.h:29
FunctionGenerator fGen3
Definition BetaProject.h:30
void AudioReactiveGradientCallback() override
Callback invoked when the Audio Reactive Gradient face is enabled/updated.
Standby standby
Definition BetaProject.h:23
void AngryFace()
const __FlashStringHelper * faceArray[15]
Definition BetaProject.h:32
FunctionGenerator fGen
Definition BetaProject.h:28
A class to generate various waveform functions with customizable parameters.
@ Sine
Sine waveform.
float Update()
Updates and calculates the next value of the waveform.
void SetFaceArray(const __FlashStringHelper **faceNames)
Sets the array of face names.
Definition SSD1306.cpp:217
@ 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 AddKeyFrame(float time, float value)
Adds a keyframe to the track.
float Update()
Updates the animation track and computes the new parameter value.
static uint8_t GetFaceState()
Retrieves the current face state. In hardware mode, it is read from the MenuHandler.
Definition Menu.cpp:381
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
Scene scene
The Scene object representing the rendered environment.
Definition Project.h:35
A default project template that includes functionality for an analog microphone, APDS9960 boop sensor...
void SetMenuWiggleSpeed(float multiplierX, float multiplierY, float multiplierR)
Adjusts the menu's wiggle speed along X, Y, and rotation.
Vector3D GetWiggleOffset()
Computes and returns a Vector3D offset for a "wiggle" effect using function generators.
void EnableBlinking()
Enables blinking (resets and plays the blink track).
void AudioReactiveGradientFace()
Enables the Audio Reactive Gradient on the face, updating offsets and calling callbacks.
void SetMenuOffset(Vector2D offset)
Sets the menu's position offset.
void SetMenuSize(Vector2D size)
Sets the menu's size.
void AddBackgroundMaterialFrame(Color color, float opacity=0.8f)
Adds a material frame to the background from a color enum.
void OscilloscopeFace()
Enables the Oscilloscope on the face, updating offsets and calling callbacks.
void AlignObjectRear(Object3D *obj, float rotation=0.0f, float margin=2.0f, bool mirror=true)
Aligns a single Object3D to the rear camera bounds with scaling.
void SetWiggleSpeed(float multiplier)
Sets the overall wiggle speed for both X and Y function generators.
bool IsBooped()
Checks if the sensor has detected a boop.
void SpectrumAnalyzerFace()
Enables the Spectrum Analyzer on the face, updating offsets and calling callbacks.
void AddParameter(uint8_t index, float *parameter, uint16_t transitionFrames, IEasyEaseAnimator::InterpolationMethod interpolationMethod=IEasyEaseAnimator::InterpolationMethod::Overshoot, bool invertDirection=false)
Adds a parameter to the EasyEaseAnimator for interpolation.
void DisableBlinking()
Disables blinking (pauses and resets the blink track).
void AlignObjectFace(Object3D *obj, float rotation=0.0f, float margin=2.0f, bool mirror=true)
Aligns a single Object3D to the "face" camera bounds with scaling.
void AddViseme(Viseme::MouthShape visemeName, float *parameter)
Adds a viseme parameter to the animator (for mouth shapes).
void SetCameraRear(Vector2D min, Vector2D max)
Sets the camera bounds for the rear view.
@ CRAINBOWNOISE
Flow noise (rainbow noise).
@ CHORIZONTALRAINBOW
Horizontal rainbow effect.
@ CRAINBOW
Rainbow spiral.
HeadsUpDisplay hud
Heads-up display (HUD) for the face overlay or additional data.
void AddMaterialFrame(Color color, float opacity=0.8f)
Adds a new material frame to the face's MaterialAnimator from a color enum.
void AddBlinkParameter(float *blinkParameter)
Adds a float parameter to the blink track for controlling blinking.
void AddParameterFrame(uint16_t ProjectIndex, float target)
Adds a frame target to a previously added parameter.
Material * GetFaceMaterial()
Retrieves the current face material animator.
Represents an RGB color and provides methods for manipulation.
Definition RGBColor.h:23
void AddObject(Object3D *object)
Adds a 3D object to the scene.
Definition Scene.cpp:31
A material that applies a single, solid RGB color to surfaces.
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.
@ SS
Mouth shape corresponding to the "SS" sound (optional).
@ EE
Mouth shape corresponding to the "EE" sound.
Manages WS2812-based displays for the Beta Protogen head.
void SetAccentBrightness(uint8_t maxAccentBrightness) override
Sets the maximum accent brightness (not used for this controller).
void SetBrightness(uint8_t maxBrightness) override
Sets the maximum brightness for the displays.