From 5ddf4aeb18973bb397ef0683588be638dec7c117 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Thu, 30 Dec 2021 23:23:45 -0500 Subject: [PATCH] add model opacity and wireframe --- src/mesh/model.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/mesh/model.js b/src/mesh/model.js index db990dc6..c8ca51ad 100644 --- a/src/mesh/model.js +++ b/src/mesh/model.js @@ -68,6 +68,40 @@ mesh.model = class MeshModel { this._group = gv; } + opacity(ov) { + let mat = this.mesh.material; + if (ov === undefined) { + return mat.opacity; + } + if (ov <= 0.0) { + mat.transparent = false; + mat.opacity = 1; + mat.visible = false; + } else { + mat.transparent = ov < 1.0; + mat.opacity = ov; + mat.visible = true; + } + moto.Space.update(); + } + + wireframe(bool, opt = {}) { + if (this._wire) { + this.mesh.remove(this._wire); + this._wire = undefined; + this.opacity(this._wireo); + } + if (bool) { + this._wireo = this.opacity(); + this._wire = new THREE.LineSegments( + new THREE.WireframeGeometry(this.mesh.geometry), + new THREE.LineBasicMaterial({ color: opt.color || 0 })); + this.mesh.add(this._wire); + this.opacity(opt.opacity || 0); + } + moto.Space.update(); + } + remove() { mesh.api.model.remove(this); }