okgeometry-api 0.2.3 → 0.2.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "okgeometry-api",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Geometry engine API for AEC applications — NURBS, meshes, booleans, intersections. Powered by Rust/WASM.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/wasm/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # OkGeometryCore
2
+
3
+ A production-grade geometry engine written in Rust, compiled to WebAssembly. Built for [OkNodes](https://orkestra.online), a visual programming tool for the AEC (Architecture, Engineering, Construction) industry.
4
+
5
+ ## Features
6
+
7
+ ### Mesh Primitives
8
+ - Box, Cylinder, Sphere, Prism, Cone, Torus
9
+
10
+ ### Mesh Operations
11
+ - **Transforms** - translate, rotate, scale, mirror, arbitrary matrix
12
+ - **Extrude** - linear extrusion with optional end caps
13
+ - **Loft** - surface generation between multiple curves
14
+ - **Sweep** - curve along path
15
+ - **Boolean** - union, intersection, subtraction (~95% reliable on manifold meshes)
16
+ - **Subdivision** - Catmull-Clark (quad meshes) and Loop (triangle meshes)
17
+ - **Offset / Shell** - inward/outward mesh offset
18
+ - **Bevel / Chamfer** - flat bevel on all edges or selected edges
19
+ - **Triangulation** - ear clipping and fan triangulation
20
+
21
+ ### Curve Primitives
22
+ - Line, Arc, Circle, Polyline, Polycurve (mixed segments)
23
+
24
+ ### Curve Operations
25
+ - Evaluate, tangent, length, closest point, bounds
26
+ - Chamfer corners, fillet corners (arc), offset polyline
27
+
28
+ ### Intersection
29
+ - Line-Line, Line-Plane, Line-Circle, Circle-Circle
30
+ - Ray-Mesh (BVH-accelerated), closest point on mesh
31
+
32
+ ### Spatial Indexing
33
+ - BVH (Bounding Volume Hierarchy) for O(log n) ray casting and proximity queries
34
+
35
+ ### I/O
36
+ - OBJ import/export
37
+
38
+ ## Architecture
39
+
40
+ ```
41
+ OkNodes (TypeScript)
42
+ | ArrayBuffer / TypedArray
43
+ v
44
+ OkGeometryCore (Rust -> WASM)
45
+ |- math/ Vector3, Matrix4, Quaternion, Plane, Ray, AABB
46
+ |- curves/ Line, Arc, Circle, Polyline, Polycurve
47
+ |- intersection/ Curve-curve intersections
48
+ |- mesh/ Half-edge data structure, primitives
49
+ |- ops/ Boolean, extrude, loft, sweep, subdivide, bevel...
50
+ |- spatial/ BVH, ray casting, closest point
51
+ |- io/ OBJ format
52
+ ```
53
+
54
+ The engine uses an **index-based half-edge mesh** data structure for cache-friendly traversal and easy WASM serialization. All data crosses the WASM boundary as flat typed arrays to minimize overhead.
55
+
56
+ ## Building
57
+
58
+ ### Prerequisites
59
+ - [Rust](https://rustup.rs/)
60
+ - [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/)
61
+
62
+ ### Build WASM
63
+ ```bash
64
+ wasm-pack build --target web
65
+ ```
66
+
67
+ ### Run tests
68
+ ```bash
69
+ cargo test
70
+ ```
71
+
72
+ ### Viewer
73
+ The `okgeometry-viewer/` directory contains interactive Three.js viewers for visual verification:
74
+
75
+ ```bash
76
+ # Serve the viewer directory with any static file server, e.g.:
77
+ npx serve okgeometry-viewer
78
+ ```
79
+
80
+ Available viewers:
81
+ - **Curves** - Line, Circle, Arc, Polyline visualization
82
+ - **Intersections** - All curve-curve intersection scenarios
83
+ - **Meshes** - Primitives, wireframe, OBJ import/export
84
+ - **Booleans** - Union, intersection, subtraction with position controls
85
+ - **Subdivision** - Catmull-Clark and Loop with iteration slider
86
+ - **Ray Casting** - Interactive ray cast and closest point queries
87
+ - **Bevel / Chamfer** - Flat bevel on box, cylinder, prism
88
+
89
+ ## Dependencies
90
+
91
+ | Crate | Purpose |
92
+ |-------|---------|
93
+ | `wasm-bindgen` | Rust-WASM interop |
94
+ | `js-sys` / `web-sys` | Browser API access |
95
+ | `robust` | Exact geometric predicates (orient2d, orient3d, incircle) |
96
+ | `spade` | Constrained Delaunay triangulation |
97
+ | `serde` | Serialization |
98
+ | `nalgebra` | Linear algebra (optional feature) |
99
+
100
+ ## License
101
+
102
+ Copyright Mostafa El Ayoubi / Orkestra Online. All rights reserved.
@@ -0,0 +1,286 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Get the length of an arc.
6
+ */
7
+ export function arc_length(radius: number, start_angle: number, end_angle: number): number;
8
+
9
+ /**
10
+ * Evaluate a point on an arc at parameter t ∈ [0,1].
11
+ * Returns [x, y, z].
12
+ */
13
+ export function arc_point_at(cx: number, cy: number, cz: number, nx: number, ny: number, nz: number, radius: number, start_angle: number, end_angle: number, t: number): Float64Array;
14
+
15
+ /**
16
+ * Get the circumference of a circle.
17
+ */
18
+ export function circle_length(radius: number): number;
19
+
20
+ /**
21
+ * Evaluate a point on a circle at parameter t ∈ [0,1].
22
+ * Returns [x, y, z].
23
+ */
24
+ export function circle_point_at(cx: number, cy: number, cz: number, nx: number, ny: number, nz: number, radius: number, t: number): Float64Array;
25
+
26
+ /**
27
+ * Create an arc and return sampled points
28
+ */
29
+ export function create_arc(cx: number, cy: number, cz: number, nx: number, ny: number, nz: number, radius: number, start_angle: number, end_angle: number, samples: number): Float64Array;
30
+
31
+ /**
32
+ * Create a circle and return sampled points
33
+ */
34
+ export function create_circle(cx: number, cy: number, cz: number, nx: number, ny: number, nz: number, radius: number, samples: number): Float64Array;
35
+
36
+ /**
37
+ * Create a line segment and return sampled points
38
+ */
39
+ export function create_line(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, samples: number): Float64Array;
40
+
41
+ /**
42
+ * Create a polyline and return the points
43
+ */
44
+ export function create_polyline(coords: Float64Array, samples_per_segment: number): Float64Array;
45
+
46
+ /**
47
+ * Serialize a curve to a list of points for Three.js rendering
48
+ * Returns a flat array of coordinates: [x1, y1, z1, x2, y2, z2, ...]
49
+ */
50
+ export function curve_to_points(curve_type: string, params: Float64Array, samples: number): Float64Array;
51
+
52
+ /**
53
+ * Extrude a circle and return mesh buffers
54
+ */
55
+ export function extrude_circle(cx: number, cy: number, cz: number, nx: number, ny: number, nz: number, radius: number, dx: number, dy: number, dz: number, segments: number, with_caps: boolean): Float64Array;
56
+
57
+ /**
58
+ * Extrude a line segment and return mesh buffers
59
+ */
60
+ export function extrude_line(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, dx: number, dy: number, dz: number, segments: number): Float64Array;
61
+
62
+ /**
63
+ * Extrude a polyline and return mesh buffers
64
+ */
65
+ export function extrude_polyline(coords: Float64Array, dx: number, dy: number, dz: number, segments: number, with_caps: boolean): Float64Array;
66
+
67
+ /**
68
+ * Get the length of a line segment.
69
+ */
70
+ export function line_length(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number): number;
71
+
72
+ /**
73
+ * Evaluate a point on a line segment at parameter t ∈ [0,1].
74
+ * Returns [x, y, z].
75
+ */
76
+ export function line_point_at(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, t: number): Float64Array;
77
+
78
+ /**
79
+ * Get the tangent direction of a line segment. Returns [x, y, z].
80
+ */
81
+ export function line_tangent(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number): Float64Array;
82
+
83
+ /**
84
+ * Loft between multiple circles
85
+ *
86
+ * # Parameters
87
+ * * `circle_data` - Flat array of circle definitions [cx, cy, cz, nx, ny, nz, radius, ...]
88
+ * * `segments` - Number of segments to sample along each curve
89
+ * * `with_caps` - Whether to create end caps
90
+ *
91
+ * # Returns
92
+ * Mesh buffers for the lofted surface
93
+ */
94
+ export function loft_circles(circle_data: Float64Array, segments: number, with_caps: boolean): Float64Array;
95
+
96
+ /**
97
+ * Loft between multiple polylines
98
+ *
99
+ * # Parameters
100
+ * * `polyline_data` - Flat array where each polyline is prefixed by its point count:
101
+ * [count1, x1, y1, z1, x2, y2, z2, ..., count2, x1, y1, z1, ...]
102
+ * * `segments` - Number of segments to sample along each curve
103
+ * * `with_caps` - Whether to create end caps
104
+ *
105
+ * # Returns
106
+ * Mesh buffers for the lofted surface
107
+ */
108
+ export function loft_polylines(polyline_data: Float64Array, segments: number, with_caps: boolean): Float64Array;
109
+
110
+ /**
111
+ * Perform boolean intersection on two meshes
112
+ */
113
+ export function mesh_boolean_intersection(vertex_count_a: number, buffer_a: Float64Array, vertex_count_b: number, buffer_b: Float64Array): Float64Array;
114
+
115
+ /**
116
+ * Perform boolean operation on two meshes
117
+ *
118
+ * # Parameters
119
+ * * `vertex_count_a` - Number of vertices in mesh A
120
+ * * `buffer_a` - Buffer for mesh A [vertices..., indices...]
121
+ * * `vertex_count_b` - Number of vertices in mesh B
122
+ * * `buffer_b` - Buffer for mesh B [vertices..., indices...]
123
+ * * `operation` - Operation type: "union", "intersection", or "subtraction"
124
+ *
125
+ * # Returns
126
+ * Result mesh buffer [vertices..., indices...]
127
+ */
128
+ export function mesh_boolean_operation(vertex_count_a: number, buffer_a: Float64Array, vertex_count_b: number, buffer_b: Float64Array, operation: string): Float64Array;
129
+
130
+ /**
131
+ * Perform boolean subtraction on two meshes (A - B)
132
+ */
133
+ export function mesh_boolean_subtraction(vertex_count_a: number, buffer_a: Float64Array, vertex_count_b: number, buffer_b: Float64Array): Float64Array;
134
+
135
+ /**
136
+ * Perform boolean union on two meshes
137
+ */
138
+ export function mesh_boolean_union(vertex_count_a: number, buffer_a: Float64Array, vertex_count_b: number, buffer_b: Float64Array): Float64Array;
139
+
140
+ /**
141
+ * Chamfer all edges of a primitive mesh (flat bevel)
142
+ *
143
+ * # Arguments
144
+ * * `mesh_type` - "box", "cylinder", or "prism"
145
+ * * `params` - Parameters: [width,height,depth] for box, [radius,height,segments] for cylinder/prism
146
+ * * `offset` - Chamfer offset distance
147
+ *
148
+ * # Returns
149
+ * Result mesh buffer [vertexCount, vertices..., indices...]
150
+ */
151
+ export function mesh_chamfer_all_edges(mesh_type: string, params: Float64Array, offset: number): Float64Array;
152
+
153
+ /**
154
+ * Create a box mesh and return buffers
155
+ * Returns [vertices..., indices...]
156
+ */
157
+ export function mesh_create_box(width: number, height: number, depth: number): Float64Array;
158
+
159
+ /**
160
+ * Create a cone mesh and return buffers
161
+ */
162
+ export function mesh_create_cone(radius: number, height: number, segments: number): Float64Array;
163
+
164
+ /**
165
+ * Create a cylinder mesh and return buffers
166
+ */
167
+ export function mesh_create_cylinder(radius: number, height: number, segments: number): Float64Array;
168
+
169
+ /**
170
+ * Create a prism mesh and return buffers
171
+ */
172
+ export function mesh_create_prism(radius: number, height: number, sides: number): Float64Array;
173
+
174
+ /**
175
+ * Create a sphere mesh and return buffers
176
+ */
177
+ export function mesh_create_sphere(radius: number, segments: number, rings: number): Float64Array;
178
+
179
+ /**
180
+ * Export a mesh to OBJ format
181
+ * Takes mesh buffers as input (same format as mesh_to_buffers output)
182
+ * Returns OBJ string
183
+ */
184
+ export function mesh_export_obj(vertex_count: number, buffer: Float64Array): string;
185
+
186
+ /**
187
+ * Get mesh statistics
188
+ * Returns [vertex_count, face_count, edge_count]
189
+ */
190
+ export function mesh_get_stats(vertex_count: number, buffer: Float64Array): Float64Array;
191
+
192
+ /**
193
+ * Import OBJ data and return mesh buffers
194
+ */
195
+ export function mesh_import_obj(obj_data: string): Float64Array;
196
+
197
+ /**
198
+ * Intersect two meshes, returning intersection polyline points.
199
+ * Returns: [num_polylines, n1, x,y,z,..., n2, x,y,z,...]
200
+ */
201
+ export function mesh_mesh_intersect(va_count: number, buffer_a: Float64Array, vb_count: number, buffer_b: Float64Array): Float64Array;
202
+
203
+ /**
204
+ * Intersect a mesh with a plane, returning polyline points.
205
+ * Input: vertex_count, mesh_buffer..., nx, ny, nz, d
206
+ * Returns: [num_polylines, n1, x,y,z,..., n2, x,y,z,...]
207
+ */
208
+ export function mesh_plane_intersect(vertex_count: number, buffer: Float64Array, nx: number, ny: number, nz: number, d: number): Float64Array;
209
+
210
+ /**
211
+ * Rotate a mesh around an arbitrary axis and return new buffers
212
+ * Axis is defined by (ax, ay, az), angle in radians
213
+ */
214
+ export function mesh_rotate(vertex_count: number, buffer: Float64Array, ax: number, ay: number, az: number, angle: number): Float64Array;
215
+
216
+ /**
217
+ * Scale a mesh non-uniformly and return new buffers
218
+ */
219
+ export function mesh_scale(vertex_count: number, buffer: Float64Array, sx: number, sy: number, sz: number): Float64Array;
220
+
221
+ /**
222
+ * Translate a mesh by an offset vector and return new buffers
223
+ */
224
+ export function mesh_translate(vertex_count: number, buffer: Float64Array, dx: number, dy: number, dz: number): Float64Array;
225
+
226
+ /**
227
+ * Intersect two NURBS curves.
228
+ * Returns: [num_points, x,y,z, ...]
229
+ */
230
+ export function nurbs_curve_curve_intersect(data_a: Float64Array, data_b: Float64Array): Float64Array;
231
+
232
+ /**
233
+ * Intersect a NURBS curve with a plane.
234
+ * Input: same curve format as sample_nurbs_curve + plane normal (nx,ny,nz) and d.
235
+ * Returns: [num_points, x,y,z, x,y,z, ...]
236
+ */
237
+ export function nurbs_curve_plane_intersect(data: Float64Array, nx: number, ny: number, nz: number, d: number): Float64Array;
238
+
239
+ /**
240
+ * Intersect a NURBS surface with a plane.
241
+ * Input: same surface format as tessellate_nurbs_surface, then plane (nx,ny,nz,d) appended.
242
+ * Returns polyline buffer: [num_polylines, n1, x,y,z,..., n2, x,y,z,...]
243
+ */
244
+ export function nurbs_surface_plane_intersect(surface_data: Float64Array, nx: number, ny: number, nz: number, d: number, tess: number): Float64Array;
245
+
246
+ /**
247
+ * Intersect two NURBS surfaces.
248
+ * Returns polyline buffer.
249
+ */
250
+ export function nurbs_surface_surface_intersect(data_a: Float64Array, data_b: Float64Array, tess: number): Float64Array;
251
+
252
+ /**
253
+ * Get the total length of a polyline.
254
+ * Input: flat coords [x1,y1,z1, x2,y2,z2, ...]
255
+ */
256
+ export function polyline_length(coords: Float64Array): number;
257
+
258
+ /**
259
+ * Evaluate a point on a polyline at parameter t ∈ [0,1].
260
+ * Input: flat coords [x1,y1,z1, x2,y2,z2, ...]
261
+ * Returns [x, y, z].
262
+ */
263
+ export function polyline_point_at(coords: Float64Array, t: number): Float64Array;
264
+
265
+ /**
266
+ * Sample a NURBS curve.
267
+ * Input: degree, then flat control points [x,y,z,...], then flat weights, then flat knots
268
+ * Format: [degree, num_pts, x0,y0,z0, ..., w0,w1,..., k0,k1,...]
269
+ */
270
+ export function sample_nurbs_curve(data: Float64Array, samples: number): Float64Array;
271
+
272
+ /**
273
+ * Tessellate a NURBS surface to a mesh buffer.
274
+ * Input format: [degree_u, degree_v, num_u, num_v, ...control_points(flat)..., ...weights(flat)..., ...knots_u..., ...knots_v..., u_segs, v_segs]
275
+ */
276
+ export function tessellate_nurbs_surface(data: Float64Array): Float64Array;
277
+
278
+ /**
279
+ * Simple test function to verify WASM is working
280
+ */
281
+ export function test_wasm(): string;
282
+
283
+ /**
284
+ * Get version info
285
+ */
286
+ export function version(): string;
@@ -0,0 +1,9 @@
1
+ /* @ts-self-types="./okgeometrycore.d.ts" */
2
+
3
+ import * as wasm from "./okgeometrycore_bg.wasm";
4
+ import { __wbg_set_wasm } from "./okgeometrycore_bg.js";
5
+ __wbg_set_wasm(wasm);
6
+ wasm.__wbindgen_start();
7
+ export {
8
+ arc_length, arc_point_at, circle_length, circle_point_at, create_arc, create_circle, create_line, create_polyline, curve_to_points, extrude_circle, extrude_line, extrude_polyline, line_length, line_point_at, line_tangent, loft_circles, loft_polylines, mesh_boolean_intersection, mesh_boolean_operation, mesh_boolean_subtraction, mesh_boolean_union, mesh_chamfer_all_edges, mesh_create_box, mesh_create_cone, mesh_create_cylinder, mesh_create_prism, mesh_create_sphere, mesh_export_obj, mesh_get_stats, mesh_import_obj, mesh_mesh_intersect, mesh_plane_intersect, mesh_rotate, mesh_scale, mesh_translate, nurbs_curve_curve_intersect, nurbs_curve_plane_intersect, nurbs_surface_plane_intersect, nurbs_surface_surface_intersect, polyline_length, polyline_point_at, sample_nurbs_curve, tessellate_nurbs_surface, test_wasm, version
9
+ } from "./okgeometrycore_bg.js";
@@ -0,0 +1,3 @@
1
+ /* Auto-generated type declarations for okgeometrycore_bg.js */
2
+ export * from "./okgeometrycore.js";
3
+ export function __wbg_set_wasm(val: any): void;