11---
22title : ' Extrude'
3- description : ' Transform 2D polygons into 3D geometry by extruding them along a vertical axis '
3+ description : ' Create closed solids by extruding a face-like BRep profile through the kernel '
44icon : ' cubes'
55---
66
77## Overview
88
9- The extrude operation transforms a 2D polygon into a 3D solid by extending it along a height vector. This creates a prismatic geometry with the original polygon as the base, vertical side faces connecting the base to the top, and a parallel top face.
9+ OpenGeometry's production extrusion path is BRep-first. The kernel extrudes a face or wire into a
10+ closed solid while preserving loop structure, which means concave profiles and holes are supported.
1011
11- ## Function Signature
12+ In the Three.js API, the most common public entrypoint is:
1213
13- ### extrude_polygon_by_buffer_geometry
14-
15- ``` rust
16- pub fn extrude_polygon_by_buffer_geometry (geom_buf : BaseGeometry , height : f64 ) -> Geometry
14+ ``` ts
15+ const solid = polygon .extrude (height );
1716```
1817
19- Extrudes a polygon defined by buffer geometry to create a 3D mesh .
18+ That path uses the same kernel face-extrusion primitive described on this page .
2019
21- <ParamField path = " geom_buf" type = " BaseGeometry" required >
22- The base geometry containing the polygon vertices to extrude . Must have at least 3 vertices to form a valid polygon .
23- </ ParamField >
20+ ## Three.js API
2421
25- <ParamField path = " height" type = " f64" required >
26- The extrusion height in the vertical (Y ) direction . Positive values extrude upward , negative values extrude downward .
27- </ ParamField >
22+ ### polygon.extrude()
2823
29- ### extrude_brep_face
24+ Extrudes a ` Polygon ` and returns a renderable [ ` Solid ` ] ( /api/shapes/solid ) .
3025
31- ```rust
32- pub fn extrude_brep_face ( brep_face : Brep , height : f64 ) -> Brep
26+ ``` ts
27+ const solid = polygon . extrude ( height );
3328```
3429
35- Extrudes a BREP ( Boundary Representation ) face to create a new BREP object with topological information .
30+ ### Solid.extrude()
3631
37- <ParamField path = " brep_face" type = " Brep" required >
38- The BREP face to extrude . Must contain at least 3 vertices .
39- </ ParamField >
32+ Extrudes a face-like BRep source and wraps the result as a ` Solid ` .
4033
41- <ParamField path = " height" type = " f64" required >
42- The extrusion height in the Y direction .
43- </ ParamField >
44-
45- ## Return Type
46-
47- ### Geometry Structure
48-
49- The `extrude_polygon_by_buffer_geometry ` function returns a `Geometry ` object with :
34+ ``` ts
35+ const solid = Solid .extrude (source , height , options );
36+ ```
5037
51- - * * vertices ** : Complete vertex list including both base and top vertices
52- - * * edges ** : All edges forming the bottom face , top face , and vertical connections
53- - * * faces ** : Bottom face , all side faces (one per edge of the original polygon ), and top face
38+ ### extrudeBrepFace()
5439
55- ### Brep Structure
40+ Low-level helper that calls the wasm export directly and returns serialized BRep JSON.
5641
57- The ` extrude_brep_face ` function returns a ` Brep ` using OpenGeometry ' s current half - edge topology
58- schema ( see [ BRep ]( / concepts / brep )) .
42+ ``` ts
43+ import { extrudeBrepFace } from " opengeometry " ;
5944
60- At a high level , the result contains the base face , the top face , and side faces , and it is marked
61- as a closed shell .
45+ const brepSerialized = extrudeBrepFace ( source , height );
46+ ```
6247
63- ## How It Works
48+ Accepted ` source ` forms:
6449
65- 1 . * * Winding Order ** : The input vertices are sorted to counter - clockwise ( CCW ) order to ensure consistent face normals
66- 2 . * * Bottom Face ** : Creates edges and a face from the original polygon vertices
67- 3 . * * Vertical Edges ** : Generates new vertices offset by the height vector ( 0 , height , 0 ) and connects them to base vertices
68- 4 . * * Side Faces ** : Creates quadrilateral faces connecting each edge of the base to the corresponding edge on top
69- 5 . * * Top Face ** : Constructs the top face with reversed vertex order for correct normal orientation
50+ - Serialized local BRep JSON
51+ - Parsed BRep object
52+ - Another wrapper exposing ` getLocalBrepSerialized() `
53+ - Another wrapper exposing ` getLocalBrepData() `
54+ - Another wrapper exposing ` getBrepSerialized() ` or ` getBrepData() `
7055
71- ## Code Examples
56+ ## Rust API
7257
73- ### Basic Extrusion
58+ ### extrude_brep_face
7459
7560``` rust
76- use opengeometry :: {
77- geometry :: basegeometry :: BaseGeometry ,
78- operations :: extrude :: extrude_polygon_by_buffer_geometry ,
79- };
80- use openmaths :: Vector3 ;
81-
82- // Create a square base polygon
83- let vertices = vec! [
84- Vector3 :: new (0.0 , 0.0 , 0.0 ),
85- Vector3 :: new (1.0 , 0.0 , 0.0 ),
86- Vector3 :: new (1.0 , 0.0 , 1.0 ),
87- Vector3 :: new (0.0 , 0.0 , 1.0 ),
88- ];
61+ pub fn extrude_brep_face (brep_face : Brep , height : f64 ) -> Brep
62+ ```
8963
90- let base_geom = BaseGeometry :: from_vertices ( vertices );
64+ This is implemented in :
9165
92- // Extrude 2 units upward
93- let extruded = extrude_polygon_by_buffer_geometry (base_geom , 2.0 );
66+ `main / opengeometry / src / operations / extrude . rs`
9467
95- // Result: A rectangular box with base at Y=0 and top at Y=2
68+ ## Behavior
69+
70+ - The kernel extrudes along the current local Y direction .
71+ - The source must contain a face - like profile , wire , or at minimum a usable point loop .
72+ - Outer loops and hole loops are preserved , so polygons with holes stay hole - aware after extrusion .
73+ - Concave profiles are supported .
74+ - `height ` must be finite and non - zero .
75+ - The result is a closed - shell BRep suitable for boolean operations .
76+
77+ ## Usage Examples
78+
79+ ### Polygon to solid workflow
80+
81+ ```ts
82+ import * as THREE from " three" ;
83+ import { OpenGeometry , Polygon , Vector3 } from " opengeometry" ;
84+
85+ await OpenGeometry . create ({ wasmURL: " /opengeometry_bg.wasm" });
86+
87+ const scene = new THREE . Scene ();
88+
89+ const wallProfile = new Polygon ({
90+ vertices : [
91+ new Vector3 (- 2.2 , 0 , - 0.18 ),
92+ new Vector3 (2.2 , 0 , - 0.18 ),
93+ new Vector3 (2.2 , 0 , 0.18 ),
94+ new Vector3 (- 2.2 , 0 , 0.18 ),
95+ ],
96+ color : 0x60a5fa ,
97+ });
98+
99+ const openingProfile = new Polygon ({
100+ vertices : [
101+ new Vector3 (- 0.7 , 0 , - 0.34 ),
102+ new Vector3 (0.9 , 0 , - 0.34 ),
103+ new Vector3 (0.9 , 0 , 0.34 ),
104+ new Vector3 (- 0.7 , 0 , 0.34 ),
105+ ],
106+ color : 0xf97316 ,
107+ });
108+
109+ const wall = wallProfile. extrude (2.8 );
110+ const opening = openingProfile. extrude (1.35 );
111+ opening . setTranslation (new Vector3 (0 , 0.85 , 0 ));
112+
113+ const cut = wall . subtract (opening , {
114+ outline : true ,
115+ kernel : { mergeCoplanarFaces: true },
116+ });
117+
118+ scene . add (cut );
96119```
97120
98- ### Extruding a Triangle
99-
100- ``` rust
101- use opengeometry :: operations :: extrude :: extrude_polygon_by_buffer_geometry;
102- use opengeometry :: geometry :: basegeometry :: BaseGeometry ;
103- use openmaths :: Vector3 ;
121+ ### Direct low-level helper
104122
105- // Create a triangular base
106- let triangle = vec! [
107- Vector3 :: new (0.0 , 0.0 , 0.0 ),
108- Vector3 :: new (1.0 , 0.0 , 0.0 ),
109- Vector3 :: new (0.5 , 0.0 , 1.0 ),
110- ];
123+ ``` ts
124+ import { Solid , extrudeBrepFace } from " opengeometry" ;
111125
112- let base_geom = BaseGeometry :: from_vertices (triangle );
113- let prism = extrude_polygon_by_buffer_geometry (base_geom , 1.5 );
126+ const extrudedBrep = extrudeBrepFace (localFaceBrepSerialized , 3.0 );
114127
115- // Result: A triangular prism
128+ const solid = new Solid ({
129+ brep: extrudedBrep ,
130+ color: 0x10b981 ,
131+ });
116132```
117133
118- ### Using BREP Extrusion
134+ ### Rust kernel usage
119135
120136``` rust
121137use opengeometry :: {
@@ -125,7 +141,6 @@ use opengeometry::{
125141use openmaths :: Vector3 ;
126142use uuid :: Uuid ;
127143
128- // Build a single face B-Rep (a surface) with BrepBuilder.
129144let mut builder = BrepBuilder :: new (Uuid :: new_v4 ());
130145builder . add_vertices (& [
131146 Vector3 :: new (0.0 , 0.0 , 0.0 ),
@@ -134,50 +149,19 @@ builder.add_vertices(&[
134149 Vector3 :: new (0.0 , 0.0 , 1.0 ),
135150]);
136151builder . add_face (& [0 , 1 , 2 , 3 ], & []). unwrap ();
137- let brep_face = builder . build (). unwrap ();
152+ let profile = builder . build (). unwrap ();
138153
139- // Extrude to create a 3D BREP with topological data
140- let extruded_brep = extrude_brep_face (brep_face , 3.0 );
141-
142- // Access topological information
143- println! (" Vertices: {}" , extruded_brep . get_vertex_count ());
144- println! (" Edges: {}" , extruded_brep . get_edge_count ());
145- println! (" Faces: {}" , extruded_brep . get_face_count ());
154+ let solid = extrude_brep_face (profile , 3.0 );
155+ assert! (solid . shells. iter (). any (| shell | shell . is_closed));
146156```
147157
148- ## Visual Examples
149-
150- ```
151- Input Polygon (Top View): Extruded Result (3D):
152-
153- v3────v2 v7────v6
154- │ │ ╱│ ╱│
155- │ │ +height ╱ │ ╱ │
156- v0────v1 ────────> v4─┼─v5 │
157- │ v3──┼─v2
158- │╱ │╱
159- v0────v1
160- ```
161-
162- ## Implementation Details
163-
164- ### Source Location
165-
166- ` main/opengeometry/src/operations/extrude.rs `
167-
168- ### Edge Cases
169-
170- - ** Minimum Vertices** : Polygons with fewer than 3 vertices are technically invalid, but the function proceeds (returns incomplete geometry)
171- - ** Direction** : Currently extrudes only in the Y direction; future versions may support arbitrary extrusion vectors
172- - ** Winding Order** : Automatically corrects to CCW to ensure proper face orientation
173-
174158## See Also
175159
176- - [ Sweep] ( /api/operations/sweep ) - Extrude a profile along an arbitrary path
177- - [ Offset] ( /api/operations/offset ) - Create parallel offset curves
178- - [ Triangulate] ( /api/operations/triangulate ) - Convert polygons to triangle meshes
160+ - [ Polygon] ( /api/shapes/polygon )
161+ - [ Solid] ( /api/shapes/solid )
162+ - [ Sweep] ( /api/operations/sweep )
163+ - [ Boolean operations] ( /api/operations/boolean-operations )
179164
180165## Live demo
181166
182- There is no dedicated extrude demo page yet. Start from the demo index:
183- [ OpenGeometry demos] ( https://demo.opengeometry.io/ ) .
167+ - [ Extruded boolean operations demo] ( https://demo.opengeometry.io/operations/extruded-boolean-operations.html )
0 commit comments