The Sweep class creates 3D shapes by sweeping a 2D profile along a 3D path. This powerful technique enables creation of pipes, tubes, rails, and complex extruded forms that follow custom trajectories.
Array of points defining the 2D profile to be swept. Minimum 3 points required. Profile should be defined on a plane perpendicular to the initial path direction.
profile: [ new Vector3(-0.5, 0, -0.5), new Vector3(0.5, 0, -0.5), new Vector3(0.5, 0, 0.5), new Vector3(-0.5, 0, 0.5)]
import { Sweep, Vector3 } from 'opengeometry';// Sweep without end caps (open tube)const openTube = new Sweep({ path: [ new Vector3(0, 0, 0), new Vector3(5, 0, 0), new Vector3(5, 5, 0) ], profile: [ new Vector3(-0.5, 0, -0.5), new Vector3(0.5, 0, -0.5), new Vector3(0.5, 0, 0.5), new Vector3(-0.5, 0, 0.5) ], color: 0xe74c3c, capStart: false, // No start cap capEnd: false // No end cap});
The sweep operation positions the profile at each path point and connects adjacent profiles:Rust Implementation:/workspace/source/main/opengeometry/src/primitives/sweep.rs:92-99
The sweep validates path and profile requirements:Source:/workspace/source/main/opengeometry/src/shapes/sweep.ts:75-87
validateOptions() { if (!this.options) { throw new Error("Options are not defined for Sweep"); } if (this.options.path.length < 2) { throw new Error("Sweep path requires at least 2 points."); } if (this.options.profile.length < 3) { throw new Error("Sweep profile requires at least 3 points."); }}
When capStart or capEnd is true, the sweep operation adds triangulated faces at the ends:Source:/workspace/source/main/opengeometry/src/shapes/sweep.ts:95-96
Profile Orientation: Define the profile on a plane perpendicular to the initial path direction. For paths starting along the Y-axis, define profiles on the XZ plane.
Path Smoothness: Sharp angles in the path may cause geometry artifacts. For smoother results, use more path points with gradual direction changes.
Profile Complexity: Complex profiles with many points will generate more geometry. Balance profile detail with performance requirements.
Closed Profiles: For hollow tubes, ensure the profile forms a closed loop by making the first and last points identical.