Got a single frame exporting correctly
This commit is contained in:
@@ -13,7 +13,7 @@ namespace AnimationHelpers{
|
|||||||
V3D<uint8_t> cyan{0,255,255};
|
V3D<uint8_t> cyan{0,255,255};
|
||||||
V3D<uint8_t> magenta{255,0,255};
|
V3D<uint8_t> magenta{255,0,255};
|
||||||
|
|
||||||
Cell CreateCell(float x_percent, float y_percent, float z_percent, V3D<uint8_t> &color){
|
Cell CreateCell(float x_percent, float y_percent, float z_percent, const V3D<uint8_t> &color){
|
||||||
float continuousMaxValue{static_cast<float>(std::numeric_limits<uint32_t>::max())};
|
float continuousMaxValue{static_cast<float>(std::numeric_limits<uint32_t>::max())};
|
||||||
Cell cell{
|
Cell cell{
|
||||||
.position = V3D<uint32_t>{
|
.position = V3D<uint32_t>{
|
||||||
@@ -211,11 +211,27 @@ namespace RisingCubes{
|
|||||||
.delay = std::chrono::milliseconds(1)
|
.delay = std::chrono::milliseconds(1)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
AnimationFrame frame0{
|
||||||
|
.frame = {
|
||||||
|
CreateCell(0.0,0.0,0.0,V3D<uint8_t>(255.0,255.0,255.0)),
|
||||||
|
CreateCell(0.0,0.5,0.0,V3D<uint8_t>(0.0,255.0,0.0)),
|
||||||
|
CreateCell(0.0,1.0,0.0,V3D<uint8_t>(0.0,255.0,0.0)),
|
||||||
|
CreateCell(0.0,0.0,0.5,V3D<uint8_t>(0.0,0.0,255.0)),
|
||||||
|
CreateCell(0.0,0.0,1.0,V3D<uint8_t>(0.0,0.0,255.0)),
|
||||||
|
CreateCell(0.5,0.0,0.0,V3D<uint8_t>(255.0,0.0,0.0)),
|
||||||
|
CreateCell(1.0,0.0,0.0,V3D<uint8_t>(255.0,0.0,0.0))
|
||||||
|
},
|
||||||
|
.fillInterpolation = FillInterpolation::NO_FILL,
|
||||||
|
.frameInterpolation = FrameInterpolation::FADE,
|
||||||
|
.delay = std::chrono::milliseconds(1000)
|
||||||
|
};
|
||||||
|
|
||||||
std::vector<AnimationFrame> rising{
|
std::vector<AnimationFrame> rising{
|
||||||
frame1, // 0
|
frame0, frame0
|
||||||
frame2, // 1
|
// frame1, // 0
|
||||||
frame3, // 2
|
// frame2, // 1
|
||||||
frame4, // 3
|
// frame3, // 2
|
||||||
frame5
|
// frame4, // 3
|
||||||
|
// frame5
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -7,34 +7,37 @@
|
|||||||
;
|
;
|
||||||
; Please visit documentation for the other options and examples
|
; Please visit documentation for the other options and examples
|
||||||
; https://docs.platformio.org/page/projectconf.html
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
[platformio]
|
[platformio]
|
||||||
default_envs = esp32s3_release ; this ensures that only this environment is built for anything but the debug build
|
default_envs = esp32s3_release
|
||||||
extra_configs = platformio-local.ini
|
extra_configs = platformio-local.ini
|
||||||
|
|
||||||
[env]
|
[env]
|
||||||
; platform = espressif32
|
|
||||||
upload_protocol = esptool
|
upload_protocol = esptool
|
||||||
platform = https://github.com/platformio/platform-espressif32.git
|
platform = https://github.com/platformio/platform-espressif32.git
|
||||||
board = esp32-s3-devkitc-1
|
board = esp32-s3-devkitc-1
|
||||||
framework = arduino
|
framework = arduino
|
||||||
build_flags = -Iinclude
|
build_flags = -Iinclude
|
||||||
|
|
||||||
monitor_speed = 9600
|
monitor_speed = 9600
|
||||||
monitor_filters = colorize, send_on_enter
|
monitor_filters = colorize, send_on_enter
|
||||||
upload_speed = 2000000 ;ESP32S3 USB-Serial Converter maximum 2000000bps
|
upload_speed = 2000000
|
||||||
lib_deps = adafruit/Adafruit NeoPixel@^1.12.0
|
lib_deps =
|
||||||
|
adafruit/Adafruit NeoPixel@^1.12.3
|
||||||
|
fastled/FastLED@^3.7.3
|
||||||
|
|
||||||
|
|
||||||
[env:esp32s3_release]
|
[env:esp32s3_release]
|
||||||
build_type = release
|
build_type = release
|
||||||
|
monitor_port = COM21
|
||||||
|
upload_port = COM20
|
||||||
|
|
||||||
[env:esp32s3_debug]
|
[env:esp32s3_debug]
|
||||||
debug_init_break = tbreak setup
|
debug_init_break = tbreak setup
|
||||||
debug_tool = esp-builtin
|
debug_tool = esp-builtin
|
||||||
build_type = debug
|
build_type = debug
|
||||||
debug_speed = 20000
|
debug_speed = 20000
|
||||||
; debug_port = COM7
|
|
||||||
; monitor_port = COM14
|
|
||||||
build_flags =
|
build_flags =
|
||||||
-D DEBUG = 1
|
-D DEBUG = 1
|
||||||
-I include
|
-I include
|
||||||
|
monitor_port = COM21
|
||||||
|
upload_port = COM20
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ TaskHandle_t updateBoardTask;
|
|||||||
|
|
||||||
std::array<std::vector<AnimationFrame>*, 2> animations = {
|
std::array<std::vector<AnimationFrame>*, 2> animations = {
|
||||||
&RisingCubes::rising,
|
&RisingCubes::rising,
|
||||||
&RotatingCubes::rotating,
|
// &RotatingCubes::rotating,
|
||||||
};
|
};
|
||||||
|
|
||||||
// BluetoothSerial SerialBT;
|
// BluetoothSerial SerialBT;
|
||||||
@@ -112,6 +112,7 @@ void parseData(Message<SERIAL_CHAR_LENGTH, SERIAL_ARG_LENGTH> &message){
|
|||||||
}
|
}
|
||||||
case Commands::PING:{
|
case Commands::PING:{
|
||||||
GlobalPrint::Println("!" + String(Commands::PING) + ";");
|
GlobalPrint::Println("!" + String(Commands::PING) + ";");
|
||||||
|
boardManager.PrintColorState();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Commands::SetStackColors:{
|
case Commands::SetStackColors:{
|
||||||
|
|||||||
1
tools/animation-tools/.gitignore
vendored
1
tools/animation-tools/.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
venv/
|
venv/
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
output.txt
|
||||||
74
tools/animation-tools/AnimationExporter.py
Normal file
74
tools/animation-tools/AnimationExporter.py
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
from Scene import Scene
|
||||||
|
from enum import StrEnum
|
||||||
|
from pygame.math import Vector3
|
||||||
|
from Shapes import Mesh
|
||||||
|
|
||||||
|
class FillInterpolation(StrEnum):
|
||||||
|
NO_FILL = "NO_FILL"
|
||||||
|
CLOSEST_COLOR = "CLOSEST_COLOR"
|
||||||
|
LINEAR_WEIGHTED_DISTANCE = "LINEAR_WEIGHTED_DISTANCE"
|
||||||
|
SQUARE_WEIGHTED_DISTANCE = "SQUARE_WEIGHTED_DISTANCE"
|
||||||
|
|
||||||
|
class FrameInterpolation(StrEnum):
|
||||||
|
SNAP = "SNAP"
|
||||||
|
FADE = "FADE"
|
||||||
|
|
||||||
|
class Cell:
|
||||||
|
def __init__(self, position: Vector3, color: Vector3):
|
||||||
|
self.position: Vector3 = position
|
||||||
|
self.color: Vector3 = color
|
||||||
|
|
||||||
|
def to_string(self):
|
||||||
|
message = f"CreateCell({self.position.x},{self.position.y},{self.position.z}"
|
||||||
|
message += f",V3D<uint8_t>({self.color.x},{self.color.y},{self.color.z})),"
|
||||||
|
return message
|
||||||
|
|
||||||
|
class AnimationFrame:
|
||||||
|
def __init__(self, cells: list[Cell], fill_interpolation: FillInterpolation, frame_interpolation: FrameInterpolation, delay: int):
|
||||||
|
self.cells = cells
|
||||||
|
self.fill = fill_interpolation
|
||||||
|
self.frame_interp = frame_interpolation
|
||||||
|
self.delay = delay
|
||||||
|
|
||||||
|
def to_string(self, frame_number: int):
|
||||||
|
cell_str = ""
|
||||||
|
for cell in self.cells:
|
||||||
|
if cell.color.x != 0 or cell.color.y != 0 or cell.color.z != 0:
|
||||||
|
cell_str += cell.to_string() + "\n\t"
|
||||||
|
cell_str = cell_str[:-3]
|
||||||
|
message = f"""
|
||||||
|
AnimationFrame frame{frame_number}{{
|
||||||
|
.frame = {{
|
||||||
|
{cell_str}
|
||||||
|
}},
|
||||||
|
.fillInterpolation = FillInterpolation::{self.fill},
|
||||||
|
.frameInterpolation = FrameInterpolation::{self.frame_interp},
|
||||||
|
.delay = std::chrono::milliseconds({self.delay})
|
||||||
|
}};
|
||||||
|
"""
|
||||||
|
return message
|
||||||
|
|
||||||
|
|
||||||
|
#TODO: Impliment this
|
||||||
|
def generate_animation_frame_struct(animation_types_path: str):
|
||||||
|
with open(animation_types_path, 'r') as AnimationTypes:
|
||||||
|
with open("AnimationTypes.py", 'w') as output:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def mesh_to_cell(mesh: Mesh) -> Cell:
|
||||||
|
if mesh.face_color[0] != 0 or mesh.face_color[1] != 0 or mesh.face_color[2] != 0:
|
||||||
|
pass
|
||||||
|
pos = (mesh.get_average_position() + Vector3(1,1,1)) / 2
|
||||||
|
# need to swap z and y for the coordinate system
|
||||||
|
z = pos.y
|
||||||
|
pos.y = pos.z
|
||||||
|
pos.z = z
|
||||||
|
testVector = Vector3(0.1,0.5,0.9)
|
||||||
|
|
||||||
|
cell = Cell(pos, Vector3(mesh.face_color))
|
||||||
|
return cell
|
||||||
|
|
||||||
|
def scene_to_frame(scene: Scene) -> str:
|
||||||
|
cells = [mesh_to_cell(cube) for cube in scene.meshes]
|
||||||
|
frame = AnimationFrame(cells, FillInterpolation.NO_FILL, FrameInterpolation.FADE, 1000)
|
||||||
|
return frame.to_string(0)
|
||||||
31
tools/animation-tools/README.md
Normal file
31
tools/animation-tools/README.md
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# Setup
|
||||||
|
In order to run this tool follow these steps:
|
||||||
|
|
||||||
|
1. ensure you're using python 3.12+. You can verify this by running
|
||||||
|
```
|
||||||
|
python --version
|
||||||
|
```
|
||||||
|
in a terminal.
|
||||||
|
|
||||||
|
2. Inside of a terminal in the
|
||||||
|
```
|
||||||
|
tools/animation-tools
|
||||||
|
```
|
||||||
|
folder, run:
|
||||||
|
```
|
||||||
|
python -m venv venv
|
||||||
|
```
|
||||||
|
to create your virtual environment.
|
||||||
|
|
||||||
|
3. Now activate the virtual environment. In powershell run
|
||||||
|
```
|
||||||
|
venv\Scripts\activate
|
||||||
|
```
|
||||||
|
You may need to fix permission issues if this is your first time using a virtual environment. For git bash just run:
|
||||||
|
```
|
||||||
|
source venv/Scripts/activate
|
||||||
|
```
|
||||||
|
4. Run
|
||||||
|
```
|
||||||
|
pip install -r requirements.txt
|
||||||
|
```
|
||||||
@@ -18,6 +18,12 @@ class Mesh():
|
|||||||
def calculate_average_z(self, vertices):
|
def calculate_average_z(self, vertices):
|
||||||
return [(i, sum([vertices[j].z for j in f]) / len(f)) for i, f in enumerate(self.__faces)]
|
return [(i, sum([vertices[j].z for j in f]) / len(f)) for i, f in enumerate(self.__faces)]
|
||||||
|
|
||||||
|
def get_average_position(self):
|
||||||
|
vertex_sum: Vector3 = Vector3()
|
||||||
|
for vertex in self.__vertices:
|
||||||
|
vertex_sum += vertex
|
||||||
|
return vertex_sum / len(self.__vertices)
|
||||||
|
|
||||||
def get_face(self, index):
|
def get_face(self, index):
|
||||||
return self.__faces[index]
|
return self.__faces[index]
|
||||||
def get_vertices(self):
|
def get_vertices(self):
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import pygame_widgets
|
|||||||
from Shapes import *
|
from Shapes import *
|
||||||
from Scene import Scene
|
from Scene import Scene
|
||||||
from CustomWidgets import ColorPicker
|
from CustomWidgets import ColorPicker
|
||||||
|
from pygame_widgets.button import Button
|
||||||
|
from AnimationExporter import scene_to_frame
|
||||||
|
|
||||||
|
|
||||||
# generate a list of cubes
|
# generate a list of cubes
|
||||||
@@ -17,10 +19,19 @@ for origin in product([-1, 0, 1],[-1, 0, 1],[-1, 0, 1]):
|
|||||||
|
|
||||||
scene = Scene(meshes, 90, 5)
|
scene = Scene(meshes, 90, 5)
|
||||||
|
|
||||||
|
WINDOW_W = 500
|
||||||
|
WINDOW_H = 500
|
||||||
|
|
||||||
|
def save_frame_to_file(frame_data=""):
|
||||||
|
frame_data += scene_to_frame(scene)
|
||||||
|
print(frame_data)
|
||||||
|
with open("tools/animation-tools/output.txt", 'w') as file:
|
||||||
|
file.write(frame_data)
|
||||||
|
|
||||||
pygame.init()
|
pygame.init()
|
||||||
window = pygame.display.set_mode((500, 500))
|
window = pygame.display.set_mode((WINDOW_W, WINDOW_H))
|
||||||
colorPicker = ColorPicker(window, 20, 20, 100, 300)
|
colorPicker = ColorPicker(window, 20, 20, 100, 300)
|
||||||
|
save_button = Button(window, 20, WINDOW_H-40, 60, 30, text="Save",onClick=save_frame_to_file)
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
selected_meshes = []
|
selected_meshes = []
|
||||||
run = True
|
run = True
|
||||||
|
|||||||
Reference in New Issue
Block a user