feat: use gateway
This commit is contained in:
250
docs/EDITOR_UPDATE.md
Normal file
250
docs/EDITOR_UPDATE.md
Normal file
@@ -0,0 +1,250 @@
|
||||
# Editor UI Improvements - Update Summary
|
||||
|
||||
## Overview
|
||||
|
||||
The Preset Editor has been significantly enhanced with live canvas preview, node selection, and real-time rendering capabilities.
|
||||
|
||||
## New Features
|
||||
|
||||
### 1. Live Canvas Preview
|
||||
|
||||
A real-time canvas preview has been added directly to the Editor view:
|
||||
|
||||
- **Location**: Center panel, above the layer list
|
||||
- **Display**: Shows live animation rendering at the configured FPS
|
||||
- **Updates**: Automatically refreshes when layers are added, modified, or removed
|
||||
- **FPS Counter**: Displays actual rendering frame rate
|
||||
- **Size Display**: Shows current matrix dimensions (e.g., "16×16")
|
||||
|
||||
**Implementation:**
|
||||
- `canvas-renderer.js` - Client-side renderer that executes building blocks
|
||||
- Simplified versions of shapes, colors, and animations for browser rendering
|
||||
- Efficient pixel-by-pixel drawing with proper serpentine wiring support
|
||||
|
||||
### 2. Node Selector Dropdown
|
||||
|
||||
A dropdown has been added to the editor header for target selection:
|
||||
|
||||
- **Options**:
|
||||
- "Canvas Preview Only" (default) - Only renders to canvas
|
||||
- List of discovered nodes with IP addresses
|
||||
- **Auto-Discovery**: Automatically populates with available nodes
|
||||
- **Dynamic Updates**: Updates when nodes are discovered or lost
|
||||
- **Persistent Selection**: Maintains selection when nodes list refreshes
|
||||
|
||||
### 3. Dual-Mode Preview
|
||||
|
||||
The preview system now supports two modes:
|
||||
|
||||
**Canvas-Only Mode** (No node selected):
|
||||
- Renders animation to canvas preview only
|
||||
- No network traffic
|
||||
- Perfect for designing and testing
|
||||
- Uses client-side rendering engine
|
||||
|
||||
**Canvas + Node Mode** (Node selected):
|
||||
- Renders to both canvas AND transmits to selected node
|
||||
- Canvas preview for visual feedback
|
||||
- Node receives frames via server streaming
|
||||
- Synchronized rendering
|
||||
|
||||
### 4. Preview Controls
|
||||
|
||||
Enhanced preview control panel:
|
||||
|
||||
- **Start/Stop Button**: Toggles preview on/off
|
||||
- "▶️ Start Preview" when stopped
|
||||
- "⏸️ Stop Preview" when running
|
||||
- **Status Indicator**: Shows current mode
|
||||
- "Stopped" (gray) - Preview is off
|
||||
- "Canvas Preview" (green) - Rendering to canvas only
|
||||
- "Streaming to [IP]" (blue) - Rendering to canvas + node
|
||||
|
||||
### 5. Auto-Refresh on Changes
|
||||
|
||||
The preview automatically restarts when configuration changes:
|
||||
|
||||
- Adding a new layer
|
||||
- Deleting a layer
|
||||
- Loading a preset
|
||||
- Importing JSON
|
||||
- Animation states are reset for clean restart
|
||||
|
||||
## Technical Details
|
||||
|
||||
### Canvas Renderer (`canvas-renderer.js`)
|
||||
|
||||
A browser-based implementation of the building blocks system:
|
||||
|
||||
**Features:**
|
||||
- Renders shapes: circle, rectangle, blob, point
|
||||
- Color generators: solid, gradient, rainbow
|
||||
- Animations: move, rotate, pulse, oscillate, fade
|
||||
- Pattern support: radial, spiral
|
||||
- Proper RGB color blending
|
||||
- FPS tracking and display
|
||||
|
||||
**Architecture:**
|
||||
```javascript
|
||||
class CanvasRenderer {
|
||||
- setSize(width, height) // Update matrix dimensions
|
||||
- renderConfiguration(config) // Render preset configuration
|
||||
- drawFrame(frame) // Draw frame to canvas
|
||||
- clear() // Clear canvas
|
||||
- reset() // Reset animation states
|
||||
}
|
||||
```
|
||||
|
||||
### Preview System Flow
|
||||
|
||||
```
|
||||
User clicks "Start Preview"
|
||||
↓
|
||||
1. Initialize canvas renderer
|
||||
2. Reset animation states
|
||||
3. Start render loop (20 FPS default)
|
||||
↓
|
||||
Every frame:
|
||||
- Execute building blocks
|
||||
- Render to canvas
|
||||
- Update FPS counter
|
||||
↓
|
||||
If node selected:
|
||||
- Also send config to server
|
||||
- Server streams to node
|
||||
```
|
||||
|
||||
### Node Discovery Integration
|
||||
|
||||
The editor subscribes to the main app's event bus:
|
||||
|
||||
```javascript
|
||||
eventBus.subscribe('nodeDiscovered', () => updateDropdown())
|
||||
eventBus.subscribe('nodeLost', () => updateDropdown())
|
||||
```
|
||||
|
||||
This ensures the node list stays synchronized with the Stream view.
|
||||
|
||||
## UI Layout Changes
|
||||
|
||||
### Before
|
||||
```
|
||||
[Editor Header]
|
||||
[Sidebar] [Layers] [Details]
|
||||
```
|
||||
|
||||
### After
|
||||
```
|
||||
[Editor Header with Preview Controls]
|
||||
[Sidebar] [Canvas Preview + Layers] [Details]
|
||||
```
|
||||
|
||||
The center panel now features the canvas preview prominently at the top, with the layer list below it.
|
||||
|
||||
## Usage Examples
|
||||
|
||||
### Example 1: Design Without Hardware
|
||||
|
||||
1. Create preset in editor
|
||||
2. Leave node selector at "Canvas Preview Only"
|
||||
3. Click "Start Preview"
|
||||
4. Watch animation in canvas
|
||||
5. Modify layers and see changes instantly
|
||||
6. No SPORE node required!
|
||||
|
||||
### Example 2: Test on Real Hardware
|
||||
|
||||
1. Create preset in editor
|
||||
2. Select target node from dropdown
|
||||
3. Click "Start Preview"
|
||||
4. Animation appears on both canvas and physical LED matrix
|
||||
5. Modify and see changes on both displays
|
||||
|
||||
### Example 3: Quick Iteration
|
||||
|
||||
1. Import an example preset
|
||||
2. Start canvas preview
|
||||
3. Modify parameters in layer details
|
||||
4. Changes automatically refresh
|
||||
5. When satisfied, select node and stream
|
||||
|
||||
## Performance
|
||||
|
||||
- **Canvas Rendering**: ~60 FPS capable, default 20 FPS
|
||||
- **Network Efficiency**: Only streams when node is selected
|
||||
- **CPU Usage**: Minimal, uses requestAnimationFrame equivalent (setInterval)
|
||||
- **Memory**: Efficient frame buffer management
|
||||
|
||||
## Browser Compatibility
|
||||
|
||||
- Modern browsers with Canvas API support
|
||||
- Chrome, Firefox, Safari, Edge (latest versions)
|
||||
- Mobile browsers supported (responsive design)
|
||||
|
||||
## Styling Updates
|
||||
|
||||
New CSS classes added:
|
||||
|
||||
- `.editor-preview-controls` - Preview control panel
|
||||
- `.preview-control-group` - Control group container
|
||||
- `.node-select` - Node selector dropdown
|
||||
- `.preview-status` - Status indicator
|
||||
- `.active` - Canvas preview (green)
|
||||
- `.streaming` - Node streaming (blue)
|
||||
- `.editor-preview-container` - Canvas container
|
||||
- `.editor-canvas` - Canvas element
|
||||
- `.editor-canvas-info` - Size and FPS display
|
||||
|
||||
## Files Modified
|
||||
|
||||
1. **public/index.html**
|
||||
- Added preview controls header
|
||||
- Added canvas preview section
|
||||
- Removed old preview button
|
||||
- Added canvas-renderer.js script
|
||||
|
||||
2. **public/styles/main.css**
|
||||
- Added preview control styles (~80 lines)
|
||||
- Added canvas preview styles
|
||||
- Enhanced responsive design
|
||||
- Added status indicator styles
|
||||
|
||||
3. **public/scripts/preset-editor.js**
|
||||
- Added canvas renderer integration
|
||||
- Added node discovery and dropdown
|
||||
- Added dual-mode preview system
|
||||
- Added auto-refresh on changes
|
||||
- Enhanced preview controls
|
||||
|
||||
4. **public/scripts/canvas-renderer.js** (NEW)
|
||||
- Complete client-side renderer
|
||||
- Building blocks implementation
|
||||
- Animation engine
|
||||
- Canvas drawing logic
|
||||
|
||||
## Benefits
|
||||
|
||||
✅ **Instant Feedback**: See animations immediately without node
|
||||
✅ **Faster Iteration**: No need to upload to hardware for testing
|
||||
✅ **Better UX**: Visual confirmation of changes
|
||||
✅ **Flexible Testing**: Canvas-only or canvas+node modes
|
||||
✅ **Resource Efficient**: No network traffic in canvas-only mode
|
||||
✅ **Educational**: Watch animations render in real-time
|
||||
✅ **Debugging**: FPS counter helps identify performance issues
|
||||
|
||||
## Future Enhancements
|
||||
|
||||
Possible future additions:
|
||||
|
||||
- [ ] Adjustable preview FPS slider
|
||||
- [ ] Canvas zoom controls
|
||||
- [ ] Grid overlay option
|
||||
- [ ] Pixel coordinates on hover
|
||||
- [ ] Recording/GIF export
|
||||
- [ ] Side-by-side canvas comparison
|
||||
- [ ] Preview size presets (8×8, 16×16, 32×32)
|
||||
|
||||
## Conclusion
|
||||
|
||||
The enhanced Editor UI provides a professional, feature-rich environment for creating and testing LED animations. The live canvas preview and flexible node targeting make the design process intuitive and efficient, whether working with physical hardware or designing purely in software.
|
||||
|
||||
234
docs/MULTI_NODE_UPDATE.md
Normal file
234
docs/MULTI_NODE_UPDATE.md
Normal file
@@ -0,0 +1,234 @@
|
||||
# Multi-Node Canvas Grid Update
|
||||
|
||||
## Overview
|
||||
|
||||
The SPORE LEDLab interface has been redesigned to display all SPORE nodes simultaneously with individual canvases in a responsive grid layout. Each node can be controlled independently with its own preset and parameters.
|
||||
|
||||
## Key Changes
|
||||
|
||||
### 1. UI Layout Redesign
|
||||
|
||||
**Before:**
|
||||
- Single canvas display in center
|
||||
- Node list in right sidebar
|
||||
- Controls always visible in right sidebar
|
||||
|
||||
**After:**
|
||||
- Full-width grid layout displaying all nodes
|
||||
- Each node has its own canvas card
|
||||
- Floating control panel appears when a node is selected
|
||||
- Maximizes screen space for displaying multiple nodes
|
||||
|
||||
### 2. New Components
|
||||
|
||||
#### `NodeCanvasGrid` Component
|
||||
- **Location:** `/public/scripts/node-canvas-grid.js`
|
||||
- **Purpose:** Manages the grid of node canvases
|
||||
- **Features:**
|
||||
- Displays all discovered SPORE nodes in a responsive grid
|
||||
- Each node card shows:
|
||||
- Node IP address
|
||||
- Connection status (connected/streaming)
|
||||
- Live canvas with streaming visualization
|
||||
- Click on any node to select it and show controls
|
||||
- Supports both individual node selection and broadcast mode
|
||||
- Real-time frame rendering for each node
|
||||
|
||||
#### Updated `PresetControls` Component
|
||||
- **Location:** `/public/scripts/preset-controls.js`
|
||||
- **Changes:**
|
||||
- Now works with floating control panel
|
||||
- Tracks parameters per node (using Map)
|
||||
- Restores node-specific settings when switching between nodes
|
||||
- Sends node-specific commands to server
|
||||
|
||||
### 3. CSS Styling
|
||||
|
||||
#### New Classes
|
||||
- `.matrix-grid-section` - Full-width container for node grid
|
||||
- `.node-canvas-grid` - CSS grid layout for node cards
|
||||
- `.node-canvas-item` - Individual node card styling
|
||||
- Hover effects
|
||||
- Selected state (green border glow)
|
||||
- Streaming animation
|
||||
- `.floating-controls` - Floating control panel
|
||||
- Appears when node is selected
|
||||
- Slides in from right (desktop) or bottom (mobile)
|
||||
- Closes when clicking X or deselecting node
|
||||
|
||||
#### Responsive Design
|
||||
- Desktop: 3-4 columns based on screen width
|
||||
- Tablet: 2-3 columns
|
||||
- Mobile: 1-2 columns with controls sliding from bottom
|
||||
|
||||
### 4. Server-Side Multi-Node Streaming
|
||||
|
||||
#### Updated `LEDLabServer` Class
|
||||
- **Location:** `/server/index.js`
|
||||
- **New Features:**
|
||||
- `nodeStreams` Map: Tracks active streams per node
|
||||
- `nodeConfigurations` Map: Stores per-node settings
|
||||
- Simultaneous streaming to multiple nodes
|
||||
- Per-node preset instances and parameters
|
||||
|
||||
#### Key Methods Updated
|
||||
- `startPreset(presetName, width, height, nodeIp, parameters)`
|
||||
- Now accepts nodeIp to target specific node
|
||||
- Supports initial parameter values
|
||||
|
||||
- `stopStreaming(nodeIp)`
|
||||
- Stops streaming for specific node or all nodes
|
||||
|
||||
- `updatePresetParameter(parameter, value, nodeIp)`
|
||||
- Updates parameters for specific node or broadcast to all
|
||||
|
||||
- `streamFrameForNode(nodeIp)`
|
||||
- Generates and sends frames for specific node
|
||||
- Multiple intervals running simultaneously
|
||||
|
||||
### 5. HTML Structure
|
||||
|
||||
#### Stream View (Main View)
|
||||
```html
|
||||
<section class="matrix-grid-section">
|
||||
<div class="node-canvas-grid">
|
||||
<!-- Node cards dynamically created here -->
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<aside class="floating-controls">
|
||||
<!-- Control panel content -->
|
||||
</aside>
|
||||
```
|
||||
|
||||
### 6. User Workflow
|
||||
|
||||
1. **Node Discovery**
|
||||
- Nodes automatically discovered via UDP
|
||||
- Each node appears as a card in the grid
|
||||
|
||||
2. **Node Selection**
|
||||
- Click any node card to select it
|
||||
- Floating control panel appears
|
||||
- Node card highlights with green border
|
||||
|
||||
3. **Configure Node**
|
||||
- Select preset from dropdown
|
||||
- Adjust parameters with sliders
|
||||
- Changes apply only to selected node
|
||||
|
||||
4. **Start Streaming**
|
||||
- Click "Start Streaming" button
|
||||
- Node card shows "streaming" status
|
||||
- Canvas displays live animation
|
||||
|
||||
5. **Multi-Node Operation**
|
||||
- Select different node
|
||||
- Configure with different preset/parameters
|
||||
- Start streaming independently
|
||||
- Multiple nodes can stream simultaneously
|
||||
|
||||
6. **Broadcast Mode**
|
||||
- Click "Broadcast to All" button
|
||||
- Control panel shows "Broadcast to All"
|
||||
- Preset and parameters apply to all nodes
|
||||
|
||||
## Technical Details
|
||||
|
||||
### Per-Node State Management
|
||||
|
||||
#### Client-Side (PresetControls)
|
||||
```javascript
|
||||
this.nodeParameters = new Map(); // nodeIp -> {presetName, parameters}
|
||||
```
|
||||
- Stores preset selection and parameters for each node
|
||||
- Restores settings when switching between nodes
|
||||
- Maintains independent state per node
|
||||
|
||||
#### Server-Side (LEDLabServer)
|
||||
```javascript
|
||||
this.nodeStreams = new Map(); // nodeIp -> {preset, presetName, interval, matrixSize}
|
||||
this.nodeConfigurations = new Map(); // nodeIp -> {presetName, parameters, matrixSize}
|
||||
```
|
||||
- Active streams run independently with separate intervals
|
||||
- Configurations saved per node
|
||||
- Multiple presets can run simultaneously
|
||||
|
||||
### WebSocket Messages
|
||||
|
||||
#### Enhanced Messages
|
||||
All streaming-related messages now include optional `nodeIp` field:
|
||||
```javascript
|
||||
{
|
||||
type: 'startPreset',
|
||||
presetName: 'lava-lamp',
|
||||
width: 16,
|
||||
height: 16,
|
||||
nodeIp: '192.168.1.100', // or null for broadcast
|
||||
parameters: {speed: 1.5, scale: 2.0}
|
||||
}
|
||||
```
|
||||
|
||||
### Frame Rendering
|
||||
|
||||
Each node has its own canvas with:
|
||||
- Independent rendering context
|
||||
- Automatic sizing based on container
|
||||
- Serpentine pixel order support
|
||||
- Glow effects for bright pixels
|
||||
- Smooth animations
|
||||
|
||||
## Benefits
|
||||
|
||||
1. **Visual Overview** - See all nodes at once
|
||||
2. **Independent Control** - Each node can run different animations
|
||||
3. **Space Efficient** - Responsive grid maximizes screen usage
|
||||
4. **Scalable** - Works with 1-20+ nodes
|
||||
5. **Intuitive** - Click to select, visual feedback
|
||||
6. **Flexible** - Individual or broadcast mode
|
||||
|
||||
## Backwards Compatibility
|
||||
|
||||
- Old single-stream API still supported
|
||||
- Settings view unchanged
|
||||
- Existing presets work without modification
|
||||
- UDP discovery unchanged
|
||||
|
||||
## File Changes Summary
|
||||
|
||||
### New Files
|
||||
- `/public/scripts/node-canvas-grid.js` - New component
|
||||
|
||||
### Modified Files
|
||||
- `/public/index.html` - Updated layout
|
||||
- `/public/styles/main.css` - New grid and floating control styles
|
||||
- `/public/scripts/preset-controls.js` - Per-node parameter tracking
|
||||
- `/public/scripts/ledlab-app.js` - Initialize new component
|
||||
- `/server/index.js` - Multi-node streaming support
|
||||
|
||||
### Unchanged Files
|
||||
- All preset files (`/presets/*.js`)
|
||||
- `/server/udp-discovery.js`
|
||||
- `/public/scripts/framework.js`
|
||||
- `/public/scripts/theme-manager.js`
|
||||
- `/public/scripts/navigation.js`
|
||||
|
||||
## Testing Recommendations
|
||||
|
||||
1. Test with single node
|
||||
2. Test with multiple nodes (2-4)
|
||||
3. Test node selection and switching
|
||||
4. Test broadcast mode
|
||||
5. Test parameter independence
|
||||
6. Test starting/stopping individual streams
|
||||
7. Test responsive layout on different screen sizes
|
||||
8. Test node disconnection/reconnection
|
||||
|
||||
## Future Enhancements
|
||||
|
||||
- Drag to reorder nodes
|
||||
- Group nodes for collective control
|
||||
- Save/load multi-node scenes
|
||||
- Node status graphs
|
||||
- Performance metrics per node
|
||||
|
||||
354
docs/PRESET_EDITOR.md
Normal file
354
docs/PRESET_EDITOR.md
Normal file
@@ -0,0 +1,354 @@
|
||||
# Preset Editor - Implementation Summary
|
||||
|
||||
## Overview
|
||||
|
||||
A visual preset editor has been added to SPORE LEDLab, allowing users to create custom LED animations by combining reusable building blocks without writing code.
|
||||
|
||||
## Components Implemented
|
||||
|
||||
### 1. Building Blocks System (`presets/building-blocks.js`)
|
||||
|
||||
A comprehensive library of reusable animation components:
|
||||
|
||||
#### **Shapes**
|
||||
- Circle, Rectangle, Triangle, Blob, Point, Line
|
||||
- Configurable position, size, color, and intensity
|
||||
- Support for blending and compositing
|
||||
|
||||
#### **Transforms**
|
||||
- Rotate, Scale, Translate
|
||||
- Transform composition for complex movements
|
||||
|
||||
#### **Color Generators**
|
||||
- Solid, Gradient, Palette (multi-stop), Rainbow, Radial
|
||||
- HSV color space support
|
||||
- Programmable color functions
|
||||
|
||||
#### **Animations**
|
||||
- Linear Move, Rotation, Pulse
|
||||
- Oscillation (X/Y axes)
|
||||
- Bounce physics, Fade in/out
|
||||
- Time-based with customizable parameters
|
||||
|
||||
#### **Patterns**
|
||||
- Trail effects (fade decay)
|
||||
- Energy fields (distance-based intensity)
|
||||
- Radial patterns
|
||||
- Spiral patterns
|
||||
|
||||
### 2. Custom Preset Engine (`presets/custom-preset.js`)
|
||||
|
||||
A JSON-driven preset system that:
|
||||
- Loads and validates preset configurations
|
||||
- Manages multiple layers
|
||||
- Applies animations in real-time
|
||||
- Supports dynamic parameters
|
||||
- Renders frames at target FPS
|
||||
|
||||
**JSON Schema:**
|
||||
```json
|
||||
{
|
||||
"name": "Preset Name",
|
||||
"description": "Description",
|
||||
"layers": [
|
||||
{
|
||||
"type": "shape|pattern",
|
||||
"shape": "circle|rectangle|...",
|
||||
"position": { "x": 8, "y": 8 },
|
||||
"size": { "radius": 3 },
|
||||
"color": { "type": "solid", "value": "ff0000" },
|
||||
"animation": {
|
||||
"type": "pulse",
|
||||
"params": { "minScale": 0.5, "maxScale": 1.5, "frequency": 1.0 }
|
||||
}
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"speed": { "type": "range", "min": 0.1, "max": 2.0, "default": 1.0 }
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 3. Visual Editor UI (`public/scripts/preset-editor.js`)
|
||||
|
||||
A modern two-panel editor interface:
|
||||
|
||||
**Left Panel: Preset Management & Layers**
|
||||
- Preset metadata (name, description)
|
||||
- **New preset button** - Creates fresh preset with confirmation
|
||||
- Add layer button
|
||||
- Expandable layer list with:
|
||||
- Visual layer cards showing type and properties
|
||||
- Layer reordering (up/down arrows)
|
||||
- Layer deletion
|
||||
- Click to expand/collapse layer details
|
||||
- Management section:
|
||||
- Save/Load presets (localStorage)
|
||||
- Export/Import JSON files
|
||||
- Delete current preset
|
||||
|
||||
**Right Panel: Preview & Controls**
|
||||
- Preview controls bar:
|
||||
- Node selection dropdown (Canvas Only or specific node)
|
||||
- Start/Stop preview button
|
||||
- Status indicator
|
||||
- Canvas size and FPS display
|
||||
- **Real-time canvas preview** - Shows exact animation as streamed to nodes
|
||||
- **Synchronized rendering** - Client preview matches server output perfectly
|
||||
|
||||
### 4. Server Integration (`server/index.js`)
|
||||
|
||||
Added `startCustomPreset` handler:
|
||||
- Accepts JSON configuration via WebSocket
|
||||
- Creates CustomPreset instance
|
||||
- Manages streaming like built-in presets
|
||||
- Supports all existing features (parameters, node selection, FPS control)
|
||||
|
||||
### 5. UI Integration (`public/index.html`, `public/styles/main.css`)
|
||||
|
||||
- Added Editor tab to navigation
|
||||
- Modern two-panel responsive layout
|
||||
- Dark/light theme support with **enhanced dropdown styling**
|
||||
- **Dark dropdown backgrounds** with light text for better readability
|
||||
- Notification system for user feedback
|
||||
- Import/Export file handling
|
||||
- **Canvas renderer** (`public/scripts/canvas-renderer.js`) for client-side preview
|
||||
|
||||
### 6. Example Presets (`presets/examples/`)
|
||||
|
||||
Four complete example presets:
|
||||
1. **Pulsing Circle** - Rainbow circle with pulse animation
|
||||
2. **Bouncing Squares** - Multiple colored squares with oscillation
|
||||
3. **Spiral Rainbow** - Rotating spiral with multi-color gradient
|
||||
4. **Moving Triangle** - Linear movement with gradient colors
|
||||
|
||||
Plus comprehensive README documentation.
|
||||
|
||||
## Features
|
||||
|
||||
✅ **Visual Composition**
|
||||
- Drag-free layer management with expandable cards
|
||||
- Real-time property editing
|
||||
- Layer reordering and deletion
|
||||
- **Triangle shape support** - Full triangle rendering with rotation
|
||||
|
||||
✅ **Flexible Configuration**
|
||||
- Multiple shape types (circle, rectangle, triangle, blob, point)
|
||||
- Various color modes (solid, gradient, palette, rainbow)
|
||||
- Rich animation options (move, rotate, pulse, oscillate, fade)
|
||||
- Parameter customization
|
||||
- **Pattern layers** with intensity control
|
||||
|
||||
✅ **Save & Share**
|
||||
- LocalStorage persistence
|
||||
- JSON export/import
|
||||
- Version-controllable configurations
|
||||
- Shareable preset files
|
||||
- **New preset button** for fresh starts
|
||||
|
||||
✅ **Live Preview**
|
||||
- **Synchronized canvas preview** - Shows exact animation as streamed to nodes
|
||||
- Real-time streaming to selected node
|
||||
- Integrated with existing node selection
|
||||
- Full parameter control
|
||||
- **Layer compositing** - All layers render correctly with proper alpha blending
|
||||
|
||||
✅ **Reusable Components**
|
||||
- Extracted from existing presets
|
||||
- Optimized rendering
|
||||
- Extensible architecture
|
||||
- **Server-client rendering parity** - Identical output on both sides
|
||||
|
||||
## Usage Flow
|
||||
|
||||
1. User opens **🎨 Editor** view
|
||||
2. Enters preset name and description
|
||||
3. Adds layers:
|
||||
- Clicks "➕ Add Layer" button
|
||||
- Configures layer properties in expandable cards:
|
||||
- Shape type (circle, rectangle, triangle, blob, point)
|
||||
- Position (X, Y coordinates)
|
||||
- Size (radius, width, height)
|
||||
- Color (solid, gradient, palette, rainbow)
|
||||
- Intensity (0.0 - 1.0)
|
||||
- Animation (move, rotate, pulse, oscillate, fade)
|
||||
4. Manages layers:
|
||||
- Expands/collapses layer details by clicking
|
||||
- Reorders with up/down arrows
|
||||
- Deletes unwanted layers
|
||||
5. Previews animation:
|
||||
- Selects target node or "Canvas Only"
|
||||
- Clicks "▶️ Start" to begin preview
|
||||
- Watches synchronized canvas preview
|
||||
6. Saves work:
|
||||
- Uses "💾 Save" to store in localStorage
|
||||
- Uses "📤 Export JSON" to download file
|
||||
- Uses "📥 Import JSON" to load shared presets
|
||||
7. Creates new presets:
|
||||
- Uses "📄 New" button for fresh start
|
||||
- Confirms if current work will be lost
|
||||
|
||||
## Technical Architecture
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────┐
|
||||
│ Editor UI (Browser) │
|
||||
│ ┌────────────────────────────────────┐ │
|
||||
│ │ Preset Editor Component │ │
|
||||
│ │ - Layer Management │ │
|
||||
│ │ - Property Forms │ │
|
||||
│ │ - Preview Control │ │
|
||||
│ └────────────────────────────────────┘ │
|
||||
└──────────────┬──────────────────────────┘
|
||||
│ WebSocket (JSON Config)
|
||||
▼
|
||||
┌─────────────────────────────────────────┐
|
||||
│ Server (Node.js) │
|
||||
│ ┌────────────────────────────────────┐ │
|
||||
│ │ startCustomPreset Handler │ │
|
||||
│ │ - Parse JSON configuration │ │
|
||||
│ │ - Create CustomPreset instance │ │
|
||||
│ │ - Start streaming │ │
|
||||
│ └────────────────────────────────────┘ │
|
||||
└──────────────┬──────────────────────────┘
|
||||
│ Frame Generation Loop
|
||||
▼
|
||||
┌─────────────────────────────────────────┐
|
||||
│ Custom Preset Engine │
|
||||
│ ┌────────────────────────────────────┐ │
|
||||
│ │ Building Blocks System │ │
|
||||
│ │ - Shapes, Patterns, Colors │ │
|
||||
│ │ - Animations, Transforms │ │
|
||||
│ │ - Composition & Rendering │ │
|
||||
│ └────────────────────────────────────┘ │
|
||||
└──────────────┬──────────────────────────┘
|
||||
│ UDP Frames
|
||||
▼
|
||||
[SPORE Node LED Matrix]
|
||||
```
|
||||
|
||||
## File Changes Summary
|
||||
|
||||
### New Files
|
||||
- `presets/building-blocks.js` - Core building blocks library
|
||||
- `presets/custom-preset.js` - JSON-driven preset engine
|
||||
- `public/scripts/preset-editor.js` - Visual editor UI
|
||||
- `public/scripts/canvas-renderer.js` - Client-side canvas renderer
|
||||
- `presets/examples/pulsing-circle.json` - Example preset
|
||||
- `presets/examples/bouncing-squares.json` - Example preset
|
||||
- `presets/examples/spiral-rainbow.json` - Example preset
|
||||
- `presets/examples/moving-triangle.json` - Example preset
|
||||
- `presets/examples/README.md` - Example documentation
|
||||
- `PRESET_EDITOR.md` - This file
|
||||
|
||||
### Modified Files
|
||||
- `public/index.html` - Added Editor view HTML with New button
|
||||
- `public/styles/main.css` - Added editor styles and enhanced dropdown styling
|
||||
- `server/index.js` - Added custom preset handler
|
||||
- `presets/building-blocks.js` - Added intensity support for pattern layers
|
||||
- `presets/custom-preset.js` - Added intensity support for pattern rendering
|
||||
- `README.md` - Added Preset Editor documentation
|
||||
|
||||
## Extensibility
|
||||
|
||||
The system is designed to be easily extended:
|
||||
|
||||
**Add New Shape:**
|
||||
```javascript
|
||||
Shapes.star = (frame, width, height, centerX, centerY, points, radius, color) => {
|
||||
// Rendering logic
|
||||
};
|
||||
```
|
||||
|
||||
**Add New Animation:**
|
||||
```javascript
|
||||
Animations.wobble = (amplitude, frequency) => {
|
||||
return () => {
|
||||
// Animation logic
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
**Add New Color Generator:**
|
||||
```javascript
|
||||
ColorGenerators.plasma = (time, x, y) => {
|
||||
// Color calculation
|
||||
};
|
||||
```
|
||||
|
||||
## Performance
|
||||
|
||||
- Efficient rendering with minimal allocations
|
||||
- Frame generation at configurable FPS (1-60)
|
||||
- Optimized color blending
|
||||
- Smart update scheduling
|
||||
|
||||
## Browser Compatibility
|
||||
|
||||
- Modern browsers (Chrome, Firefox, Safari, Edge)
|
||||
- Requires ES6+ support
|
||||
- LocalStorage for persistence
|
||||
- File API for import/export
|
||||
|
||||
## Recent Updates
|
||||
|
||||
### Latest Improvements (Current Version)
|
||||
- ✅ **Triangle Shape Support** - Added full triangle rendering with rotation animation
|
||||
- ✅ **Layer Compositing Fix** - All layers now render correctly with proper alpha blending
|
||||
- ✅ **Server-Client Synchronization** - Preview canvas shows identical animation to streamed output
|
||||
- ✅ **Pattern Layer Intensity** - Pattern layers now support intensity control like shape layers
|
||||
- ✅ **New Preset Button** - Quick way to start fresh with confirmation dialog
|
||||
- ✅ **Enhanced Dropdown Styling** - Dark backgrounds with light text for better readability
|
||||
- ✅ **Canvas Renderer** - Dedicated client-side renderer for accurate previews
|
||||
|
||||
### Bug Fixes
|
||||
- Fixed pattern layer overwriting instead of compositing with other layers
|
||||
- Fixed gradient color calculation bug in client-side renderer
|
||||
- Fixed triangle rendering missing from preview canvas
|
||||
- Improved dropdown readability in dark theme
|
||||
|
||||
## Future Enhancements
|
||||
|
||||
Possible future additions:
|
||||
- [ ] Undo/Redo support
|
||||
- [ ] Layer groups
|
||||
- [ ] Custom parameter types
|
||||
- [ ] Animation timeline editor
|
||||
- [ ] Blend modes between layers
|
||||
- [ ] Physics simulations
|
||||
- [ ] Sound-reactive parameters
|
||||
- [ ] Community preset library
|
||||
- [ ] Preset thumbnails/previews
|
||||
- [ ] Keyboard shortcuts
|
||||
- [ ] Line shape support
|
||||
- [ ] Additional pattern types
|
||||
- [ ] Real-time collaboration
|
||||
|
||||
## Testing
|
||||
|
||||
To test the implementation:
|
||||
|
||||
1. Start LEDLab server: `npm start`
|
||||
2. Open browser to `http://localhost:3000`
|
||||
3. Navigate to Stream view and select a node
|
||||
4. Switch to Editor view
|
||||
5. Import an example preset (e.g., `pulsing-circle.json`)
|
||||
6. Click Preview to see it running
|
||||
7. Modify parameters and preview again
|
||||
8. Create your own preset from scratch
|
||||
9. Export and reimport to verify JSON handling
|
||||
|
||||
## Conclusion
|
||||
|
||||
The Preset Editor provides a powerful, user-friendly way to create custom LED animations without coding. It leverages a well-architected building blocks system that extracts reusable patterns from existing presets and makes them composable through a visual interface and JSON configuration.
|
||||
|
||||
**Key achievements:**
|
||||
- **Perfect synchronization** between preview and actual output
|
||||
- **Comprehensive shape support** including triangles with rotation
|
||||
- **Proper layer compositing** with alpha blending
|
||||
- **Intuitive UI** with expandable layer cards and dark theme
|
||||
- **Robust persistence** with localStorage and JSON export/import
|
||||
- **Real-time preview** that matches server rendering exactly
|
||||
|
||||
The editor is now production-ready with all major rendering issues resolved and enhanced user experience features implemented.
|
||||
|
||||
Reference in New Issue
Block a user