ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
SplatAnimation.h
Go to the documentation of this file.
1#pragma once
2
3#include "../Templates/ProtogenProjectTemplate.h"
4#include "../../Assets/Models/OBJ/DeltaDisplayBackground.h"
5#include "../../Assets/Models/FBX/Commissions/SplatFace.h"
6#include "../../Assets/Models/OBJ/LEDStripBackground.h"
7
8#include "../../Camera/CameraManager/Implementations/HUB75DeltaCameras.h"
9#include "../../Controller/HUB75Controller.h"
10
11#include "../../Scene/Materials/Animated/HorizontalRainbow.h"
12
14private:
17 SplatFace pM;
18 DeltaDisplayBackground deltaDisplayBackground;
19 LEDStripBackground ledStripBackground;
21
22 const __FlashStringHelper* faceArray[13] = {F("DEFAULT"), F("ANGRY"), F("CONFUSE"), F("DISAPPO"), F("FCIRCLE"), F("EXCITED"), F("HEART"), F("HCIRCLE"), F("SLEEPY"), F("AUDIO1"), F("AUDIO2"), F("AUDIO3")};
23
24 void LinkControlParameters() override {//Called from parent
25 AddParameter(SplatFace::AngryEyes, pM.GetMorphWeightReference(SplatFace::AngryEyes), 15);
26 AddParameter(SplatFace::AngryMouth, pM.GetMorphWeightReference(SplatFace::AngryMouth), 15);
27 AddParameter(SplatFace::ConfusedEyes, pM.GetMorphWeightReference(SplatFace::ConfusedEyes), 25);
28 AddParameter(SplatFace::ConfusedMouth, pM.GetMorphWeightReference(SplatFace::ConfusedMouth), 25);
29 AddParameter(SplatFace::DisappointedEyes, pM.GetMorphWeightReference(SplatFace::DisappointedEyes), 25);
30 AddParameter(SplatFace::DisappointedMouth, pM.GetMorphWeightReference(SplatFace::DisappointedMouth), 25);
31 AddParameter(SplatFace::ExcitedEyes, pM.GetMorphWeightReference(SplatFace::ExcitedEyes), 25);
32 AddParameter(SplatFace::FullCircleEyes, pM.GetMorphWeightReference(SplatFace::FullCircleEyes), 25);
33 AddParameter(SplatFace::HeartEyes, pM.GetMorphWeightReference(SplatFace::HeartEyes), 25);
34 AddParameter(SplatFace::HollowCircleEyes, pM.GetMorphWeightReference(SplatFace::HollowCircleEyes), 25);
35 AddParameter(SplatFace::SleepyEyes, pM.GetMorphWeightReference(SplatFace::SleepyEyes), 50, IEasyEaseAnimator::InterpolationMethod::Cosine);
36 AddParameter(SplatFace::SleepyMouth, pM.GetMorphWeightReference(SplatFace::SleepyMouth), 50, IEasyEaseAnimator::InterpolationMethod::Cosine);
37
38 AddParameter(SplatFace::HideBlush, pM.GetMorphWeightReference(SplatFace::HideBlush), 15, IEasyEaseAnimator::InterpolationMethod::Cosine, true);
39
40 AddViseme(Viseme::MouthShape::EE, pM.GetMorphWeightReference(SplatFace::vrc_v_ee));
41 AddViseme(Viseme::MouthShape::AH, pM.GetMorphWeightReference(SplatFace::vrc_v_aa));
42 AddViseme(Viseme::MouthShape::UH, pM.GetMorphWeightReference(SplatFace::vrc_v_dd));
43 AddViseme(Viseme::MouthShape::AR, pM.GetMorphWeightReference(SplatFace::vrc_v_rr));
44 AddViseme(Viseme::MouthShape::ER, pM.GetMorphWeightReference(SplatFace::vrc_v_ch));
45 AddViseme(Viseme::MouthShape::OO, pM.GetMorphWeightReference(SplatFace::vrc_v_oh));
46 AddViseme(Viseme::MouthShape::SS, pM.GetMorphWeightReference(SplatFace::vrc_v_ss));
47
48 //AddBlinkParameter(pM.GetMorphWeightReference(SplatFace::Blink));
49 }
50
51 void Default(){
52 //AddMaterialFrame(Color::CWHITE, 0.8f);
54
55 ledStripBackground.GetObject()->SetMaterial(GetFaceMaterial());
56 }
57
58 void Angry(){
59 AddParameterFrame(SplatFace::AngryEyes, 1.0f);
60 AddParameterFrame(SplatFace::AngryMouth, 1.0f);
62 }
63
64 void Confused(){
65 AddParameterFrame(SplatFace::ConfusedEyes, 1.0f);
66 AddParameterFrame(SplatFace::ConfusedMouth, 1.0f);
67 AddParameterFrame(SplatFace::HideBlush, 0.0f);
68 //AddMaterialFrame(Color::CRAINBOW, 0.8f);
70 }
71
73 AddParameterFrame(SplatFace::DisappointedEyes, 1.0f);
74 AddParameterFrame(SplatFace::DisappointedMouth, 1.0f);
75 //AddMaterialFrame(Color::CRAINBOW, 0.8f);
77 }
78
79 void Excited(){
80 AddParameterFrame(SplatFace::ExcitedEyes, 1.0f);
81 AddParameterFrame(SplatFace::HideBlush, 0.0f);
82 //AddMaterialFrame(Color::CRAINBOW, 0.8f);
84 }
85
86 void FullCircle(){
87 AddParameterFrame(SplatFace::FullCircleEyes, 1.0f);
88 //AddMaterialFrame(Color::CRAINBOW, 0.8f);
90 }
91
92 void Heart(){
93 AddParameterFrame(SplatFace::HeartEyes, 1.0f);
94 AddParameterFrame(SplatFace::HideBlush, 0.0f);
95 //AddMaterialFrame(Color::CRAINBOW, 0.8f);
97 }
98
100 AddParameterFrame(SplatFace::HollowCircleEyes, 1.0f);
101 //AddMaterialFrame(Color::CRAINBOW, 0.8f);
103 }
104
105 void Sleepy(){
106 AddParameterFrame(SplatFace::SleepyEyes, 1.0f);
107 AddParameterFrame(SplatFace::SleepyMouth, 1.0f);
109 }
110
111 void SpectrumAnalyzerCallback() override {
112 deltaDisplayBackground.GetObject()->SetMaterial(&hRainbow);
113 ledStripBackground.GetObject()->SetMaterial(&hRainbow);
114 }
115
117 deltaDisplayBackground.GetObject()->SetMaterial(&hRainbow);
118 ledStripBackground.GetObject()->SetMaterial(&hRainbow);
119 }
120
121 void OscilloscopeCallback() override {
122 deltaDisplayBackground.GetObject()->SetMaterial(&hRainbow);
123 ledStripBackground.GetObject()->SetMaterial(&hRainbow);
124 }
125
126public:
127 SplatAnimation() : ProtogenProject(&cameras, &controller, 3, Vector2D(), Vector2D(192.0f, 94.0f), 14, 20, 12){
128 scene.AddObject(pM.GetObject());
131
132 pM.GetObject()->SetMaterial(GetFaceMaterial());
133 deltaDisplayBackground.GetObject()->SetMaterial(GetFaceMaterial());
134 ledStripBackground.GetObject()->SetMaterial(GetFaceMaterial());
135
136 AddMaterial(Material::Replace, &hRainbow, 40, 0.0f, 1.0f);
137
139
141
142 SetWiggleSpeed(5.0f);
143 SetMenuWiggleSpeed(0.0f, 0.0f, 0.0f);
144 SetMenuOffset(Vector2D(17.5f, -3.0f));
145 SetMenuSize(Vector2D(192, 56));
146 }
147
148 void Update(float ratio) override {
149 pM.Reset();
150
151 uint8_t mode = Menu::GetFaceState();//change by button press
152
155
156 SelectFace(mode);
157
158 hRainbow.Update(ratio);
159
160 UpdateFace(ratio);
161
162 pM.Update();
163
164 AlignObjectFace(pM.GetObject(), 95.0f);
165
166 pM.GetObject()->GetTransform()->SetPosition(GetWiggleOffset());
167 pM.GetObject()->UpdateTransform();
168 }
169
170 void SelectFace(uint8_t code) {
171 if (IsBooped() && code < 9) {
172 Excited();
173 return;
174 }
175
176 switch(code) {
177 case 0: Default(); break;
178 case 1: Angry(); break;
179 case 2: Confused(); break;
180 case 3: Disappointed(); break;
181 case 4: FullCircle(); break;
182 case 5: Excited(); break;
183 case 6: Heart(); break;
184 case 7: HollowCircle(); break;
185 case 8: Sleepy(); break;
186 case 9: AudioReactiveGradientFace(); break;
187 case 10: OscilloscopeFace(); break;
188 default: SpectrumAnalyzerFace(); break;
189 }
190 }
191
192};
Manages HUB75 LED matrices with camera integration.
void SetAccentBrightness(uint8_t maxAccentBrightness) override
Sets the maximum accent brightness of the secondary display.
void SetBrightness(uint8_t maxBrightness) override
Sets the maximum brightness of the LED matrix.
void SetFaceArray(const __FlashStringHelper **faceNames)
Sets the array of face names.
Definition SSD1306.cpp:217
A dynamic horizontal rainbow gradient material.
void Update(float ratio)
Updates the gradient animation based on the provided time ratio.
@ Cosine
Smooth cosine interpolation.
@ Replace
Replaces the base color.
Definition Material.h:44
static uint8_t GetFaceState()
Retrieves the current face state. In hardware mode, it is read from the MenuHandler.
Definition Menu.cpp:381
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 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 OscilloscopeFace()
Enables the Oscilloscope on the face, updating offsets and calling callbacks.
void UpdateFace(float ratio)
Updates the face's rendered content, reading any user input and applying changes.
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 AddMaterial(Material::Method method, Material *material, uint16_t frames=20, float minOpacity=0.0f, float maxOpacity=1.0f)
Adds a new material to the face's MaterialAnimator with given parameters.
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).
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 AddParameterFrame(uint16_t ProjectIndex, float target)
Adds a frame target to a previously added parameter.
Material * GetFaceMaterial()
Retrieves the current face material animator.
void AddObject(Object3D *object)
Adds a 3D object to the scene.
Definition Scene.cpp:31
void SelectFace(uint8_t code)
const __FlashStringHelper * faceArray[13]
void LinkControlParameters() override
Links external or user-defined control parameters (pure virtual to be implemented).
void OscilloscopeCallback() override
Callback invoked when the Oscilloscope face is enabled/updated.
void SpectrumAnalyzerCallback() override
Callback invoked when the Spectrum Analyzer face is enabled/updated.
LEDStripBackground ledStripBackground
void Update(float ratio) override
Updates the project state based on the given ratio.
HorizontalRainbow hRainbow
DeltaDisplayBackground deltaDisplayBackground
HUB75Controller controller
HUB75DeltaCameraManager cameras
void AudioReactiveGradientCallback() override
Callback invoked when the Audio Reactive Gradient face is enabled/updated.
Represents a 2D vector (X, Y) and provides methods for vector arithmetic.
Definition Vector2D.h:27
@ 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.