Change vector drawing primitive from shape to doubly-connected edge graph

This commit is contained in:
Skyler Lehmkuhl
2026-02-23 21:29:58 -05:00
parent eab116c930
commit 99f8dcfcf4
31 changed files with 2664 additions and 3774 deletions
@@ -747,7 +747,6 @@ pub fn render_frame_to_rgba_hdr(
base_transform,
image_cache,
video_manager,
None, // No skipping during export
);
// Buffer specs for layer rendering
@@ -1133,7 +1132,6 @@ pub fn render_frame_to_gpu_rgba(
base_transform,
image_cache,
video_manager,
None, // No skipping during export
);
// Buffer specs for layer rendering
@@ -1887,10 +1887,9 @@ impl EditorApp {
let new_shape_ids: Vec<Uuid> = shapes.iter().map(|s| s.id).collect();
let kf = vector_layer.ensure_keyframe_at(self.playback_time);
for shape in shapes {
kf.shapes.push(shape);
}
// TODO: DCEL - paste shapes disabled during migration
// (was: push shapes into kf.shapes)
let _ = (vector_layer, shapes);
// Select pasted shapes
self.selection.clear_shapes();
@@ -2098,11 +2097,9 @@ impl EditorApp {
_ => return,
};
for split in &region_sel.splits {
vector_layer.remove_shape_from_keyframe(&split.inside_shape_id, region_sel.time);
vector_layer.remove_shape_from_keyframe(&split.outside_shape_id, region_sel.time);
vector_layer.add_shape_to_keyframe(split.original_shape.clone(), region_sel.time);
}
// TODO: DCEL - region selection revert disabled during migration
// (was: remove/add_shape_from/to_keyframe for splits)
let _ = vector_layer;
selection.clear();
}
@@ -2626,7 +2623,7 @@ impl EditorApp {
let mut test_clip = VectorClip::new(&clip_name, 400.0, 400.0, 5.0);
// Create a layer with some shapes
let mut layer = VectorLayer::new("Shapes");
let layer = VectorLayer::new("Shapes");
// Create a red circle shape
let circle_path = Circle::new((100.0, 100.0), 50.0).to_path(0.1);
@@ -2638,10 +2635,9 @@ impl EditorApp {
let mut rect_shape = Shape::new(rect_path);
rect_shape.fill_color = Some(ShapeColor::rgb(0, 0, 255));
// Add shapes to keyframe at time 0.0
let kf = layer.ensure_keyframe_at(0.0);
kf.shapes.push(circle_shape);
kf.shapes.push(rect_shape);
// TODO: DCEL - test shape creation disabled during migration
// (was: push shapes into kf.shapes)
let _ = (circle_shape, rect_shape);
// Add the layer to the clip
test_clip.layers.add_root(AnyLayer::Vector(layer));
@@ -2664,14 +2660,11 @@ impl EditorApp {
if let Some(layer_id) = self.active_layer_id {
let document = self.action_executor.document();
// Determine which selected objects are shape instances vs clip instances
let mut shape_ids = Vec::new();
let _shape_ids: Vec<uuid::Uuid> = Vec::new();
let mut clip_ids = Vec::new();
if let Some(AnyLayer::Vector(vl)) = document.get_layer(&layer_id) {
for &id in self.selection.shape_instances() {
if vl.get_shape_in_keyframe(&id, self.playback_time).is_some() {
shape_ids.push(id);
}
}
// TODO: DCEL - shape instance lookup disabled during migration
// (was: get_shape_in_keyframe to check which selected objects are shapes)
for &id in self.selection.clip_instances() {
if vl.clip_instances.iter().any(|ci| ci.id == id) {
clip_ids.push(id);
@@ -3555,34 +3548,10 @@ impl EditorApp {
// Get image dimensions
let (width, height) = asset_info.dimensions.unwrap_or((100.0, 100.0));
// Get document center position
let doc = self.action_executor.document();
let center_x = doc.width / 2.0;
let center_y = doc.height / 2.0;
// Create a rectangle path at the origin (position handled by transform)
use kurbo::BezPath;
let mut path = BezPath::new();
path.move_to((0.0, 0.0));
path.line_to((width, 0.0));
path.line_to((width, height));
path.line_to((0.0, height));
path.close_path();
// Create shape with image fill (references the ImageAsset)
use lightningbeam_core::shape::Shape;
let shape = Shape::new(path).with_image_fill(asset_info.clip_id);
// Set position on shape directly
let shape = shape.with_position(center_x, center_y);
// Create and execute action
let action = lightningbeam_core::actions::AddShapeAction::new(
layer_id,
shape,
self.playback_time,
);
let _ = self.action_executor.execute(Box::new(action));
// TODO: Image fills on DCEL faces are a separate feature.
// For now, just log a message.
let _ = (layer_id, width, height);
eprintln!("Image drop to canvas not yet supported with DCEL backend");
} else {
// For clips, create a clip instance
let mut clip_instance = ClipInstance::new(asset_info.clip_id)
@@ -10,7 +10,6 @@ use eframe::egui;
use lightningbeam_core::clip::{AudioClipType, VectorClip};
use lightningbeam_core::document::Document;
use lightningbeam_core::layer::AnyLayer;
use lightningbeam_core::shape::ShapeColor;
use std::collections::{HashMap, HashSet};
use uuid::Uuid;
@@ -413,8 +412,7 @@ fn generate_midi_thumbnail(
/// Generate a 64x64 RGBA thumbnail for a vector clip
/// Renders frame 0 of the clip using tiny-skia for software rendering
fn generate_vector_thumbnail(clip: &VectorClip, bg_color: egui::Color32) -> Vec<u8> {
use kurbo::PathEl;
use tiny_skia::{Paint, PathBuilder, Pixmap, Transform as TsTransform};
use tiny_skia::Pixmap;
let size = THUMBNAIL_SIZE as usize;
let mut pixmap = Pixmap::new(THUMBNAIL_SIZE, THUMBNAIL_SIZE)
@@ -431,94 +429,14 @@ fn generate_vector_thumbnail(clip: &VectorClip, bg_color: egui::Color32) -> Vec<
// Calculate scale to fit clip dimensions into thumbnail
let scale_x = THUMBNAIL_SIZE as f64 / clip.width.max(1.0);
let scale_y = THUMBNAIL_SIZE as f64 / clip.height.max(1.0);
let scale = scale_x.min(scale_y) * 0.9; // 90% to leave a small margin
// Center offset
let offset_x = (THUMBNAIL_SIZE as f64 - clip.width * scale) / 2.0;
let offset_y = (THUMBNAIL_SIZE as f64 - clip.height * scale) / 2.0;
let _scale = scale_x.min(scale_y) * 0.9; // 90% to leave a small margin
// Iterate through layers and render shapes
for layer_node in clip.layers.iter() {
if let AnyLayer::Vector(vector_layer) = &layer_node.data {
// Render each shape at time 0.0 (frame 0)
for shape in vector_layer.shapes_at_time(0.0) {
// Get the path (frame 0)
let kurbo_path = shape.path();
// Convert kurbo BezPath to tiny-skia PathBuilder
let mut path_builder = PathBuilder::new();
for el in kurbo_path.iter() {
match el {
PathEl::MoveTo(p) => {
let x = (p.x * scale + offset_x) as f32;
let y = (p.y * scale + offset_y) as f32;
path_builder.move_to(x, y);
}
PathEl::LineTo(p) => {
let x = (p.x * scale + offset_x) as f32;
let y = (p.y * scale + offset_y) as f32;
path_builder.line_to(x, y);
}
PathEl::QuadTo(p1, p2) => {
let x1 = (p1.x * scale + offset_x) as f32;
let y1 = (p1.y * scale + offset_y) as f32;
let x2 = (p2.x * scale + offset_x) as f32;
let y2 = (p2.y * scale + offset_y) as f32;
path_builder.quad_to(x1, y1, x2, y2);
}
PathEl::CurveTo(p1, p2, p3) => {
let x1 = (p1.x * scale + offset_x) as f32;
let y1 = (p1.y * scale + offset_y) as f32;
let x2 = (p2.x * scale + offset_x) as f32;
let y2 = (p2.y * scale + offset_y) as f32;
let x3 = (p3.x * scale + offset_x) as f32;
let y3 = (p3.y * scale + offset_y) as f32;
path_builder.cubic_to(x1, y1, x2, y2, x3, y3);
}
PathEl::ClosePath => {
path_builder.close();
}
}
}
if let Some(ts_path) = path_builder.finish() {
// Draw fill if present
if let Some(fill_color) = &shape.fill_color {
let mut paint = Paint::default();
paint.set_color(shape_color_to_tiny_skia(fill_color));
paint.anti_alias = true;
pixmap.fill_path(
&ts_path,
&paint,
tiny_skia::FillRule::Winding,
TsTransform::identity(),
None,
);
}
// Draw stroke if present
if let Some(stroke_color) = &shape.stroke_color {
if let Some(stroke_style) = &shape.stroke_style {
let mut paint = Paint::default();
paint.set_color(shape_color_to_tiny_skia(stroke_color));
paint.anti_alias = true;
let stroke = tiny_skia::Stroke {
width: (stroke_style.width * scale) as f32,
..Default::default()
};
pixmap.stroke_path(
&ts_path,
&paint,
&stroke,
TsTransform::identity(),
None,
);
}
}
}
}
// TODO: DCEL - thumbnail shape rendering disabled during migration
// (was: shapes_at_time(0.0) to render shape fills/strokes into thumbnail)
let _ = vector_layer;
}
}
@@ -541,11 +459,6 @@ fn generate_vector_thumbnail(clip: &VectorClip, bg_color: egui::Color32) -> Vec<
rgba
}
/// Convert ShapeColor to tiny_skia Color
fn shape_color_to_tiny_skia(color: &ShapeColor) -> tiny_skia::Color {
tiny_skia::Color::from_rgba8(color.r, color.g, color.b, color.a)
}
/// Generate a simple effect thumbnail with a pink gradient
#[allow(dead_code)]
fn generate_effect_thumbnail() -> Vec<u8> {
@@ -114,84 +114,9 @@ impl InfopanelPane {
if let Some(layer) = document.get_layer(&layer_id) {
if let AnyLayer::Vector(vector_layer) = layer {
// Gather values from all selected instances
let mut first = true;
for instance_id in &info.instance_ids {
if let Some(shape) = vector_layer.get_shape_in_keyframe(instance_id, *shared.playback_time) {
info.shape_ids.push(*instance_id);
if first {
// First shape - set initial values
info.x = Some(shape.transform.x);
info.y = Some(shape.transform.y);
info.rotation = Some(shape.transform.rotation);
info.scale_x = Some(shape.transform.scale_x);
info.scale_y = Some(shape.transform.scale_y);
info.skew_x = Some(shape.transform.skew_x);
info.skew_y = Some(shape.transform.skew_y);
info.opacity = Some(shape.opacity);
// Get shape properties
info.fill_color = Some(shape.fill_color);
info.stroke_color = Some(shape.stroke_color);
info.stroke_width = shape
.stroke_style
.as_ref()
.map(|s| Some(s.width))
.unwrap_or(Some(1.0));
first = false;
} else {
// Check if values differ (set to None if mixed)
if info.x != Some(shape.transform.x) {
info.x = None;
}
if info.y != Some(shape.transform.y) {
info.y = None;
}
if info.rotation != Some(shape.transform.rotation) {
info.rotation = None;
}
if info.scale_x != Some(shape.transform.scale_x) {
info.scale_x = None;
}
if info.scale_y != Some(shape.transform.scale_y) {
info.scale_y = None;
}
if info.skew_x != Some(shape.transform.skew_x) {
info.skew_x = None;
}
if info.skew_y != Some(shape.transform.skew_y) {
info.skew_y = None;
}
if info.opacity != Some(shape.opacity) {
info.opacity = None;
}
// Check shape properties
// Compare fill colors - set to None if mixed
if let Some(current_fill) = &info.fill_color {
if *current_fill != shape.fill_color {
info.fill_color = None;
}
}
// Compare stroke colors - set to None if mixed
if let Some(current_stroke) = &info.stroke_color {
if *current_stroke != shape.stroke_color {
info.stroke_color = None;
}
}
let stroke_w = shape
.stroke_style
.as_ref()
.map(|s| s.width)
.unwrap_or(1.0);
if info.stroke_width != Some(stroke_w) {
info.stroke_width = None;
}
}
}
}
// TODO: DCEL - shape property gathering disabled during migration
// (was: get_shape_in_keyframe to gather transform/fill/stroke properties)
let _ = vector_layer;
}
}
}
File diff suppressed because it is too large Load Diff