opengeometry 0.0.3 → 0.0.4
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/index.d.ts +45 -4
- package/index.js +402 -87
- package/index.js.map +1 -1
- package/opengeometry_bg.wasm +0 -0
- package/opengeometry_bg.wasm.d.ts +73 -61
- package/package.json +3 -3
- package/src/base-types.d.ts +4 -2
- package/src/pencil.d.ts +1 -0
- package/src/primitives/base-primitive.d.ts +11 -0
- package/src/primitives/poly-line.d.ts +6 -1
- package/src/primitives/rectangle.d.ts +8 -9
- package/src/shapes/polygon.d.ts +6 -1
package/index.js
CHANGED
|
@@ -76,6 +76,19 @@ function addHeapObject(obj) {
|
|
|
76
76
|
heap[idx] = obj;
|
|
77
77
|
return idx;
|
|
78
78
|
}
|
|
79
|
+
function getObject(idx) {
|
|
80
|
+
return heap[idx];
|
|
81
|
+
}
|
|
82
|
+
function dropObject(idx) {
|
|
83
|
+
if (idx < 132) return;
|
|
84
|
+
heap[idx] = heap_next;
|
|
85
|
+
heap_next = idx;
|
|
86
|
+
}
|
|
87
|
+
function takeObject(idx) {
|
|
88
|
+
const ret = getObject(idx);
|
|
89
|
+
dropObject(idx);
|
|
90
|
+
return ret;
|
|
91
|
+
}
|
|
79
92
|
function _assertClass(instance, klass) {
|
|
80
93
|
if (!(instance instanceof klass)) {
|
|
81
94
|
throw new Error(`expected instance of ${klass.name}`);
|
|
@@ -144,19 +157,6 @@ function passArrayJsValueToWasm0(array, malloc) {
|
|
|
144
157
|
WASM_VECTOR_LEN = array.length;
|
|
145
158
|
return ptr;
|
|
146
159
|
}
|
|
147
|
-
function getObject(idx) {
|
|
148
|
-
return heap[idx];
|
|
149
|
-
}
|
|
150
|
-
function dropObject(idx) {
|
|
151
|
-
if (idx < 132) return;
|
|
152
|
-
heap[idx] = heap_next;
|
|
153
|
-
heap_next = idx;
|
|
154
|
-
}
|
|
155
|
-
function takeObject(idx) {
|
|
156
|
-
const ret = getObject(idx);
|
|
157
|
-
dropObject(idx);
|
|
158
|
-
return ret;
|
|
159
|
-
}
|
|
160
160
|
function getArrayJsValueFromWasm0(ptr, len) {
|
|
161
161
|
ptr = ptr >>> 0;
|
|
162
162
|
const mem = getDataViewMemory0();
|
|
@@ -1027,12 +1027,28 @@ class OGPolyLine {
|
|
|
1027
1027
|
return OGPolyLine.__wrap(ret);
|
|
1028
1028
|
}
|
|
1029
1029
|
/**
|
|
1030
|
+
* @param {Vector3D} translation
|
|
1031
|
+
*/
|
|
1032
|
+
translate(translation) {
|
|
1033
|
+
_assertClass(translation, Vector3D);
|
|
1034
|
+
var ptr0 = translation.__destroy_into_raw();
|
|
1035
|
+
wasm.ogpolyline_translate(this.__wbg_ptr, ptr0);
|
|
1036
|
+
}
|
|
1037
|
+
/**
|
|
1038
|
+
* @param {Vector3D} position
|
|
1039
|
+
*/
|
|
1040
|
+
set_position(position) {
|
|
1041
|
+
_assertClass(position, Vector3D);
|
|
1042
|
+
var ptr0 = position.__destroy_into_raw();
|
|
1043
|
+
wasm.ogpolyline_set_position(this.__wbg_ptr, ptr0);
|
|
1044
|
+
}
|
|
1045
|
+
/**
|
|
1030
1046
|
* @param {(Vector3D)[]} points
|
|
1031
1047
|
*/
|
|
1032
|
-
|
|
1048
|
+
add_multiple_points(points) {
|
|
1033
1049
|
const ptr0 = passArrayJsValueToWasm0(points, wasm.__wbindgen_malloc);
|
|
1034
1050
|
const len0 = WASM_VECTOR_LEN;
|
|
1035
|
-
wasm.
|
|
1051
|
+
wasm.ogpolyline_add_multiple_points(this.__wbg_ptr, ptr0, len0);
|
|
1036
1052
|
}
|
|
1037
1053
|
/**
|
|
1038
1054
|
* @param {Vector3D} point
|
|
@@ -1043,16 +1059,6 @@ class OGPolyLine {
|
|
|
1043
1059
|
wasm.ogpolyline_add_point(this.__wbg_ptr, ptr0);
|
|
1044
1060
|
}
|
|
1045
1061
|
/**
|
|
1046
|
-
*/
|
|
1047
|
-
dispose_points() {
|
|
1048
|
-
wasm.ogpolyline_destroy(this.__wbg_ptr);
|
|
1049
|
-
}
|
|
1050
|
-
/**
|
|
1051
|
-
*/
|
|
1052
|
-
destroy() {
|
|
1053
|
-
wasm.ogpolyline_destroy(this.__wbg_ptr);
|
|
1054
|
-
}
|
|
1055
|
-
/**
|
|
1056
1062
|
* @returns {string}
|
|
1057
1063
|
*/
|
|
1058
1064
|
get_points() {
|
|
@@ -1099,6 +1105,65 @@ class OGPolyLine {
|
|
|
1099
1105
|
check_closed_test() {
|
|
1100
1106
|
wasm.ogpolyline_check_closed_test(this.__wbg_ptr);
|
|
1101
1107
|
}
|
|
1108
|
+
/**
|
|
1109
|
+
*/
|
|
1110
|
+
generate_brep() {
|
|
1111
|
+
wasm.ogpolyline_generate_brep(this.__wbg_ptr);
|
|
1112
|
+
}
|
|
1113
|
+
/**
|
|
1114
|
+
* @returns {string}
|
|
1115
|
+
*/
|
|
1116
|
+
get_brep_data() {
|
|
1117
|
+
let deferred1_0;
|
|
1118
|
+
let deferred1_1;
|
|
1119
|
+
try {
|
|
1120
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1121
|
+
wasm.ogpolyline_get_brep_data(retptr, this.__wbg_ptr);
|
|
1122
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1123
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1124
|
+
deferred1_0 = r0;
|
|
1125
|
+
deferred1_1 = r1;
|
|
1126
|
+
return getStringFromWasm0(r0, r1);
|
|
1127
|
+
} finally {
|
|
1128
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1129
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
/**
|
|
1133
|
+
* @param {number} distance
|
|
1134
|
+
* @returns {string}
|
|
1135
|
+
*/
|
|
1136
|
+
get_offset(distance) {
|
|
1137
|
+
let deferred1_0;
|
|
1138
|
+
let deferred1_1;
|
|
1139
|
+
try {
|
|
1140
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1141
|
+
wasm.ogpolyline_get_offset(retptr, this.__wbg_ptr, distance);
|
|
1142
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1143
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1144
|
+
deferred1_0 = r0;
|
|
1145
|
+
deferred1_1 = r1;
|
|
1146
|
+
return getStringFromWasm0(r0, r1);
|
|
1147
|
+
} finally {
|
|
1148
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1149
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
/**
|
|
1153
|
+
* @param {Vector3D} point_a
|
|
1154
|
+
* @param {Vector3D} point_b
|
|
1155
|
+
* @param {Vector3D} point_c
|
|
1156
|
+
* @param {Vector3D} point_d
|
|
1157
|
+
* @returns {Vector3D | undefined}
|
|
1158
|
+
*/
|
|
1159
|
+
static calculate_2D_interesection(point_a, point_b, point_c, point_d) {
|
|
1160
|
+
_assertClass(point_a, Vector3D);
|
|
1161
|
+
_assertClass(point_b, Vector3D);
|
|
1162
|
+
_assertClass(point_c, Vector3D);
|
|
1163
|
+
_assertClass(point_d, Vector3D);
|
|
1164
|
+
const ret = wasm.ogpolyline_calculate_2D_interesection(point_a.__wbg_ptr, point_b.__wbg_ptr, point_c.__wbg_ptr, point_d.__wbg_ptr);
|
|
1165
|
+
return ret === 0 ? undefined : Vector3D.__wrap(ret);
|
|
1166
|
+
}
|
|
1102
1167
|
}
|
|
1103
1168
|
const OGPolygonFinalization = typeof FinalizationRegistry === 'undefined' ? {
|
|
1104
1169
|
register: () => {},
|
|
@@ -1247,6 +1312,14 @@ class OGPolygon {
|
|
|
1247
1312
|
return this;
|
|
1248
1313
|
}
|
|
1249
1314
|
/**
|
|
1315
|
+
* @param {Vector3D} translation
|
|
1316
|
+
*/
|
|
1317
|
+
translate(translation) {
|
|
1318
|
+
_assertClass(translation, Vector3D);
|
|
1319
|
+
var ptr0 = translation.__destroy_into_raw();
|
|
1320
|
+
wasm.ogpolygon_translate(this.__wbg_ptr, ptr0);
|
|
1321
|
+
}
|
|
1322
|
+
/**
|
|
1250
1323
|
* @param {CircleArc} circle_arc
|
|
1251
1324
|
* @returns {OGPolygon}
|
|
1252
1325
|
*/
|
|
@@ -1369,6 +1442,11 @@ class OGPolygon {
|
|
|
1369
1442
|
}
|
|
1370
1443
|
/**
|
|
1371
1444
|
*/
|
|
1445
|
+
clear_buffer() {
|
|
1446
|
+
wasm.ogpolygon_clear_buffer(this.__wbg_ptr);
|
|
1447
|
+
}
|
|
1448
|
+
/**
|
|
1449
|
+
*/
|
|
1372
1450
|
clear_vertices() {
|
|
1373
1451
|
wasm.ogpolygon_clear_vertices(this.__wbg_ptr);
|
|
1374
1452
|
}
|
|
@@ -1493,6 +1571,25 @@ class OGPolygon {
|
|
|
1493
1571
|
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
1494
1572
|
}
|
|
1495
1573
|
}
|
|
1574
|
+
/**
|
|
1575
|
+
* @returns {string}
|
|
1576
|
+
*/
|
|
1577
|
+
binary_tree() {
|
|
1578
|
+
let deferred1_0;
|
|
1579
|
+
let deferred1_1;
|
|
1580
|
+
try {
|
|
1581
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1582
|
+
wasm.ogpolygon_binary_tree(retptr, this.__wbg_ptr);
|
|
1583
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1584
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1585
|
+
deferred1_0 = r0;
|
|
1586
|
+
deferred1_1 = r1;
|
|
1587
|
+
return getStringFromWasm0(r0, r1);
|
|
1588
|
+
} finally {
|
|
1589
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1590
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1496
1593
|
}
|
|
1497
1594
|
const OGRectangleFinalization = typeof FinalizationRegistry === 'undefined' ? {
|
|
1498
1595
|
register: () => {},
|
|
@@ -1928,6 +2025,44 @@ class Vector3D {
|
|
|
1928
2025
|
const ret = wasm.vector3d_clone(this.__wbg_ptr);
|
|
1929
2026
|
return Vector3D.__wrap(ret);
|
|
1930
2027
|
}
|
|
2028
|
+
/**
|
|
2029
|
+
* @returns {number}
|
|
2030
|
+
*/
|
|
2031
|
+
length_squared() {
|
|
2032
|
+
const ret = wasm.vector3d_length_squared(this.__wbg_ptr);
|
|
2033
|
+
return ret;
|
|
2034
|
+
}
|
|
2035
|
+
/**
|
|
2036
|
+
* @returns {number}
|
|
2037
|
+
*/
|
|
2038
|
+
magnitude() {
|
|
2039
|
+
const ret = wasm.vector3d_magnitude(this.__wbg_ptr);
|
|
2040
|
+
return ret;
|
|
2041
|
+
}
|
|
2042
|
+
/**
|
|
2043
|
+
* @returns {Vector3D}
|
|
2044
|
+
*/
|
|
2045
|
+
normalize() {
|
|
2046
|
+
const ret = wasm.vector3d_normalize(this.__wbg_ptr);
|
|
2047
|
+
return Vector3D.__wrap(ret);
|
|
2048
|
+
}
|
|
2049
|
+
/**
|
|
2050
|
+
* @param {number} scalar
|
|
2051
|
+
* @returns {Vector3D}
|
|
2052
|
+
*/
|
|
2053
|
+
multiply(scalar) {
|
|
2054
|
+
const ret = wasm.vector3d_multiply(this.__wbg_ptr, scalar);
|
|
2055
|
+
return Vector3D.__wrap(ret);
|
|
2056
|
+
}
|
|
2057
|
+
/**
|
|
2058
|
+
* @param {Vector3D} other
|
|
2059
|
+
* @returns {number}
|
|
2060
|
+
*/
|
|
2061
|
+
distance_to(other) {
|
|
2062
|
+
_assertClass(other, Vector3D);
|
|
2063
|
+
const ret = wasm.vector3d_distance_to(this.__wbg_ptr, other.__wbg_ptr);
|
|
2064
|
+
return ret;
|
|
2065
|
+
}
|
|
1931
2066
|
}
|
|
1932
2067
|
async function __wbg_load(module, imports) {
|
|
1933
2068
|
if (typeof Response === 'function' && module instanceof Response) {
|
|
@@ -1959,6 +2094,13 @@ async function __wbg_load(module, imports) {
|
|
|
1959
2094
|
function __wbg_get_imports() {
|
|
1960
2095
|
const imports = {};
|
|
1961
2096
|
imports.wbg = {};
|
|
2097
|
+
imports.wbg.__wbindgen_string_new = function (arg0, arg1) {
|
|
2098
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
2099
|
+
return addHeapObject(ret);
|
|
2100
|
+
};
|
|
2101
|
+
imports.wbg.__wbindgen_object_drop_ref = function (arg0) {
|
|
2102
|
+
takeObject(arg0);
|
|
2103
|
+
};
|
|
1962
2104
|
imports.wbg.__wbg_vector3d_new = function (arg0) {
|
|
1963
2105
|
const ret = Vector3D.__wrap(arg0);
|
|
1964
2106
|
return addHeapObject(ret);
|
|
@@ -1967,9 +2109,8 @@ function __wbg_get_imports() {
|
|
|
1967
2109
|
const ret = Vector3D.__unwrap(takeObject(arg0));
|
|
1968
2110
|
return ret;
|
|
1969
2111
|
};
|
|
1970
|
-
imports.wbg.
|
|
1971
|
-
|
|
1972
|
-
return addHeapObject(ret);
|
|
2112
|
+
imports.wbg.__wbg_log_b103404cc5920657 = function (arg0) {
|
|
2113
|
+
console.log(getObject(arg0));
|
|
1973
2114
|
};
|
|
1974
2115
|
imports.wbg.__wbindgen_throw = function (arg0, arg1) {
|
|
1975
2116
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
@@ -13382,12 +13523,14 @@ class Pencil {
|
|
|
13382
13523
|
// Raycaster
|
|
13383
13524
|
this.raycaster.params.Line.threshold = 0.1;
|
|
13384
13525
|
// A Dummy Ground Plane
|
|
13385
|
-
const geometry = new PlaneGeometry(
|
|
13526
|
+
const geometry = new PlaneGeometry(1000, 1000);
|
|
13527
|
+
// const material = new THREE.MeshBasicMaterial({ color: 0xffff00, side: THREE.DoubleSide, wireframe: true });
|
|
13386
13528
|
const material = new MeshBasicMaterial({ color: 0xffff00, side: DoubleSide, transparent: true, opacity: 0 });
|
|
13387
13529
|
const plane = new Mesh(geometry, material);
|
|
13388
13530
|
plane.name = "pencil-ground";
|
|
13389
13531
|
plane.rotation.x = Math.PI / 2;
|
|
13390
13532
|
this.scene.add(plane);
|
|
13533
|
+
// plane.visible = true;
|
|
13391
13534
|
plane.visible = false;
|
|
13392
13535
|
this.dummyPlane = plane;
|
|
13393
13536
|
}
|
|
@@ -13460,6 +13603,17 @@ class Pencil {
|
|
|
13460
13603
|
}
|
|
13461
13604
|
});
|
|
13462
13605
|
}
|
|
13606
|
+
fireCursor(mouse) {
|
|
13607
|
+
const rect = this.container.getBoundingClientRect();
|
|
13608
|
+
const x = ((mouse.clientX - rect.left) / rect.width) * 2 - 1;
|
|
13609
|
+
const y = -((mouse.clientY - rect.top) / rect.height) * 2 + 1;
|
|
13610
|
+
this.raycaster.setFromCamera(new Vector2(x, y), this.camera);
|
|
13611
|
+
const intersects = this.raycaster.intersectObjects([this.dummyPlane]);
|
|
13612
|
+
if (intersects.length > 0) {
|
|
13613
|
+
const point = intersects[0].point;
|
|
13614
|
+
this.onCursorDown.trigger(point);
|
|
13615
|
+
}
|
|
13616
|
+
}
|
|
13463
13617
|
}
|
|
13464
13618
|
|
|
13465
13619
|
function spotLabelElement() {
|
|
@@ -13529,23 +13683,40 @@ class PolyLine extends Line {
|
|
|
13529
13683
|
this.material.color.set(color);
|
|
13530
13684
|
}
|
|
13531
13685
|
}
|
|
13532
|
-
constructor(points
|
|
13686
|
+
constructor(points) {
|
|
13533
13687
|
super();
|
|
13534
13688
|
this.points = [];
|
|
13535
13689
|
this.isClosed = false;
|
|
13690
|
+
this.polyline = null;
|
|
13536
13691
|
this.ogid = getUUID();
|
|
13537
|
-
this.points = points;
|
|
13538
13692
|
this.polyline = new OGPolyLine(this.ogid);
|
|
13539
|
-
|
|
13693
|
+
if (points) {
|
|
13694
|
+
this.addMultiplePoints(points);
|
|
13695
|
+
}
|
|
13696
|
+
}
|
|
13697
|
+
addMultiplePoints(points) {
|
|
13698
|
+
this.points = points;
|
|
13699
|
+
if (!this.polyline)
|
|
13700
|
+
return;
|
|
13701
|
+
this.polyline.add_multiple_points(points);
|
|
13540
13702
|
this.generateGeometry();
|
|
13541
13703
|
}
|
|
13542
|
-
|
|
13543
|
-
|
|
13704
|
+
// TODO: This needs to be improved
|
|
13705
|
+
translate(translation) {
|
|
13706
|
+
if (!this.polyline)
|
|
13707
|
+
return;
|
|
13708
|
+
this.polyline.translate(translation);
|
|
13709
|
+
this.generateGeometry();
|
|
13710
|
+
}
|
|
13711
|
+
set_position(position) {
|
|
13712
|
+
if (!this.polyline)
|
|
13544
13713
|
return;
|
|
13545
|
-
this.polyline.
|
|
13714
|
+
this.polyline.set_position(position);
|
|
13546
13715
|
}
|
|
13547
13716
|
addPoint(point) {
|
|
13548
13717
|
this.points.push(point);
|
|
13718
|
+
if (!this.polyline)
|
|
13719
|
+
return;
|
|
13549
13720
|
this.polyline.add_point(point);
|
|
13550
13721
|
if (this.points.length < 2)
|
|
13551
13722
|
return;
|
|
@@ -13556,6 +13727,8 @@ class PolyLine extends Line {
|
|
|
13556
13727
|
}
|
|
13557
13728
|
generateGeometry() {
|
|
13558
13729
|
this.clearGeometry();
|
|
13730
|
+
if (!this.polyline)
|
|
13731
|
+
return;
|
|
13559
13732
|
const buf = this.polyline.get_points();
|
|
13560
13733
|
const bufFlush = JSON.parse(buf);
|
|
13561
13734
|
const line = new BufferGeometry().setFromPoints(bufFlush);
|
|
@@ -13564,8 +13737,32 @@ class PolyLine extends Line {
|
|
|
13564
13737
|
this.material = material;
|
|
13565
13738
|
this.isClosed = this.polyline.is_closed();
|
|
13566
13739
|
}
|
|
13740
|
+
getBrepData() {
|
|
13741
|
+
if (!this.polyline)
|
|
13742
|
+
return null;
|
|
13743
|
+
return this.polyline.get_brep_data();
|
|
13744
|
+
}
|
|
13745
|
+
// TODO: Add proper return type
|
|
13746
|
+
createOffset(offset) {
|
|
13747
|
+
if (!this.polyline)
|
|
13748
|
+
return null;
|
|
13749
|
+
const offsetData = this.polyline.get_offset(offset);
|
|
13750
|
+
if (!offsetData)
|
|
13751
|
+
return null;
|
|
13752
|
+
const data = JSON.parse(offsetData);
|
|
13753
|
+
if (!data.treated || data.treated.length === 0) {
|
|
13754
|
+
return null;
|
|
13755
|
+
}
|
|
13756
|
+
return data;
|
|
13757
|
+
}
|
|
13758
|
+
dispose() {
|
|
13759
|
+
console.log("Disposing OG - Polyline");
|
|
13760
|
+
this.clearGeometry();
|
|
13761
|
+
this.polyline = null;
|
|
13762
|
+
}
|
|
13567
13763
|
}
|
|
13568
13764
|
|
|
13765
|
+
// TODO: What if user wants infintely smooth circle
|
|
13569
13766
|
class BaseCircle extends Line {
|
|
13570
13767
|
set color(color) {
|
|
13571
13768
|
if (this.material instanceof LineBasicMaterial) {
|
|
@@ -13590,7 +13787,6 @@ class BaseCircle extends Line {
|
|
|
13590
13787
|
this.circleArc.generate_points();
|
|
13591
13788
|
const bufRaw = this.circleArc.get_points();
|
|
13592
13789
|
const bufFlush = JSON.parse(bufRaw);
|
|
13593
|
-
console.log(bufFlush);
|
|
13594
13790
|
const line = new BufferGeometry().setFromPoints(bufFlush);
|
|
13595
13791
|
const material = new LineBasicMaterial({ color: 0x000000 });
|
|
13596
13792
|
this.geometry = line;
|
|
@@ -13609,11 +13805,13 @@ class BaseCircle extends Line {
|
|
|
13609
13805
|
}
|
|
13610
13806
|
}
|
|
13611
13807
|
|
|
13612
|
-
|
|
13808
|
+
class BasePrimitive extends Line {
|
|
13809
|
+
}
|
|
13810
|
+
|
|
13613
13811
|
/**
|
|
13614
13812
|
* Rectangle
|
|
13615
13813
|
*/
|
|
13616
|
-
class Rectangle extends
|
|
13814
|
+
class Rectangle extends BasePrimitive {
|
|
13617
13815
|
set width(width) {
|
|
13618
13816
|
this.options.width = width;
|
|
13619
13817
|
this.polyLineRectangle.update_width(width);
|
|
@@ -13624,33 +13822,47 @@ class Rectangle extends Line {
|
|
|
13624
13822
|
this.polyLineRectangle.update_breadth(breadth);
|
|
13625
13823
|
this.generateGeometry();
|
|
13626
13824
|
}
|
|
13825
|
+
set center(center) {
|
|
13826
|
+
this.options.center = center;
|
|
13827
|
+
this.polyLineRectangle.update_center(center);
|
|
13828
|
+
this.generateGeometry();
|
|
13829
|
+
}
|
|
13627
13830
|
set color(color) {
|
|
13628
13831
|
if (this.material instanceof LineBasicMaterial) {
|
|
13629
13832
|
this.material.color.set(color);
|
|
13630
|
-
|
|
13833
|
+
this.options.color = color;
|
|
13631
13834
|
}
|
|
13632
13835
|
}
|
|
13633
13836
|
constructor(options) {
|
|
13837
|
+
var _a;
|
|
13634
13838
|
super();
|
|
13635
|
-
|
|
13636
|
-
|
|
13637
|
-
|
|
13638
|
-
|
|
13639
|
-
|
|
13640
|
-
|
|
13641
|
-
|
|
13839
|
+
this.options = {
|
|
13840
|
+
width: 1,
|
|
13841
|
+
breadth: 1,
|
|
13842
|
+
center: new Vector3D(0, 0, 0),
|
|
13843
|
+
color: 0x000000,
|
|
13844
|
+
};
|
|
13845
|
+
const ogid = (_a = options === null || options === void 0 ? void 0 : options.ogid) !== null && _a !== void 0 ? _a : getUUID();
|
|
13846
|
+
this.polyLineRectangle = new OGRectangle(ogid);
|
|
13847
|
+
const mergedOptions = Object.assign(Object.assign(Object.assign({}, this.options), options), { ogid });
|
|
13848
|
+
this.setConfig(mergedOptions);
|
|
13642
13849
|
this.generateGeometry();
|
|
13643
13850
|
}
|
|
13644
|
-
setConfig() {
|
|
13851
|
+
setConfig(options) {
|
|
13852
|
+
this.options = options;
|
|
13853
|
+
console.log("Rectangle options set:", this.options);
|
|
13645
13854
|
const { breadth, width, center } = this.options;
|
|
13646
13855
|
this.polyLineRectangle.set_config(center, width, breadth);
|
|
13647
13856
|
}
|
|
13857
|
+
getConfig() {
|
|
13858
|
+
return this.options;
|
|
13859
|
+
}
|
|
13648
13860
|
generateGeometry() {
|
|
13649
13861
|
this.polyLineRectangle.generate_points();
|
|
13650
13862
|
const bufRaw = this.polyLineRectangle.get_points();
|
|
13651
13863
|
const bufFlush = JSON.parse(bufRaw);
|
|
13652
13864
|
const line = new BufferGeometry().setFromPoints(bufFlush);
|
|
13653
|
-
const material = new LineBasicMaterial({ color:
|
|
13865
|
+
const material = new LineBasicMaterial({ color: this.options.color });
|
|
13654
13866
|
this.geometry = line;
|
|
13655
13867
|
this.material = material;
|
|
13656
13868
|
}
|
|
@@ -13658,7 +13870,6 @@ class Rectangle extends Line {
|
|
|
13658
13870
|
this.geometry.dispose();
|
|
13659
13871
|
}
|
|
13660
13872
|
}
|
|
13661
|
-
_Rectangle_color = new WeakMap();
|
|
13662
13873
|
|
|
13663
13874
|
var _Cylinder_outlineMesh;
|
|
13664
13875
|
class Cylinder extends Mesh {
|
|
@@ -13770,6 +13981,19 @@ class Polygon extends Mesh {
|
|
|
13770
13981
|
// return originalCopy(v);
|
|
13771
13982
|
// };
|
|
13772
13983
|
}
|
|
13984
|
+
translate(translation) {
|
|
13985
|
+
if (!this.polygon)
|
|
13986
|
+
return;
|
|
13987
|
+
console.log("Translating polygon by", translation.x, translation.y, translation.z);
|
|
13988
|
+
this.geometry.dispose();
|
|
13989
|
+
this.polygon.clear_buffer();
|
|
13990
|
+
this.polygon.translate(translation);
|
|
13991
|
+
this.polygon.triangulate();
|
|
13992
|
+
console.log("Polygon translated by", translation);
|
|
13993
|
+
const bufFlush = this.polygon.get_buffer_flush();
|
|
13994
|
+
console.log("Buffer flush after translation:", bufFlush);
|
|
13995
|
+
this.addFlushBufferToScene(bufFlush);
|
|
13996
|
+
}
|
|
13773
13997
|
addVertices(vertices) {
|
|
13774
13998
|
var _a, _b;
|
|
13775
13999
|
if (!this.polygon)
|
|
@@ -13785,7 +14009,7 @@ class Polygon extends Mesh {
|
|
|
13785
14009
|
return;
|
|
13786
14010
|
this.layerVertices = [];
|
|
13787
14011
|
this.geometry.dispose();
|
|
13788
|
-
(_a = this.polygon) === null || _a === void 0 ? void 0 : _a.
|
|
14012
|
+
(_a = this.polygon) === null || _a === void 0 ? void 0 : _a.clear_vertices();
|
|
13789
14013
|
this.isTriangulated = false;
|
|
13790
14014
|
}
|
|
13791
14015
|
addVertex(threeVertex) {
|
|
@@ -13793,7 +14017,7 @@ class Polygon extends Mesh {
|
|
|
13793
14017
|
if (this.isTriangulated) {
|
|
13794
14018
|
this.layerVertices = [];
|
|
13795
14019
|
this.geometry.dispose();
|
|
13796
|
-
(_a = this.polygon) === null || _a === void 0 ? void 0 : _a.
|
|
14020
|
+
(_a = this.polygon) === null || _a === void 0 ? void 0 : _a.clear_vertices();
|
|
13797
14021
|
this.isTriangulated = false;
|
|
13798
14022
|
for (const vertex of this.layerBackVertices) {
|
|
13799
14023
|
this.layerVertices.push(vertex.clone());
|
|
@@ -13835,7 +14059,7 @@ class Polygon extends Mesh {
|
|
|
13835
14059
|
geometry.computeVertexNormals();
|
|
13836
14060
|
const material = new MeshStandardMaterial({
|
|
13837
14061
|
color: 0x00ff00,
|
|
13838
|
-
|
|
14062
|
+
side: DoubleSide,
|
|
13839
14063
|
transparent: true,
|
|
13840
14064
|
opacity: 0.5,
|
|
13841
14065
|
// wireframe: true
|
|
@@ -13858,18 +14082,31 @@ class Polygon extends Mesh {
|
|
|
13858
14082
|
geometry.setAttribute("position", new BufferAttribute(new Float32Array(flushBuffer), 3));
|
|
13859
14083
|
geometry.computeVertexNormals();
|
|
13860
14084
|
this.geometry = geometry;
|
|
13861
|
-
|
|
13862
|
-
|
|
13863
|
-
|
|
13864
|
-
|
|
13865
|
-
|
|
14085
|
+
const material = new MeshStandardMaterial({
|
|
14086
|
+
color: 0x00ff00,
|
|
14087
|
+
side: FrontSide,
|
|
14088
|
+
transparent: true,
|
|
14089
|
+
opacity: 0.5,
|
|
14090
|
+
// wireframe: true
|
|
14091
|
+
});
|
|
14092
|
+
this.material = material;
|
|
13866
14093
|
}
|
|
13867
14094
|
getBrepData() {
|
|
13868
14095
|
if (!this.polygon)
|
|
13869
|
-
return;
|
|
14096
|
+
return null;
|
|
13870
14097
|
const brepData = this.polygon.get_brep_data();
|
|
13871
|
-
|
|
13872
|
-
|
|
14098
|
+
return brepData;
|
|
14099
|
+
}
|
|
14100
|
+
set outlineColor(color) {
|
|
14101
|
+
if (__classPrivateFieldGet(this, _Polygon_outlineMesh, "f") && __classPrivateFieldGet(this, _Polygon_outlineMesh, "f").material instanceof LineBasicMaterial) {
|
|
14102
|
+
__classPrivateFieldGet(this, _Polygon_outlineMesh, "f").material.color.set(color);
|
|
14103
|
+
}
|
|
14104
|
+
}
|
|
14105
|
+
get outlineColor() {
|
|
14106
|
+
if (__classPrivateFieldGet(this, _Polygon_outlineMesh, "f") && __classPrivateFieldGet(this, _Polygon_outlineMesh, "f").material instanceof LineBasicMaterial) {
|
|
14107
|
+
return __classPrivateFieldGet(this, _Polygon_outlineMesh, "f").material.color.getHex();
|
|
14108
|
+
}
|
|
14109
|
+
return 0x000000; // Default color if outline mesh is not present
|
|
13873
14110
|
}
|
|
13874
14111
|
set outline(enable) {
|
|
13875
14112
|
if (enable && !__classPrivateFieldGet(this, _Polygon_outlineMesh, "f") && this.polygon) {
|
|
@@ -13899,23 +14136,93 @@ class Polygon extends Mesh {
|
|
|
13899
14136
|
}
|
|
13900
14137
|
return false;
|
|
13901
14138
|
}
|
|
14139
|
+
bTree() {
|
|
14140
|
+
if (!this.polygon)
|
|
14141
|
+
return;
|
|
14142
|
+
const bTree = this.polygon.binary_tree();
|
|
14143
|
+
const parsedData = JSON.parse(bTree);
|
|
14144
|
+
console.log(parsedData);
|
|
14145
|
+
}
|
|
14146
|
+
dispose() {
|
|
14147
|
+
// console.log("Disposing OG - Polygon");
|
|
14148
|
+
this.geometry.dispose();
|
|
14149
|
+
if (this.material instanceof Material) {
|
|
14150
|
+
this.material.dispose();
|
|
14151
|
+
}
|
|
14152
|
+
if (__classPrivateFieldGet(this, _Polygon_outlineMesh, "f")) {
|
|
14153
|
+
__classPrivateFieldGet(this, _Polygon_outlineMesh, "f").geometry.dispose();
|
|
14154
|
+
if (__classPrivateFieldGet(this, _Polygon_outlineMesh, "f").material instanceof Material) {
|
|
14155
|
+
__classPrivateFieldGet(this, _Polygon_outlineMesh, "f").material.dispose();
|
|
14156
|
+
}
|
|
14157
|
+
}
|
|
14158
|
+
this.polygon = null;
|
|
14159
|
+
this.layerVertices = [];
|
|
14160
|
+
this.layerBackVertices = [];
|
|
14161
|
+
}
|
|
13902
14162
|
}
|
|
13903
14163
|
_Polygon_outlineMesh = new WeakMap();
|
|
13904
14164
|
|
|
13905
14165
|
class OpenGeometry {
|
|
14166
|
+
set enablePencil(value) {
|
|
14167
|
+
if (value && !this._pencil) {
|
|
14168
|
+
if (!this.container || !this.scene) {
|
|
14169
|
+
throw new Error("Container or Scene is not defined");
|
|
14170
|
+
}
|
|
14171
|
+
this._pencil = new Pencil(this.container, this.scene, this.camera);
|
|
14172
|
+
}
|
|
14173
|
+
else if (!value && this._pencil) ;
|
|
14174
|
+
}
|
|
14175
|
+
get pencil() {
|
|
14176
|
+
return this._pencil;
|
|
14177
|
+
}
|
|
14178
|
+
get labelRenderer() {
|
|
14179
|
+
return this._labelRenderer;
|
|
14180
|
+
}
|
|
14181
|
+
get enableDebug() {
|
|
14182
|
+
return this._enableDebug;
|
|
14183
|
+
}
|
|
14184
|
+
/**
|
|
14185
|
+
* Enables or disables debug mode for OpenGeometry.
|
|
14186
|
+
* When enabled, it logs debug information to the console.
|
|
14187
|
+
* Addtionally,
|
|
14188
|
+
* 1. The geometry will be rendered with a semi-transparent material.
|
|
14189
|
+
* 2. The faces will be rendered with a random color.
|
|
14190
|
+
* 3. The normals will be rendered for better visualization.
|
|
14191
|
+
* @param value - A boolean indicating whether to enable or disable debug mode.
|
|
14192
|
+
*/
|
|
14193
|
+
set enableDebug(value) {
|
|
14194
|
+
this._enableDebug = value;
|
|
14195
|
+
if (this._enableDebug) {
|
|
14196
|
+
console.log("OpenGeometry Debug Mode Enabled");
|
|
14197
|
+
}
|
|
14198
|
+
}
|
|
13906
14199
|
constructor(container, threeScene, camera) {
|
|
13907
14200
|
this.camera = camera;
|
|
14201
|
+
this._enableDebug = false;
|
|
13908
14202
|
this.scene = threeScene;
|
|
13909
14203
|
this.container = container;
|
|
13910
14204
|
}
|
|
13911
|
-
|
|
13912
|
-
|
|
13913
|
-
|
|
13914
|
-
|
|
13915
|
-
|
|
13916
|
-
|
|
13917
|
-
|
|
13918
|
-
|
|
14205
|
+
/**
|
|
14206
|
+
* Asynchronously creates and initializes an instance of OpenGeometry.
|
|
14207
|
+
*
|
|
14208
|
+
* This factory method sets up the OpenGeometry engine by linking it with the
|
|
14209
|
+
* rendering context and the WebAssembly module. It ensures all required
|
|
14210
|
+
* options are provided and prepares the instance for 3D geometry operations.
|
|
14211
|
+
*
|
|
14212
|
+
* @param options - Configuration object for initializing OpenGeometry.
|
|
14213
|
+
* @returns A promise that resolves to a fully initialized OpenGeometry instance.
|
|
14214
|
+
* @throws If any of the required options (`container`, `scene`, or `camera`) are missing.
|
|
14215
|
+
*
|
|
14216
|
+
* @example
|
|
14217
|
+
* ```ts
|
|
14218
|
+
* const openGeometry = await OpenGeometry.create({
|
|
14219
|
+
* container: document.getElementById('myContainer')!,
|
|
14220
|
+
* scene: threeScene,
|
|
14221
|
+
* camera: threeCamera,
|
|
14222
|
+
* wasmURL: '/assets/opengeometry.wasm'
|
|
14223
|
+
* });
|
|
14224
|
+
* ```
|
|
14225
|
+
*/
|
|
13919
14226
|
static create(options) {
|
|
13920
14227
|
return __awaiter(this, void 0, void 0, function* () {
|
|
13921
14228
|
const { container, scene, camera } = options;
|
|
@@ -13931,18 +14238,9 @@ class OpenGeometry {
|
|
|
13931
14238
|
return __awaiter(this, void 0, void 0, function* () {
|
|
13932
14239
|
yield __wbg_init(wasmURL);
|
|
13933
14240
|
this.setuplabelRenderer();
|
|
13934
|
-
if (!this.container || !this.scene)
|
|
13935
|
-
return;
|
|
13936
|
-
this._pencil = new Pencil(this.container, this.scene, this.camera);
|
|
13937
14241
|
this.setupEvent();
|
|
13938
14242
|
});
|
|
13939
14243
|
}
|
|
13940
|
-
get pencil() {
|
|
13941
|
-
return this._pencil;
|
|
13942
|
-
}
|
|
13943
|
-
get labelRenderer() {
|
|
13944
|
-
return this._labelRenderer;
|
|
13945
|
-
}
|
|
13946
14244
|
setuplabelRenderer() {
|
|
13947
14245
|
if (!this.container || !this.scene) {
|
|
13948
14246
|
throw new Error("Container or Scene is not defined");
|
|
@@ -13955,6 +14253,8 @@ class OpenGeometry {
|
|
|
13955
14253
|
this._labelRenderer = labelRenderer;
|
|
13956
14254
|
}
|
|
13957
14255
|
setupEvent() {
|
|
14256
|
+
// NOTE: The responsibility to resize normal rendererer lies with the user
|
|
14257
|
+
// but the label renderer should be resized automatically
|
|
13958
14258
|
window.addEventListener("resize", () => {
|
|
13959
14259
|
var _a, _b, _c;
|
|
13960
14260
|
if (!this.container)
|
|
@@ -13962,6 +14262,13 @@ class OpenGeometry {
|
|
|
13962
14262
|
(_a = this._labelRenderer) === null || _a === void 0 ? void 0 : _a.setSize((_b = this.container) === null || _b === void 0 ? void 0 : _b.clientWidth, (_c = this.container) === null || _c === void 0 ? void 0 : _c.clientHeight);
|
|
13963
14263
|
});
|
|
13964
14264
|
}
|
|
14265
|
+
// TODO: Can this be handled inside the OpenGeometry class itself?
|
|
14266
|
+
/**
|
|
14267
|
+
* Updates the label renderer to render the scene with the given camera.
|
|
14268
|
+
* This method should be called in the animation loop or render loop of your application.
|
|
14269
|
+
* @param scene - The Three.js scene containing the objects to be rendered.
|
|
14270
|
+
* @param camera - The Three.js camera used for rendering the scene.
|
|
14271
|
+
*/
|
|
13965
14272
|
update(scene, camera) {
|
|
13966
14273
|
var _a;
|
|
13967
14274
|
(_a = this._labelRenderer) === null || _a === void 0 ? void 0 : _a.render(scene, camera);
|
|
@@ -14275,6 +14582,15 @@ class CirclePoly extends Mesh {
|
|
|
14275
14582
|
this.geometry = geometry;
|
|
14276
14583
|
// this.material = material;
|
|
14277
14584
|
}
|
|
14585
|
+
dispose() {
|
|
14586
|
+
var _a;
|
|
14587
|
+
if (!this.polygon)
|
|
14588
|
+
return;
|
|
14589
|
+
this.geometry.dispose();
|
|
14590
|
+
(_a = this.polygon) === null || _a === void 0 ? void 0 : _a.clear_vertices();
|
|
14591
|
+
this.polygon = null;
|
|
14592
|
+
this.isExtruded = false;
|
|
14593
|
+
}
|
|
14278
14594
|
}
|
|
14279
14595
|
class RectanglePoly extends Mesh {
|
|
14280
14596
|
constructor(baseRectangle) {
|
|
@@ -14282,27 +14598,26 @@ class RectanglePoly extends Mesh {
|
|
|
14282
14598
|
this.polygon = null;
|
|
14283
14599
|
this.isExtruded = false;
|
|
14284
14600
|
this.ogid = getUUID();
|
|
14285
|
-
if (!baseRectangle.polyLineRectangle) {
|
|
14286
|
-
|
|
14287
|
-
}
|
|
14288
|
-
// baseRectangle.nodeChild = this;
|
|
14289
|
-
baseRectangle.nodeOperation = "polygon";
|
|
14601
|
+
// if (!baseRectangle.polyLineRectangle) {
|
|
14602
|
+
// throw new Error("BaseRectangle is not defined");
|
|
14603
|
+
// }
|
|
14604
|
+
// // baseRectangle.nodeChild = this;
|
|
14605
|
+
// baseRectangle.nodeOperation = "polygon";
|
|
14290
14606
|
this.baseRectangle = baseRectangle;
|
|
14291
14607
|
this.generateGeometry();
|
|
14292
14608
|
this.addFlushBufferToScene();
|
|
14293
14609
|
}
|
|
14294
14610
|
update() {
|
|
14295
|
-
var _a
|
|
14611
|
+
var _a;
|
|
14296
14612
|
this.geometry.dispose();
|
|
14297
14613
|
(_a = this.polygon) === null || _a === void 0 ? void 0 : _a.clear_vertices();
|
|
14298
|
-
|
|
14614
|
+
// this.polygon?.add_vertices(this.baseRectangle.polyLineRectangle.get_raw_points());
|
|
14299
14615
|
this.generateGeometry();
|
|
14300
14616
|
this.addFlushBufferToScene();
|
|
14301
14617
|
}
|
|
14302
14618
|
generateGeometry() {
|
|
14303
|
-
if (!this.baseRectangle.polyLineRectangle)
|
|
14304
|
-
|
|
14305
|
-
this.polygon = BasePolygon.new_with_rectangle(this.baseRectangle.polyLineRectangle.clone());
|
|
14619
|
+
// if (!this.baseRectangle.polyLineRectangle) return;
|
|
14620
|
+
// this.polygon = BasePolygon.new_with_rectangle(this.baseRectangle.polyLineRectangle.clone());
|
|
14306
14621
|
}
|
|
14307
14622
|
addFlushBufferToScene() {
|
|
14308
14623
|
if (!this.polygon)
|