opengeometry 0.0.1 → 0.0.2
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/README.md +4 -27
- package/index.d.ts +2 -0
- package/index.js +41 -36
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/src/elements/ogline.d.ts +0 -12
package/README.md
CHANGED
|
@@ -4,36 +4,13 @@
|
|
|
4
4
|
Expect frequent updates, breaking changes, and exciting new features.
|
|
5
5
|
|
|
6
6
|
# OpenGeometry
|
|
7
|
+
CAD Kernel for Web, built from scratch!
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
Documentation is available at [OpenGeometry Documentation](https://docs.opengeometry.io)
|
|
9
10
|
|
|
10
|
-
- `const openGeometry = new OpenGeometry()`
|
|
11
|
-
- `await openGeometry.setup()`
|
|
12
|
-
|
|
13
|
-
#### Create Polygon
|
|
14
|
-
- `const oPoly = new OPolygon()`
|
|
15
|
-
|
|
16
|
-
##### Add Points to Polygon
|
|
17
|
-
- addVertex(x:number, y:number, z:number) - Add Point to the Given Polygon
|
|
18
|
-
|
|
19
|
-
##### Generate Flat 2D Mesh
|
|
20
|
-
- generateMesh() - Created a Flat 2D Mesh from the given Vertices
|
|
21
|
-
- Minimum 3 Vertices are needed, else ask users for it
|
|
22
|
-
|
|
23
|
-
### Extrude
|
|
24
|
-
- Extrude is a operation which elevates the given 2D polygon by a given height
|
|
25
|
-
- `polygon.extrude(height: number)`
|
|
26
|
-
- returns a Buffer Geometry
|
|
27
|
-
|
|
28
|
-
- Scene Graph (List of Objects)
|
|
29
|
-
- Access to Scene Graph for other classes
|
|
30
|
-
- Bounding Boxes for BaseGeometry (min, max)
|
|
31
|
-
- Check Intersection with existing BBoxes - multiple cases - Partial Outside | Inside | Touching | Outside
|
|
32
|
-
|
|
33
|
-
### Test
|
|
34
11
|
#### Basic Example
|
|
35
|
-
- A basic example is available at
|
|
12
|
+
- A basic example is available at [Quick Start](https://github.com/OpenGeometry-io/quickstart-js)
|
|
36
13
|
|
|
37
14
|
#### Advanced and Additional Examples
|
|
38
15
|
- Extensive Examples(Source Code) have a separate repo - https://github.com/OpenGeometry-io/OpenGeometry-examples
|
|
39
|
-
- The live demo is available at [Kernel Examples](https://demos.opengeometry.io/
|
|
16
|
+
- The live demo is available at [Kernel Examples](https://demos.opengeometry.io/src/kernel/index.html)
|
package/index.d.ts
CHANGED
|
@@ -35,6 +35,8 @@ export declare class BasePoly extends THREE.Mesh {
|
|
|
35
35
|
addVertex(threeVertex: Vector3D): void;
|
|
36
36
|
addHole(holeVertices: Vector3D[]): void;
|
|
37
37
|
addFlushBufferToScene(flush: string): void;
|
|
38
|
+
extrude(height: number): void;
|
|
39
|
+
generateExtrudedGeometry(extruded_buff: string): void;
|
|
38
40
|
}
|
|
39
41
|
export declare class CirclePoly extends THREE.Mesh {
|
|
40
42
|
ogid: string;
|
package/index.js
CHANGED
|
@@ -13210,15 +13210,11 @@ class BasePoly extends Mesh {
|
|
|
13210
13210
|
}
|
|
13211
13211
|
}
|
|
13212
13212
|
addHole(holeVertices) {
|
|
13213
|
-
console.log(holeVertices);
|
|
13214
13213
|
if (!this.polygon)
|
|
13215
13214
|
return;
|
|
13216
13215
|
this.polygon.add_holes(holeVertices);
|
|
13217
|
-
console.log(this.polygon.get_geometry());
|
|
13218
13216
|
const triResult = JSON.parse(this.polygon.new_triangulate());
|
|
13219
|
-
console.log(triResult);
|
|
13220
13217
|
const newBufferFlush = triResult.new_buffer;
|
|
13221
|
-
console.log(newBufferFlush);
|
|
13222
13218
|
const geometry = new BufferGeometry();
|
|
13223
13219
|
geometry.setAttribute("position", new BufferAttribute(new Float32Array(newBufferFlush), 3));
|
|
13224
13220
|
this.geometry = geometry;
|
|
@@ -13227,14 +13223,31 @@ class BasePoly extends Mesh {
|
|
|
13227
13223
|
}
|
|
13228
13224
|
addFlushBufferToScene(flush) {
|
|
13229
13225
|
const flushBuffer = JSON.parse(flush);
|
|
13230
|
-
console.log(flushBuffer);
|
|
13231
13226
|
const geometry = new BufferGeometry();
|
|
13232
13227
|
geometry.setAttribute("position", new BufferAttribute(new Float32Array(flushBuffer), 3));
|
|
13233
|
-
|
|
13228
|
+
geometry.computeVertexNormals();
|
|
13229
|
+
const material = new MeshStandardMaterial({ color: 0x3a86ff, side: DoubleSide });
|
|
13230
|
+
this.geometry = geometry;
|
|
13231
|
+
this.material = material;
|
|
13232
|
+
}
|
|
13233
|
+
extrude(height) {
|
|
13234
|
+
if (!this.polygon)
|
|
13235
|
+
return;
|
|
13236
|
+
const extruded_buff = this.polygon.extrude_by_height(height);
|
|
13237
|
+
this.generateExtrudedGeometry(extruded_buff);
|
|
13238
|
+
}
|
|
13239
|
+
generateExtrudedGeometry(extruded_buff) {
|
|
13240
|
+
// THIS WORKS
|
|
13241
|
+
const flushBuffer = JSON.parse(extruded_buff);
|
|
13242
|
+
const geometry = new BufferGeometry();
|
|
13243
|
+
geometry.setAttribute("position", new BufferAttribute(new Float32Array(flushBuffer), 3));
|
|
13244
|
+
geometry.computeVertexNormals();
|
|
13245
|
+
const material = new MeshPhongMaterial({
|
|
13246
|
+
color: 0x3a86ff,
|
|
13247
|
+
});
|
|
13248
|
+
material.side = DoubleSide;
|
|
13234
13249
|
this.geometry = geometry;
|
|
13235
13250
|
this.material = material;
|
|
13236
|
-
// this.geometry.attributes.position.needsUpdate = true;
|
|
13237
|
-
// this.geometry.computeVertexNormals();
|
|
13238
13251
|
}
|
|
13239
13252
|
}
|
|
13240
13253
|
class CirclePoly extends Mesh {
|
|
@@ -13270,34 +13283,31 @@ class CirclePoly extends Mesh {
|
|
|
13270
13283
|
return;
|
|
13271
13284
|
const bufFlush = this.polygon.get_buffer_flush();
|
|
13272
13285
|
const flushBuffer = JSON.parse(bufFlush);
|
|
13273
|
-
console.log(flushBuffer);
|
|
13274
13286
|
const geometry = new BufferGeometry();
|
|
13275
13287
|
geometry.setAttribute("position", new BufferAttribute(new Float32Array(flushBuffer), 3));
|
|
13288
|
+
// TODO: Do this using a set method, poly.visualizeTriangles = true
|
|
13276
13289
|
// different colors for each triangle in the polygon dont interolate
|
|
13277
|
-
const colors = new Float32Array(flushBuffer.length);
|
|
13278
|
-
for (let i = 0; i < colors.length; i += 9) {
|
|
13279
|
-
|
|
13280
|
-
|
|
13281
|
-
|
|
13282
|
-
|
|
13283
|
-
|
|
13284
|
-
|
|
13285
|
-
|
|
13286
|
-
|
|
13287
|
-
|
|
13288
|
-
|
|
13289
|
-
|
|
13290
|
-
|
|
13291
|
-
}
|
|
13292
|
-
geometry.setAttribute('color', new BufferAttribute(colors, 3));
|
|
13293
|
-
const material = new
|
|
13294
|
-
color:
|
|
13295
|
-
flatShading: true,
|
|
13296
|
-
vertexColors: true,
|
|
13297
|
-
shininess: 0,
|
|
13290
|
+
// const colors = new Float32Array(flushBuffer.length);
|
|
13291
|
+
// for (let i = 0; i < colors.length; i += 9) {
|
|
13292
|
+
// const r = Math.random();
|
|
13293
|
+
// const g = Math.random();
|
|
13294
|
+
// const b = Math.random();
|
|
13295
|
+
// colors[i] = r;
|
|
13296
|
+
// colors[i + 1] = g;
|
|
13297
|
+
// colors[i + 2] = b;
|
|
13298
|
+
// colors[i + 3] = r;
|
|
13299
|
+
// colors[i + 4] = g;
|
|
13300
|
+
// colors[i + 5] = b;
|
|
13301
|
+
// colors[i + 6] = r;
|
|
13302
|
+
// colors[i + 7] = g;
|
|
13303
|
+
// colors[i + 8] = b;
|
|
13304
|
+
// }
|
|
13305
|
+
// geometry.setAttribute('color', new THREE.BufferAttribute(colors, 3));
|
|
13306
|
+
const material = new MeshStandardMaterial({
|
|
13307
|
+
color: 0x4460FF,
|
|
13298
13308
|
side: DoubleSide,
|
|
13299
13309
|
transparent: true,
|
|
13300
|
-
opacity: 0.
|
|
13310
|
+
opacity: 0.8
|
|
13301
13311
|
});
|
|
13302
13312
|
this.geometry = geometry;
|
|
13303
13313
|
this.material = material;
|
|
@@ -13309,7 +13319,6 @@ class CirclePoly extends Mesh {
|
|
|
13309
13319
|
if (!this.polygon)
|
|
13310
13320
|
return;
|
|
13311
13321
|
const extruded_buff = this.polygon.extrude_by_height(height);
|
|
13312
|
-
console.log(JSON.parse(extruded_buff));
|
|
13313
13322
|
this.isExtruded = true;
|
|
13314
13323
|
this.generateExtrudedGeometry(extruded_buff);
|
|
13315
13324
|
}
|
|
@@ -13357,7 +13366,6 @@ class CirclePoly extends Mesh {
|
|
|
13357
13366
|
center.add(vertex);
|
|
13358
13367
|
}
|
|
13359
13368
|
center.divideScalar(uniqueVertices.length);
|
|
13360
|
-
console.log(center);
|
|
13361
13369
|
uniqueVertices.sort((a, b) => {
|
|
13362
13370
|
if (type === "side") {
|
|
13363
13371
|
const angleA = Math.atan2(a.y - center.y, a.z - center.z);
|
|
@@ -13464,7 +13472,6 @@ class RectanglePoly extends Mesh {
|
|
|
13464
13472
|
return;
|
|
13465
13473
|
const bufFlush = this.polygon.get_buffer_flush();
|
|
13466
13474
|
const flushBuffer = JSON.parse(bufFlush);
|
|
13467
|
-
console.log(flushBuffer);
|
|
13468
13475
|
const geometry = new BufferGeometry();
|
|
13469
13476
|
geometry.setAttribute("position", new BufferAttribute(new Float32Array(flushBuffer), 3));
|
|
13470
13477
|
const material = new MeshStandardMaterial({ color: 0x3a86ff, transparent: true, opacity: 0.5 });
|
|
@@ -13478,7 +13485,6 @@ class RectanglePoly extends Mesh {
|
|
|
13478
13485
|
if (!this.polygon)
|
|
13479
13486
|
return;
|
|
13480
13487
|
const extruded_buff = this.polygon.extrude_by_height(height);
|
|
13481
|
-
console.log(JSON.parse(extruded_buff));
|
|
13482
13488
|
this.isExtruded = true;
|
|
13483
13489
|
this.generateExtrudedGeometry(extruded_buff);
|
|
13484
13490
|
}
|
|
@@ -13562,7 +13568,6 @@ class RectanglePoly extends Mesh {
|
|
|
13562
13568
|
center.add(vertex);
|
|
13563
13569
|
}
|
|
13564
13570
|
center.divideScalar(uniqueVertices.length);
|
|
13565
|
-
console.log(center);
|
|
13566
13571
|
uniqueVertices.sort((a, b) => {
|
|
13567
13572
|
if (type === "side") {
|
|
13568
13573
|
const angleA = Math.atan2(a.y - center.y, a.z - center.z);
|