From aae60f1b0573a89f77a5af1fbc8eaf0aff4834bd Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Tue, 23 Jul 2024 22:45:27 -0400 Subject: [PATCH] add missing sketch module, remove logic --- package.json | 1 - src/mesh/sketch.js | 91 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 src/mesh/sketch.js diff --git a/package.json b/package.json index a80254f9..4b6e5dcd 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,6 @@ "earcut": "^2.2.3", "express-useragent": "^1.0.13", "jszip": "^3.7.1", - "logicjs": "^1.0.0", "manifold-3d": "^2.5.1", "moment": "^2.29.4", "serve-static": "^1.14.1", diff --git a/src/mesh/sketch.js b/src/mesh/sketch.js new file mode 100644 index 00000000..54a5e6e3 --- /dev/null +++ b/src/mesh/sketch.js @@ -0,0 +1,91 @@ +/** Copyright Stewart Allen -- All Rights Reserved */ + +"use strict"; + +// dep: add.array +// dep: add.three +// dep: moto.license +// dep: moto.client +// dep: mesh.object +// use: mesh.api +// use: mesh.util +// use: mesh.group +gapp.register("mesh.sketch", [], (root, exports) => { + +const { MeshBasicMaterial, LineBasicMaterial, LineSegments, DoubleSide } = THREE; +const { PlaneGeometry, EdgesGeometry, SphereGeometry, Group, Mesh } = THREE; +const { mesh, moto } = root; +const { space } = moto; + +const mapp = mesh; +const worker = moto.client.fn; + +const material = { + plane: new MeshBasicMaterial({ color: 0x888888, side: DoubleSide, transparent: true, opacity: 0.25 }), + outline: new LineBasicMaterial({ color: 0x88dddd, side: DoubleSide, transparent: true, opacity: 0.25 }), + handle: new MeshBasicMaterial({ color: 0x88dddd, side: DoubleSide, transparent: true, opacity: 0.25 }), + highlight: new LineBasicMaterial({ color: 0x88ffdd, side: DoubleSide, transparent: true, opacity: 0.5 }), + selected: new MeshBasicMaterial({ color: 0x88aa88, side: DoubleSide, transparent: true, opacity: 0.25 }), +}; + +/** 2D plane containing open and closed polygons which can be extruded **/ +mesh.sketch = class MeshSketch extends mesh.object { + constructor(model, face, id) { + super(id); + + const planeGeometry = new PlaneGeometry(10, 10); + const planeMaterial = material.plane; + const plane = this.plane = new Mesh(planeGeometry, planeMaterial); + + const outlineGeometry = new EdgesGeometry(planeGeometry); + const outlineMaterial = material.outline; + const outline = this.outline = new LineSegments(outlineGeometry, outlineMaterial); + plane.add(outline); + + const handleGeometry = new SphereGeometry(0.2, 16, 16); + const handleMaterial = material.handle; + + const handles = []; + const corners = [ [-5, 5, 0], [5, 5, 0], [-5, -5, 0], [5, -5, 0] ]; + + for (let corner of corners) { + const handle = new Mesh(handleGeometry, handleMaterial); + handle.position.set(...corner); + plane.add(handle); + handles.push(handle); + } + } + + get type() { + return "sketch"; + } + + get object() { + return this.plane; + } + + rename(newname) { + this.file = newname; + } + + highlight() { + this.outline.material = material.highlight; + } + + unhighlight() { + this.outline.material = material.outline; + } + + select(bool) { + if (bool === undefined) { + return this.plane.material === material.selected; + } + if (bool.toggle) { + return this.select(!this.select()); + } + return this.plane.material = (bool ? material.selected : material.plane); + } + +} + +}); \ No newline at end of file