tess-extrude 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Evangelos Karatzaferis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # tess-extrude
2
+
3
+ Extrude 2D polygon outlines into `THREE.BufferGeometry` using poly2tri Delaunay tessellation.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install tess-extrude
9
+ # three is a peer dependency
10
+ npm install three
11
+ ```
12
+
13
+ ## Quick Start — points input
14
+
15
+ ```typescript
16
+ import * as THREE from 'three';
17
+ import { extrude } from 'tess-extrude';
18
+
19
+ const points = [
20
+ { x: 0, y: 0 },
21
+ { x: 100, y: 0 },
22
+ { x: 100, y: 100 },
23
+ { x: 0, y: 100 },
24
+ ];
25
+
26
+ const geometry = extrude({ type: 'points', points });
27
+ if (geometry) {
28
+ const mesh = new THREE.Mesh(geometry, new THREE.MeshStandardMaterial());
29
+ scene.add(mesh);
30
+ }
31
+ ```
32
+
33
+ ## Quick Start — SVG input
34
+
35
+ ```typescript
36
+ import { extrude } from 'tess-extrude';
37
+
38
+ // base64-encoded SVG string (data URI prefix optional)
39
+ const geometry = extrude({ type: 'svg', data: base64SvgString }, { depth: 30 });
40
+ ```
41
+
42
+ > **Note:** SVG input requires a browser environment (SVGLoader uses `DOMParser` internally).
43
+
44
+ ## API
45
+
46
+ ### `extrude(input, options?)`
47
+
48
+ | Parameter | Type | Description |
49
+ |-----------|------|-------------|
50
+ | `input` | `PointInput \| SVGInput` | Shape to extrude |
51
+ | `options` | `Partial<ExtrudeOptions>` | See options table |
52
+
53
+ Returns `THREE.BufferGeometry | null`. Never throws — returns `null` for degenerate input or triangulation failure.
54
+
55
+ ### Input types
56
+
57
+ ```typescript
58
+ // Raw polygon points
59
+ { type: 'points'; points: Point2D[] }
60
+
61
+ // base64-encoded SVG string
62
+ { type: 'svg'; data: string }
63
+ ```
64
+
65
+ ### Options
66
+
67
+ | Option | Type | Default | Description |
68
+ |--------|------|---------|-------------|
69
+ | `depth` | `number` | `20` | Extrusion depth along Z axis |
70
+ | `depthSegments` | `number` | `4` | Number of side-wall segments along depth |
71
+ | `capDensity` | `number` | `5` | Interior Steiner point density (1–20). Higher = more triangles in caps |
72
+ | `edgeSubdivisions` | `number` | `2` | Subdivisions per boundary edge |
73
+
74
+ ### Utility exports
75
+
76
+ ```typescript
77
+ import { simplifyPath, deduplicatePoints, subdivideBoundary, ensureCCW } from 'tess-extrude';
78
+ ```
79
+
80
+ | Function | Signature | Description |
81
+ |----------|-----------|-------------|
82
+ | `simplifyPath` | `(points, tolerance) => Point2D[]` | Douglas-Peucker path simplification |
83
+ | `deduplicatePoints` | `(points, eps?) => Point2D[]` | Remove consecutive near-duplicate points |
84
+ | `subdivideBoundary` | `(points, subdivisions) => Point2D[]` | Subdivide each edge |
85
+ | `ensureCCW` | `(points) => Point2D[]` | Ensure counter-clockwise winding |
86
+
87
+ ## Memory management
88
+
89
+ Dispose of geometries when no longer needed to free GPU memory:
90
+
91
+ ```typescript
92
+ geometry.dispose();
93
+ ```
94
+
95
+ For SVG input with multiple paths, all paths are merged into a single geometry automatically.
96
+
97
+ ## Browser / Node compatibility
98
+
99
+ | Feature | Browser | Node |
100
+ |---------|---------|------|
101
+ | Points input | ✅ | ✅ |
102
+ | SVG input | ✅ | ❌ (requires DOMParser) |
103
+
104
+ ## Development
105
+
106
+ ```bash
107
+ npm install
108
+ npm run dev # demo at http://localhost:5173
109
+ npm run build # build library to dist/
110
+ npm run test # run vitest tests
111
+ npm run lint # eslint
112
+ ```
@@ -0,0 +1,61 @@
1
+ import * as THREE from 'three';
2
+
3
+ /** Remove consecutive near-duplicate points (including last≈first wrap). */
4
+ export declare function deduplicatePoints(points: Point2D[], eps?: number): Point2D[];
5
+
6
+ /**
7
+ * Ensure the polygon winding is counter-clockwise (positive signed area via
8
+ * the shoelace formula). poly2tri requires CCW contours.
9
+ */
10
+ export declare function ensureCCW(points: Point2D[]): Point2D[];
11
+
12
+ /**
13
+ * Extrude a 2D shape into a THREE.BufferGeometry.
14
+ *
15
+ * Accepts raw polygon points or a base64-encoded SVG.
16
+ * Returns `null` (never throws) on degenerate input or triangulation failure.
17
+ */
18
+ export declare function extrude(input: ExtrudeInput, options?: Partial<ExtrudeOptions>): THREE.BufferGeometry | null;
19
+
20
+ export declare type ExtrudeInput = PointInput | SVGInput;
21
+
22
+ export declare interface ExtrudeOptions {
23
+ /** Extrusion depth. Default: 20 */
24
+ depth: number;
25
+ /** Number of depth segments for side walls. Default: 4 */
26
+ depthSegments: number;
27
+ /** Cap triangulation density (1–20). Default: 5 */
28
+ capDensity: number;
29
+ /** Number of edge subdivisions for boundary. Default: 2 */
30
+ edgeSubdivisions: number;
31
+ }
32
+
33
+ export declare interface Point2D {
34
+ x: number;
35
+ y: number;
36
+ }
37
+
38
+ export declare interface PointInput {
39
+ type: 'points';
40
+ points: Point2D[];
41
+ }
42
+
43
+ /**
44
+ * Iterative Douglas-Peucker simplification.
45
+ * Avoids recursion and array slicing for better performance on large inputs.
46
+ */
47
+ export declare function simplifyPath(points: Point2D[], tolerance: number): Point2D[];
48
+
49
+ /**
50
+ * Subdivide each boundary edge into `subdivisions` equal segments.
51
+ * Returns a pre-allocated flat array of the new boundary points.
52
+ */
53
+ export declare function subdivideBoundary(points: Point2D[], subdivisions: number): Point2D[];
54
+
55
+ export declare interface SVGInput {
56
+ type: 'svg';
57
+ /** base64-encoded SVG string, with or without data URI prefix */
58
+ data: string;
59
+ }
60
+
61
+ export { }