Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions node-graph/nodes/vector/src/vector_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,10 +785,26 @@ async fn extrude(_: impl Ctx, mut source: Table<Vector>, direction: DVec2, joini
}

#[node_macro::node(category("Vector: Modifier"), path(core_types::vector))]
async fn box_warp(_: impl Ctx, content: Table<Vector>, #[expose] rectangle: Table<Vector>) -> Table<Vector> {
async fn box_warp(_: impl Ctx, content: Table<Vector>, #[expose] rectangle: Table<Vector>, #[expose] combined: bool) -> Table<Vector> {
let Some((target, target_transform)) = rectangle.get(0).map(|rect| (rect.element, rect.transform)) else {
return content;
};

// Compute combined bounding box if needed
let combined_bbox = if combined {
content.iter().fold(None, |acc: Option<[DVec2; 2]>, row| {
let bbox = row.element.bounding_box_with_transform(row.transform);
match (acc, bbox) {
(None, Some(bbox)) => Some(bbox),
(Some([min, max]), Some([bbox_min, bbox_max])) => {
Some([min.min(bbox_min), max.max(bbox_max)])
}
(acc, None) => acc,
}
})
} else {
None
};

content
.into_iter()
Expand All @@ -797,7 +813,7 @@ async fn box_warp(_: impl Ctx, content: Table<Vector>, #[expose] rectangle: Tabl
let vector = row.element;

// Get the bounding box of the source vector geometry
let source_bbox = vector.bounding_box_with_transform(transform).unwrap_or([DVec2::ZERO, DVec2::ONE]);
let source_bbox = combined_bbox.unwrap_or_else(|| vector.bounding_box_with_transform(transform).unwrap_or([DVec2::ZERO, DVec2::ONE]));

// Extract first 4 points from target shape to form the quadrilateral
// Apply the target's transform to get points in world space
Expand Down