okgeometry-api 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/dist/Arc.d.ts +14 -0
- package/dist/Arc.d.ts.map +1 -0
- package/dist/Arc.js +32 -0
- package/dist/Arc.js.map +1 -0
- package/dist/Circle.d.ts +14 -0
- package/dist/Circle.d.ts.map +1 -0
- package/dist/Circle.js +36 -0
- package/dist/Circle.js.map +1 -0
- package/dist/Line.d.ts +14 -0
- package/dist/Line.d.ts.map +1 -0
- package/dist/Line.js +40 -0
- package/dist/Line.js.map +1 -0
- package/dist/Mesh.d.ts +49 -0
- package/dist/Mesh.d.ts.map +1 -0
- package/dist/Mesh.js +176 -0
- package/dist/Mesh.js.map +1 -0
- package/dist/NurbsCurve.d.ts +20 -0
- package/dist/NurbsCurve.d.ts.map +1 -0
- package/dist/NurbsCurve.js +70 -0
- package/dist/NurbsCurve.js.map +1 -0
- package/dist/NurbsSurface.d.ts +23 -0
- package/dist/NurbsSurface.d.ts.map +1 -0
- package/dist/NurbsSurface.js +86 -0
- package/dist/NurbsSurface.js.map +1 -0
- package/dist/Plane.d.ts +15 -0
- package/dist/Plane.d.ts.map +1 -0
- package/dist/Plane.js +22 -0
- package/dist/Plane.js.map +1 -0
- package/dist/Point.d.ts +16 -0
- package/dist/Point.d.ts.map +1 -0
- package/dist/Point.js +36 -0
- package/dist/Point.js.map +1 -0
- package/dist/Polyline.d.ts +14 -0
- package/dist/Polyline.d.ts.map +1 -0
- package/dist/Polyline.js +39 -0
- package/dist/Polyline.js.map +1 -0
- package/dist/Vec3.d.ts +24 -0
- package/dist/Vec3.d.ts.map +1 -0
- package/dist/Vec3.js +56 -0
- package/dist/Vec3.js.map +1 -0
- package/dist/engine.d.ts +4 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +26 -0
- package/dist/engine.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/wasm-base64.d.ts +2 -0
- package/dist/wasm-base64.d.ts.map +1 -0
- package/dist/wasm-base64.js +3 -0
- package/dist/wasm-base64.js.map +1 -0
- package/package.json +43 -0
package/dist/Arc.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Point } from "./Point.js";
|
|
2
|
+
import { Vec3 } from "./Vec3.js";
|
|
3
|
+
export declare class Arc {
|
|
4
|
+
readonly center: Point;
|
|
5
|
+
readonly radius: number;
|
|
6
|
+
readonly startAngle: number;
|
|
7
|
+
readonly endAngle: number;
|
|
8
|
+
readonly normal: Vec3;
|
|
9
|
+
constructor(center: Point, radius: number, startAngle: number, endAngle: number, normal?: Vec3);
|
|
10
|
+
pointAt(t: number): Point;
|
|
11
|
+
length(): number;
|
|
12
|
+
sample(n: number): Point[];
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=Arc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Arc.d.ts","sourceRoot":"","sources":["../src/Arc.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,qBAAa,GAAG;aAEI,MAAM,EAAE,KAAK;aACb,MAAM,EAAE,MAAM;aACd,UAAU,EAAE,MAAM;aAClB,QAAQ,EAAE,MAAM;aAChB,MAAM,EAAE,IAAI;gBAJZ,MAAM,EAAE,KAAK,EACb,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,MAAM,GAAE,IAAa;IAGvC,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,KAAK;IAUzB,MAAM,IAAI,MAAM;IAKhB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,KAAK,EAAE;CAa3B"}
|
package/dist/Arc.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ensureInit } from "./engine.js";
|
|
2
|
+
import { Point } from "./Point.js";
|
|
3
|
+
import { Vec3 } from "./Vec3.js";
|
|
4
|
+
import * as wasm from "../wasm/okgeometrycore_bg.js";
|
|
5
|
+
export class Arc {
|
|
6
|
+
constructor(center, radius, startAngle, endAngle, normal = Vec3.Z) {
|
|
7
|
+
this.center = center;
|
|
8
|
+
this.radius = radius;
|
|
9
|
+
this.startAngle = startAngle;
|
|
10
|
+
this.endAngle = endAngle;
|
|
11
|
+
this.normal = normal;
|
|
12
|
+
}
|
|
13
|
+
pointAt(t) {
|
|
14
|
+
ensureInit();
|
|
15
|
+
const r = wasm.arc_point_at(this.center.x, this.center.y, this.center.z, this.normal.x, this.normal.y, this.normal.z, this.radius, this.startAngle, this.endAngle, t);
|
|
16
|
+
return new Point(r[0], r[1], r[2]);
|
|
17
|
+
}
|
|
18
|
+
length() {
|
|
19
|
+
ensureInit();
|
|
20
|
+
return wasm.arc_length(this.radius, this.startAngle, this.endAngle);
|
|
21
|
+
}
|
|
22
|
+
sample(n) {
|
|
23
|
+
ensureInit();
|
|
24
|
+
const buf = wasm.create_arc(this.center.x, this.center.y, this.center.z, this.normal.x, this.normal.y, this.normal.z, this.radius, this.startAngle, this.endAngle, n);
|
|
25
|
+
const pts = [];
|
|
26
|
+
for (let i = 0; i < buf.length; i += 3) {
|
|
27
|
+
pts.push(new Point(buf[i], buf[i + 1], buf[i + 2]));
|
|
28
|
+
}
|
|
29
|
+
return pts;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=Arc.js.map
|
package/dist/Arc.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Arc.js","sourceRoot":"","sources":["../src/Arc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,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AAC,EAC3C,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,EAC3C,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAC/C,CAAC;QACF,MAAM,GAAG,GAAY,EAAE,CAAC;QACxB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YACvC,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACtD,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF"}
|
package/dist/Circle.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Point } from "./Point.js";
|
|
2
|
+
import { Vec3 } from "./Vec3.js";
|
|
3
|
+
import { Mesh } from "./Mesh.js";
|
|
4
|
+
export declare class Circle {
|
|
5
|
+
readonly center: Point;
|
|
6
|
+
readonly radius: number;
|
|
7
|
+
readonly normal: Vec3;
|
|
8
|
+
constructor(center: Point, radius: number, normal?: Vec3);
|
|
9
|
+
pointAt(t: number): Point;
|
|
10
|
+
length(): number;
|
|
11
|
+
sample(n: number): Point[];
|
|
12
|
+
extrude(direction: Vec3, segments?: number, caps?: boolean): Mesh;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=Circle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Circle.d.ts","sourceRoot":"","sources":["../src/Circle.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,qBAAa,MAAM;aAEC,MAAM,EAAE,KAAK;aACb,MAAM,EAAE,MAAM;aACd,MAAM,EAAE,IAAI;gBAFZ,MAAM,EAAE,KAAK,EACb,MAAM,EAAE,MAAM,EACd,MAAM,GAAE,IAAa;IAGvC,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,KAAK;IAUzB,MAAM,IAAI,MAAM;IAKhB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,KAAK,EAAE;IAc1B,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,QAAQ,SAAK,EAAE,IAAI,UAAO,GAAG,IAAI;CAW3D"}
|
package/dist/Circle.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ensureInit } from "./engine.js";
|
|
2
|
+
import { Point } from "./Point.js";
|
|
3
|
+
import { Vec3 } from "./Vec3.js";
|
|
4
|
+
import { Mesh } from "./Mesh.js";
|
|
5
|
+
import * as wasm from "../wasm/okgeometrycore_bg.js";
|
|
6
|
+
export class Circle {
|
|
7
|
+
constructor(center, radius, normal = Vec3.Z) {
|
|
8
|
+
this.center = center;
|
|
9
|
+
this.radius = radius;
|
|
10
|
+
this.normal = normal;
|
|
11
|
+
}
|
|
12
|
+
pointAt(t) {
|
|
13
|
+
ensureInit();
|
|
14
|
+
const r = wasm.circle_point_at(this.center.x, this.center.y, this.center.z, this.normal.x, this.normal.y, this.normal.z, this.radius, t);
|
|
15
|
+
return new Point(r[0], r[1], r[2]);
|
|
16
|
+
}
|
|
17
|
+
length() {
|
|
18
|
+
ensureInit();
|
|
19
|
+
return wasm.circle_length(this.radius);
|
|
20
|
+
}
|
|
21
|
+
sample(n) {
|
|
22
|
+
ensureInit();
|
|
23
|
+
const buf = wasm.create_circle(this.center.x, this.center.y, this.center.z, this.normal.x, this.normal.y, this.normal.z, this.radius, n);
|
|
24
|
+
const pts = [];
|
|
25
|
+
for (let i = 0; i < buf.length; i += 3) {
|
|
26
|
+
pts.push(new Point(buf[i], buf[i + 1], buf[i + 2]));
|
|
27
|
+
}
|
|
28
|
+
return pts;
|
|
29
|
+
}
|
|
30
|
+
extrude(direction, segments = 16, caps = true) {
|
|
31
|
+
ensureInit();
|
|
32
|
+
const buf = wasm.extrude_circle(this.center.x, this.center.y, this.center.z, this.normal.x, this.normal.y, this.normal.z, this.radius, direction.x, direction.y, direction.z, segments, caps);
|
|
33
|
+
return Mesh.fromBuffer(buf);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=Circle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Circle.js","sourceRoot":"","sources":["../src/Circle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,KAAK,IAAI,MAAM,8BAA8B,CAAC;AAErD,MAAM,OAAO,MAAM;IACjB,YACkB,MAAa,EACb,MAAc,EACd,SAAe,IAAI,CAAC,CAAC;QAFrB,WAAM,GAAN,MAAM,CAAO;QACb,WAAM,GAAN,MAAM,CAAQ;QACd,WAAM,GAAN,MAAM,CAAe;IACpC,CAAC;IAEJ,OAAO,CAAC,CAAS;QACf,UAAU,EAAE,CAAC;QACb,MAAM,CAAC,GAAG,IAAI,CAAC,eAAe,CAC5B,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,EAC3C,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,EAC3C,IAAI,CAAC,MAAM,EA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,EAC3C,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,EAC3C,IAAI,CAAC,MAAM,EACX,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EACrC,QAAQ,EAAE,IAAI,CACf,CAAC;QACF,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;CACF"}
|
package/dist/Line.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Point } from "./Point.js";
|
|
2
|
+
import { Vec3 } from "./Vec3.js";
|
|
3
|
+
import { Mesh } from "./Mesh.js";
|
|
4
|
+
export declare class Line {
|
|
5
|
+
readonly start: Point;
|
|
6
|
+
readonly end: Point;
|
|
7
|
+
constructor(start: Point, end: Point);
|
|
8
|
+
pointAt(t: number): Point;
|
|
9
|
+
length(): number;
|
|
10
|
+
tangent(): Vec3;
|
|
11
|
+
sample(n: number): Point[];
|
|
12
|
+
extrude(direction: Vec3, segments?: number): Mesh;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=Line.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Line.d.ts","sourceRoot":"","sources":["../src/Line.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,qBAAa,IAAI;aAEG,KAAK,EAAE,KAAK;aACZ,GAAG,EAAE,KAAK;gBADV,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,KAAK;IAG5B,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,KAAK;IAUzB,MAAM,IAAI,MAAM;IAQhB,OAAO,IAAI,IAAI;IASf,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,KAAK,EAAE;IAc1B,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,QAAQ,SAAI,GAAG,IAAI;CAU7C"}
|
package/dist/Line.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ensureInit } from "./engine.js";
|
|
2
|
+
import { Point } from "./Point.js";
|
|
3
|
+
import { Vec3 } from "./Vec3.js";
|
|
4
|
+
import { Mesh } from "./Mesh.js";
|
|
5
|
+
import * as wasm from "../wasm/okgeometrycore_bg.js";
|
|
6
|
+
export class Line {
|
|
7
|
+
constructor(start, end) {
|
|
8
|
+
this.start = start;
|
|
9
|
+
this.end = end;
|
|
10
|
+
}
|
|
11
|
+
pointAt(t) {
|
|
12
|
+
ensureInit();
|
|
13
|
+
const r = wasm.line_point_at(this.start.x, this.start.y, this.start.z, this.end.x, this.end.y, this.end.z, t);
|
|
14
|
+
return new Point(r[0], r[1], r[2]);
|
|
15
|
+
}
|
|
16
|
+
length() {
|
|
17
|
+
ensureInit();
|
|
18
|
+
return wasm.line_length(this.start.x, this.start.y, this.start.z, this.end.x, this.end.y, this.end.z);
|
|
19
|
+
}
|
|
20
|
+
tangent() {
|
|
21
|
+
ensureInit();
|
|
22
|
+
const r = wasm.line_tangent(this.start.x, this.start.y, this.start.z, this.end.x, this.end.y, this.end.z);
|
|
23
|
+
return new Vec3(r[0], r[1], r[2]);
|
|
24
|
+
}
|
|
25
|
+
sample(n) {
|
|
26
|
+
ensureInit();
|
|
27
|
+
const buf = wasm.create_line(this.start.x, this.start.y, this.start.z, this.end.x, this.end.y, this.end.z, n);
|
|
28
|
+
const pts = [];
|
|
29
|
+
for (let i = 0; i < buf.length; i += 3) {
|
|
30
|
+
pts.push(new Point(buf[i], buf[i + 1], buf[i + 2]));
|
|
31
|
+
}
|
|
32
|
+
return pts;
|
|
33
|
+
}
|
|
34
|
+
extrude(direction, segments = 1) {
|
|
35
|
+
ensureInit();
|
|
36
|
+
const buf = wasm.extrude_line(this.start.x, this.start.y, this.start.z, this.end.x, this.end.y, this.end.z, direction.x, direction.y, direction.z, segments);
|
|
37
|
+
return Mesh.fromBuffer(buf);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=Line.js.map
|
package/dist/Line.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Line.js","sourceRoot":"","sources":["../src/Line.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,KAAK,IAAI,MAAM,8BAA8B,CAAC;AAErD,MAAM,OAAO,IAAI;IACf,YACkB,KAAY,EACZ,GAAU;QADV,UAAK,GAAL,KAAK,CAAO;QACZ,QAAG,GAAH,GAAG,CAAO;IACzB,CAAC;IAEJ,OAAO,CAAC,CAAS;QACf,UAAU,EAAE,CAAC;QACb,MAAM,CAAC,GAAG,IAAI,CAAC,aAAa,CAC1B,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EACxC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAClC,CAAC,CACF,CAAC;QACF,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACrC,CAAC;IAED,MAAM;QACJ,UAAU,EAAE,CAAC;QACb,OAAO,IAAI,CAAC,WAAW,CACrB,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAA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CAAC,CAAC,CAAC,CAAC;QACtD,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IAED,OAAO,CAAC,SAAe,EAAE,QAAQ,GAAG,CAAC;QACnC,UAAU,EAAE,CAAC;QACb,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,CAC3B,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EACxC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAClC,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EACrC,QAAQ,CACT,CAAC;QACF,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;CACF"}
|
package/dist/Mesh.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Point } from "./Point.js";
|
|
2
|
+
import { Plane } from "./Plane.js";
|
|
3
|
+
import { Polyline } from "./Polyline.js";
|
|
4
|
+
/**
|
|
5
|
+
* Buffer-backed mesh. All geometry lives in a Float64Array from WASM.
|
|
6
|
+
* Buffer format: [vertexCount, x1,y1,z1, ..., i1,i2,i3, ...]
|
|
7
|
+
*/
|
|
8
|
+
export declare class Mesh {
|
|
9
|
+
private _buffer;
|
|
10
|
+
private _vertexCount;
|
|
11
|
+
private _positionBuffer;
|
|
12
|
+
private _indexBuffer;
|
|
13
|
+
private _vertices;
|
|
14
|
+
private _faces;
|
|
15
|
+
private constructor();
|
|
16
|
+
/** Float32 xyz positions for BufferGeometry */
|
|
17
|
+
get positionBuffer(): Float32Array;
|
|
18
|
+
/** Uint32 triangle indices for BufferGeometry.setIndex */
|
|
19
|
+
get indexBuffer(): Uint32Array;
|
|
20
|
+
get vertexCount(): number;
|
|
21
|
+
get faceCount(): number;
|
|
22
|
+
get vertices(): Point[];
|
|
23
|
+
get faces(): number[][];
|
|
24
|
+
/** Raw WASM buffer (for advanced use / re-passing to WASM) */
|
|
25
|
+
get rawBuffer(): Float64Array;
|
|
26
|
+
static fromBuffer(buffer: Float64Array): Mesh;
|
|
27
|
+
static createBox(width: number, height: number, depth: number): Mesh;
|
|
28
|
+
static createSphere(radius: number, segments: number, rings: number): Mesh;
|
|
29
|
+
static createCylinder(radius: number, height: number, segments: number): Mesh;
|
|
30
|
+
static createPrism(radius: number, height: number, sides: number): Mesh;
|
|
31
|
+
static fromOBJ(objString: string): Mesh;
|
|
32
|
+
static loftCircles(circles: Array<{
|
|
33
|
+
center: Point;
|
|
34
|
+
normal?: {
|
|
35
|
+
x: number;
|
|
36
|
+
y: number;
|
|
37
|
+
z: number;
|
|
38
|
+
};
|
|
39
|
+
radius: number;
|
|
40
|
+
}>, segments: number, caps?: boolean): Mesh;
|
|
41
|
+
static loftPolylines(polylines: Point[][], segments: number, caps?: boolean): Mesh;
|
|
42
|
+
union(other: Mesh): Mesh;
|
|
43
|
+
subtract(other: Mesh): Mesh;
|
|
44
|
+
intersect(other: Mesh): Mesh;
|
|
45
|
+
intersectPlane(plane: Plane): Polyline[];
|
|
46
|
+
intersectMesh(other: Mesh): Polyline[];
|
|
47
|
+
toOBJ(): string;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=Mesh.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Mesh.d.ts","sourceRoot":"","sources":["../src/Mesh.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC;;;GAGG;AACH,qBAAa,IAAI;IACf,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,YAAY,CAAS;IAG7B,OAAO,CAAC,eAAe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AA;KAAE,CAAC,EAC/F,QAAQ,EAAE,MAAM,EAChB,IAAI,UAAQ,GACX,IAAI;IAiBP,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,UAAQ,GAAG,IAAI;IAehF,KAAK,CAAC,KAAK,EAAE,IAAI,GAAG,IAAI;IAOxB,QAAQ,CAAC,KAAK,EAAE,IAAI,GAAG,IAAI;IAO3B,SAAS,CAAC,KAAK,EAAE,IAAI,GAAG,IAAI;IAS5B,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,QAAQ,EAAE;IAaxC,aAAa,CAAC,KAAK,EAAE,IAAI,GAAG,QAAQ,EAAE;IAatC,KAAK,IAAI,MAAM;CAIhB"}
|
package/dist/Mesh.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { ensureInit } from "./engine.js";
|
|
2
|
+
import { Point } from "./Point.js";
|
|
3
|
+
import { Polyline } from "./Polyline.js";
|
|
4
|
+
import * as wasm from "../wasm/okgeometrycore_bg.js";
|
|
5
|
+
/**
|
|
6
|
+
* Buffer-backed mesh. All geometry lives in a Float64Array from WASM.
|
|
7
|
+
* Buffer format: [vertexCount, x1,y1,z1, ..., i1,i2,i3, ...]
|
|
8
|
+
*/
|
|
9
|
+
export class Mesh {
|
|
10
|
+
constructor(buffer) {
|
|
11
|
+
// Lazy caches
|
|
12
|
+
this._positionBuffer = null;
|
|
13
|
+
this._indexBuffer = null;
|
|
14
|
+
this._vertices = null;
|
|
15
|
+
this._faces = null;
|
|
16
|
+
this._buffer = buffer;
|
|
17
|
+
this._vertexCount = buffer.length > 0 ? buffer[0] : 0;
|
|
18
|
+
}
|
|
19
|
+
// ── GPU-ready buffers ──────────────────────────────────────────
|
|
20
|
+
/** Float32 xyz positions for BufferGeometry */
|
|
21
|
+
get positionBuffer() {
|
|
22
|
+
if (!this._positionBuffer) {
|
|
23
|
+
const n = this._vertexCount * 3;
|
|
24
|
+
this._positionBuffer = new Float32Array(n);
|
|
25
|
+
for (let i = 0; i < n; i++) {
|
|
26
|
+
this._positionBuffer[i] = this._buffer[1 + i];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return this._positionBuffer;
|
|
30
|
+
}
|
|
31
|
+
/** Uint32 triangle indices for BufferGeometry.setIndex */
|
|
32
|
+
get indexBuffer() {
|
|
33
|
+
if (!this._indexBuffer) {
|
|
34
|
+
const start = 1 + this._vertexCount * 3;
|
|
35
|
+
const len = this._buffer.length - start;
|
|
36
|
+
this._indexBuffer = new Uint32Array(len);
|
|
37
|
+
for (let i = 0; i < len; i++) {
|
|
38
|
+
this._indexBuffer[i] = this._buffer[start + i];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return this._indexBuffer;
|
|
42
|
+
}
|
|
43
|
+
get vertexCount() {
|
|
44
|
+
return this._vertexCount;
|
|
45
|
+
}
|
|
46
|
+
get faceCount() {
|
|
47
|
+
return this.indexBuffer.length / 3;
|
|
48
|
+
}
|
|
49
|
+
// ── High-level accessors (lazy) ────────────────────────────────
|
|
50
|
+
get vertices() {
|
|
51
|
+
if (!this._vertices) {
|
|
52
|
+
const pts = [];
|
|
53
|
+
for (let i = 0; i < this._vertexCount; i++) {
|
|
54
|
+
const off = 1 + i * 3;
|
|
55
|
+
pts.push(new Point(this._buffer[off], this._buffer[off + 1], this._buffer[off + 2]));
|
|
56
|
+
}
|
|
57
|
+
this._vertices = pts;
|
|
58
|
+
}
|
|
59
|
+
return this._vertices;
|
|
60
|
+
}
|
|
61
|
+
get faces() {
|
|
62
|
+
if (!this._faces) {
|
|
63
|
+
const idx = this.indexBuffer;
|
|
64
|
+
const f = [];
|
|
65
|
+
for (let i = 0; i < idx.length; i += 3) {
|
|
66
|
+
f.push([idx[i], idx[i + 1], idx[i + 2]]);
|
|
67
|
+
}
|
|
68
|
+
this._faces = f;
|
|
69
|
+
}
|
|
70
|
+
return this._faces;
|
|
71
|
+
}
|
|
72
|
+
/** Raw WASM buffer (for advanced use / re-passing to WASM) */
|
|
73
|
+
get rawBuffer() {
|
|
74
|
+
return this._buffer;
|
|
75
|
+
}
|
|
76
|
+
// ── Static factories ───────────────────────────────────────────
|
|
77
|
+
static fromBuffer(buffer) {
|
|
78
|
+
return new Mesh(buffer);
|
|
79
|
+
}
|
|
80
|
+
static createBox(width, height, depth) {
|
|
81
|
+
ensureInit();
|
|
82
|
+
return new Mesh(wasm.mesh_create_box(width, height, depth));
|
|
83
|
+
}
|
|
84
|
+
static createSphere(radius, segments, rings) {
|
|
85
|
+
ensureInit();
|
|
86
|
+
return new Mesh(wasm.mesh_create_sphere(radius, segments, rings));
|
|
87
|
+
}
|
|
88
|
+
static createCylinder(radius, height, segments) {
|
|
89
|
+
ensureInit();
|
|
90
|
+
return new Mesh(wasm.mesh_create_cylinder(radius, height, segments));
|
|
91
|
+
}
|
|
92
|
+
static createPrism(radius, height, sides) {
|
|
93
|
+
ensureInit();
|
|
94
|
+
return new Mesh(wasm.mesh_create_prism(radius, height, sides));
|
|
95
|
+
}
|
|
96
|
+
static fromOBJ(objString) {
|
|
97
|
+
ensureInit();
|
|
98
|
+
return new Mesh(wasm.mesh_import_obj(objString));
|
|
99
|
+
}
|
|
100
|
+
static loftCircles(circles, segments, caps = false) {
|
|
101
|
+
ensureInit();
|
|
102
|
+
const data = new Float64Array(circles.length * 7);
|
|
103
|
+
for (let i = 0; i < circles.length; i++) {
|
|
104
|
+
const c = circles[i];
|
|
105
|
+
const off = i * 7;
|
|
106
|
+
data[off] = c.center.x;
|
|
107
|
+
data[off + 1] = c.center.y;
|
|
108
|
+
data[off + 2] = c.center.z;
|
|
109
|
+
data[off + 3] = c.normal?.x ?? 0;
|
|
110
|
+
data[off + 4] = c.normal?.y ?? 1;
|
|
111
|
+
data[off + 5] = c.normal?.z ?? 0;
|
|
112
|
+
data[off + 6] = c.radius;
|
|
113
|
+
}
|
|
114
|
+
return new Mesh(wasm.loft_circles(data, segments, caps));
|
|
115
|
+
}
|
|
116
|
+
static loftPolylines(polylines, segments, caps = false) {
|
|
117
|
+
ensureInit();
|
|
118
|
+
// Format: [count1, x,y,z,..., count2, x,y,z,...]
|
|
119
|
+
const parts = [];
|
|
120
|
+
for (const pl of polylines) {
|
|
121
|
+
parts.push(pl.length);
|
|
122
|
+
for (const p of pl) {
|
|
123
|
+
parts.push(p.x, p.y, p.z);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return new Mesh(wasm.loft_polylines(new Float64Array(parts), segments, caps));
|
|
127
|
+
}
|
|
128
|
+
// ── Booleans ───────────────────────────────────────────────────
|
|
129
|
+
union(other) {
|
|
130
|
+
ensureInit();
|
|
131
|
+
return new Mesh(wasm.mesh_boolean_union(this._vertexCount, this._buffer, other._vertexCount, other._buffer));
|
|
132
|
+
}
|
|
133
|
+
subtract(other) {
|
|
134
|
+
ensureInit();
|
|
135
|
+
return new Mesh(wasm.mesh_boolean_subtraction(this._vertexCount, this._buffer, other._vertexCount, other._buffer));
|
|
136
|
+
}
|
|
137
|
+
intersect(other) {
|
|
138
|
+
ensureInit();
|
|
139
|
+
return new Mesh(wasm.mesh_boolean_intersection(this._vertexCount, this._buffer, other._vertexCount, other._buffer));
|
|
140
|
+
}
|
|
141
|
+
// ── Intersection queries ───────────────────────────────────────
|
|
142
|
+
intersectPlane(plane) {
|
|
143
|
+
ensureInit();
|
|
144
|
+
const result = wasm.mesh_plane_intersect(this._vertexCount, this._buffer, plane.normal.x, plane.normal.y, plane.normal.z, plane.d);
|
|
145
|
+
return parsePolylineBuffer(result);
|
|
146
|
+
}
|
|
147
|
+
intersectMesh(other) {
|
|
148
|
+
ensureInit();
|
|
149
|
+
const result = wasm.mesh_mesh_intersect(this._vertexCount, this._buffer, other._vertexCount, other._buffer);
|
|
150
|
+
return parsePolylineBuffer(result);
|
|
151
|
+
}
|
|
152
|
+
// ── Export ──────────────────────────────────────────────────────
|
|
153
|
+
toOBJ() {
|
|
154
|
+
ensureInit();
|
|
155
|
+
return wasm.mesh_export_obj(this._vertexCount, this._buffer);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/** Parse WASM polyline buffer: [num_polylines, n1, x,y,z,..., n2, x,y,z,...] */
|
|
159
|
+
function parsePolylineBuffer(buf) {
|
|
160
|
+
if (buf.length === 0)
|
|
161
|
+
return [];
|
|
162
|
+
const numPolylines = buf[0];
|
|
163
|
+
const result = [];
|
|
164
|
+
let idx = 1;
|
|
165
|
+
for (let i = 0; i < numPolylines; i++) {
|
|
166
|
+
const count = buf[idx++];
|
|
167
|
+
const pts = [];
|
|
168
|
+
for (let j = 0; j < count; j++) {
|
|
169
|
+
pts.push(new Point(buf[idx], buf[idx + 1], buf[idx + 2]));
|
|
170
|
+
idx += 3;
|
|
171
|
+
}
|
|
172
|
+
result.push(new Polyline(pts));
|
|
173
|
+
}
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=Mesh.js.map
|
package/dist/Mesh.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Mesh.js","sourceRoot":"","sources":["../src/Mesh.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,IAAI,MAAM,8BAA8B,CAAC;AAErD;;;GAGG;AACH,MAAM,OAAO,IAAI;IAUf,YAAoB,MAAoB;QANxC,cAAc;QACN,oBAAe,GAAwB,IAAI,CAAC;QAC5C,iBAAY,GAAuB,IAAI,CAAC;QACxC,cAAS,GAAmB,IAAI,CAAC;QACjC,WAAM,GAAsB,IAAI,CAAC;QAGvC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,C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CAAC;QACX,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Point } from "./Point.js";
|
|
2
|
+
import { Plane } from "./Plane.js";
|
|
3
|
+
/**
|
|
4
|
+
* NURBS curve backed by WASM.
|
|
5
|
+
* Data format: [degree, num_pts, x0,y0,z0, ..., w0,w1,..., k0,k1,...]
|
|
6
|
+
*/
|
|
7
|
+
export declare class NurbsCurve {
|
|
8
|
+
readonly degree: number;
|
|
9
|
+
readonly controlPoints: Point[];
|
|
10
|
+
readonly weights: number[];
|
|
11
|
+
readonly knots: number[];
|
|
12
|
+
private _data;
|
|
13
|
+
constructor(degree: number, controlPoints: Point[], weights: number[], knots: number[]);
|
|
14
|
+
sample(n: number): Point[];
|
|
15
|
+
intersectPlane(plane: Plane): Point[];
|
|
16
|
+
intersectCurve(other: NurbsCurve): Point[];
|
|
17
|
+
/** Encode to WASM format */
|
|
18
|
+
private static encode;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=NurbsCurve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NurbsCurve.d.ts","sourceRoot":"","sources":["../src/NurbsCurve.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGnC;;;GAGG;AACH,qBAAa,UAAU;aAIH,MAAM,EAAE,MAAM;aACd,aAAa,EAAE,KAAK,EAAE;aACtB,OAAO,EAAE,MAAM,EAAE;aACjB,KAAK,EAAE,MAAM,EAAE;IANjC,OAAO,CAAC,KAAK,CAAe;gBAGV,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,KAAK,EAAE,EACtB,OAAO,EAAE,MAAM,EAAE,EACjB,KAAK,EAAE,MAAM,EAAE;IAKjC,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,KAAK,EAAE;IAU1B,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,EAAE;IAiBrC,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,KAAK,EAAE;IAa1C,4BAA4B;IAC5B,OAAO,CAAC,MAAM,CAAC,MAAM;CAoBtB"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { ensureInit } from "./engine.js";
|
|
2
|
+
import { Point } from "./Point.js";
|
|
3
|
+
import * as wasm from "../wasm/okgeometrycore_bg.js";
|
|
4
|
+
/**
|
|
5
|
+
* NURBS curve backed by WASM.
|
|
6
|
+
* Data format: [degree, num_pts, x0,y0,z0, ..., w0,w1,..., k0,k1,...]
|
|
7
|
+
*/
|
|
8
|
+
export class NurbsCurve {
|
|
9
|
+
constructor(degree, controlPoints, weights, knots) {
|
|
10
|
+
this.degree = degree;
|
|
11
|
+
this.controlPoints = controlPoints;
|
|
12
|
+
this.weights = weights;
|
|
13
|
+
this.knots = knots;
|
|
14
|
+
this._data = NurbsCurve.encode(degree, controlPoints, weights, knots);
|
|
15
|
+
}
|
|
16
|
+
sample(n) {
|
|
17
|
+
ensureInit();
|
|
18
|
+
const buf = wasm.sample_nurbs_curve(this._data, n);
|
|
19
|
+
const pts = [];
|
|
20
|
+
for (let i = 0; i < buf.length; i += 3) {
|
|
21
|
+
pts.push(new Point(buf[i], buf[i + 1], buf[i + 2]));
|
|
22
|
+
}
|
|
23
|
+
return pts;
|
|
24
|
+
}
|
|
25
|
+
intersectPlane(plane) {
|
|
26
|
+
ensureInit();
|
|
27
|
+
const buf = wasm.nurbs_curve_plane_intersect(this._data, plane.normal.x, plane.normal.y, plane.normal.z, plane.d);
|
|
28
|
+
if (buf.length === 0)
|
|
29
|
+
return [];
|
|
30
|
+
const numPts = buf[0];
|
|
31
|
+
const pts = [];
|
|
32
|
+
for (let i = 0; i < numPts; i++) {
|
|
33
|
+
const off = 1 + i * 3;
|
|
34
|
+
pts.push(new Point(buf[off], buf[off + 1], buf[off + 2]));
|
|
35
|
+
}
|
|
36
|
+
return pts;
|
|
37
|
+
}
|
|
38
|
+
intersectCurve(other) {
|
|
39
|
+
ensureInit();
|
|
40
|
+
const buf = wasm.nurbs_curve_curve_intersect(this._data, other._data);
|
|
41
|
+
if (buf.length === 0)
|
|
42
|
+
return [];
|
|
43
|
+
const numPts = buf[0];
|
|
44
|
+
const pts = [];
|
|
45
|
+
for (let i = 0; i < numPts; i++) {
|
|
46
|
+
const off = 1 + i * 3;
|
|
47
|
+
pts.push(new Point(buf[off], buf[off + 1], buf[off + 2]));
|
|
48
|
+
}
|
|
49
|
+
return pts;
|
|
50
|
+
}
|
|
51
|
+
/** Encode to WASM format */
|
|
52
|
+
static encode(degree, controlPoints, weights, knots) {
|
|
53
|
+
const n = controlPoints.length;
|
|
54
|
+
const data = new Float64Array(2 + n * 3 + weights.length + knots.length);
|
|
55
|
+
data[0] = degree;
|
|
56
|
+
data[1] = n;
|
|
57
|
+
let idx = 2;
|
|
58
|
+
for (const p of controlPoints) {
|
|
59
|
+
data[idx++] = p.x;
|
|
60
|
+
data[idx++] = p.y;
|
|
61
|
+
data[idx++] = p.z;
|
|
62
|
+
}
|
|
63
|
+
for (const w of weights)
|
|
64
|
+
data[idx++] = w;
|
|
65
|
+
for (const k of knots)
|
|
66
|
+
data[idx++] = k;
|
|
67
|
+
return data;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=NurbsCurve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NurbsCurve.js","sourceRoot":"","sources":["../src/NurbsCurve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,OAAO,KAAK,IAAI,MAAM,8BAA8B,CAAC;AAErD;;;GAGG;AACH,M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AAC,GAAG,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;QACzE,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;QACjB,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACZ,IAAI,GAAG,GAAG,CAAC,CAAC;QACZ,KAAK,MAAM,CAAC,IAAI,aAAa,EAAE,CAAC;YAC9B,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAClB,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAClB,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC;QACD,KAAK,MAAM,CAAC,IAAI,OAAO;YAAE,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;QACzC,KAAK,MAAM,CAAC,IAAI,KAAK;YAAE,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;QACvC,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Point } from "./Point.js";
|
|
2
|
+
import { Plane } from "./Plane.js";
|
|
3
|
+
import { Mesh } from "./Mesh.js";
|
|
4
|
+
import { Polyline } from "./Polyline.js";
|
|
5
|
+
/**
|
|
6
|
+
* NURBS surface backed by WASM.
|
|
7
|
+
* Data format: [degree_u, degree_v, num_u, num_v, ...cp(flat)..., ...weights..., ...knots_u..., ...knots_v...]
|
|
8
|
+
*/
|
|
9
|
+
export declare class NurbsSurface {
|
|
10
|
+
readonly degreeU: number;
|
|
11
|
+
readonly degreeV: number;
|
|
12
|
+
readonly controlPoints: Point[][];
|
|
13
|
+
readonly weights: number[][];
|
|
14
|
+
readonly knotsU: number[];
|
|
15
|
+
readonly knotsV: number[];
|
|
16
|
+
private _data;
|
|
17
|
+
constructor(degreeU: number, degreeV: number, controlPoints: Point[][], weights: number[][], knotsU: number[], knotsV: number[]);
|
|
18
|
+
tessellate(uSegs: number, vSegs: number): Mesh;
|
|
19
|
+
intersectPlane(plane: Plane, tess?: number): Polyline[];
|
|
20
|
+
intersectSurface(other: NurbsSurface, tess?: number): Polyline[];
|
|
21
|
+
private static encode;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=NurbsSurface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NurbsSurface.d.ts","sourceRoot":"","sources":["../src/NurbsSurface.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC;;;GAGG;AACH,qBAAa,YAAY;aAIL,OAAO,EAAE,MAAM;aACf,OAAO,EAAE,MAAM;aACf,aAAa,EAAE,KAAK,EAAE,EAAE;aACxB,OAAO,EAAE,MAAM,EAAE,EAAE;aACnB,MAAM,EAAE,MAAM,EAAE;aAChB,MAAM,EAAE,MAAM,EAAE;IARlC,OAAO,CAAC,KAAK,CAAe;gBAGV,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,KAAK,EAAE,EAAE,EACxB,OAAO,EAAE,MAAM,EAAE,EAAE,EACnB,MAAM,EAAE,MAAM,EAAE,EAChB,MAAM,EAAE,MAAM,EAAE;IAKlC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAU9C,cAAc,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,SAAK,GAAG,QAAQ,EAAE;IAWnD,gBAAgB,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,SAAK,GAAG,QAAQ,EAAE;IAM5D,OAAO,CAAC,MAAM,CAAC,MAAM;CAkCtB"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { ensureInit } from "./engine.js";
|
|
2
|
+
import { Point } from "./Point.js";
|
|
3
|
+
import { Mesh } from "./Mesh.js";
|
|
4
|
+
import { Polyline } from "./Polyline.js";
|
|
5
|
+
import * as wasm from "../wasm/okgeometrycore_bg.js";
|
|
6
|
+
/**
|
|
7
|
+
* NURBS surface backed by WASM.
|
|
8
|
+
* Data format: [degree_u, degree_v, num_u, num_v, ...cp(flat)..., ...weights..., ...knots_u..., ...knots_v...]
|
|
9
|
+
*/
|
|
10
|
+
export class NurbsSurface {
|
|
11
|
+
constructor(degreeU, degreeV, controlPoints, weights, knotsU, knotsV) {
|
|
12
|
+
this.degreeU = degreeU;
|
|
13
|
+
this.degreeV = degreeV;
|
|
14
|
+
this.controlPoints = controlPoints;
|
|
15
|
+
this.weights = weights;
|
|
16
|
+
this.knotsU = knotsU;
|
|
17
|
+
this.knotsV = knotsV;
|
|
18
|
+
this._data = NurbsSurface.encode(degreeU, degreeV, controlPoints, weights, knotsU, knotsV);
|
|
19
|
+
}
|
|
20
|
+
tessellate(uSegs, vSegs) {
|
|
21
|
+
ensureInit();
|
|
22
|
+
// Append u_segs, v_segs to the data
|
|
23
|
+
const full = new Float64Array(this._data.length + 2);
|
|
24
|
+
full.set(this._data);
|
|
25
|
+
full[this._data.length] = uSegs;
|
|
26
|
+
full[this._data.length + 1] = vSegs;
|
|
27
|
+
return Mesh.fromBuffer(wasm.tessellate_nurbs_surface(full));
|
|
28
|
+
}
|
|
29
|
+
intersectPlane(plane, tess = 20) {
|
|
30
|
+
ensureInit();
|
|
31
|
+
const buf = wasm.nurbs_surface_plane_intersect(this._data, plane.normal.x, plane.normal.y, plane.normal.z, plane.d, tess);
|
|
32
|
+
return parsePolylineBuffer(buf);
|
|
33
|
+
}
|
|
34
|
+
intersectSurface(other, tess = 20) {
|
|
35
|
+
ensureInit();
|
|
36
|
+
const buf = wasm.nurbs_surface_surface_intersect(this._data, other._data, tess);
|
|
37
|
+
return parsePolylineBuffer(buf);
|
|
38
|
+
}
|
|
39
|
+
static encode(degU, degV, controlPoints, weights, knotsU, knotsV) {
|
|
40
|
+
const numU = controlPoints.length;
|
|
41
|
+
const numV = controlPoints[0]?.length ?? 0;
|
|
42
|
+
const totalPts = numU * numV;
|
|
43
|
+
const data = new Float64Array(4 + totalPts * 3 + totalPts + knotsU.length + knotsV.length);
|
|
44
|
+
data[0] = degU;
|
|
45
|
+
data[1] = degV;
|
|
46
|
+
data[2] = numU;
|
|
47
|
+
data[3] = numV;
|
|
48
|
+
let idx = 4;
|
|
49
|
+
for (let u = 0; u < numU; u++) {
|
|
50
|
+
for (let v = 0; v < numV; v++) {
|
|
51
|
+
const p = controlPoints[u][v];
|
|
52
|
+
data[idx++] = p.x;
|
|
53
|
+
data[idx++] = p.y;
|
|
54
|
+
data[idx++] = p.z;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
for (let u = 0; u < numU; u++) {
|
|
58
|
+
for (let v = 0; v < numV; v++) {
|
|
59
|
+
data[idx++] = weights[u][v];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
for (const k of knotsU)
|
|
63
|
+
data[idx++] = k;
|
|
64
|
+
for (const k of knotsV)
|
|
65
|
+
data[idx++] = k;
|
|
66
|
+
return data;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function parsePolylineBuffer(buf) {
|
|
70
|
+
if (buf.length === 0)
|
|
71
|
+
return [];
|
|
72
|
+
const n = buf[0];
|
|
73
|
+
const result = [];
|
|
74
|
+
let idx = 1;
|
|
75
|
+
for (let i = 0; i < n; i++) {
|
|
76
|
+
const count = buf[idx++];
|
|
77
|
+
const pts = [];
|
|
78
|
+
for (let j = 0; j < count; j++) {
|
|
79
|
+
pts.push(new Point(buf[idx], buf[idx + 1], buf[idx + 2]));
|
|
80
|
+
idx += 3;
|
|
81
|
+
}
|
|
82
|
+
result.push(new Polyline(pts));
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=NurbsSurface.js.map
|