From 0a0f892c4e1e6747d4fbc38ef77d1f8466fca801 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Fri, 15 Apr 2022 10:37:57 -0400 Subject: [PATCH] auto-fog in wireframe mode to make detailed close examination easier on busy models --- src/mesh/api.js | 16 ++++++++++++++-- src/moto/space.js | 22 +++++++++++++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/mesh/api.js b/src/mesh/api.js index 7f7d948c..73fe7d52 100644 --- a/src/mesh/api.js +++ b/src/mesh/api.js @@ -120,6 +120,7 @@ const selection = { group.wireframe(prefs.map.space.wire || false); group.normals(prefs.map.space.norm || false); } + api.updateFog(); // prevent selection of model and its group let mgsel = selected.filter(s => s instanceof mesh.model).map(m => m.group); selected = selected.filter(sel => !mgsel.contains(sel)).filter(v => v); @@ -647,7 +648,8 @@ const api = exports({ }, wireframe(state = {toggle:true}, opt = { }) { - let wire = prefs.map.space.wire; + const mspace = prefs.map.space; + let wire = mspace.wire; if (state.toggle) { wire = !wire; } else { @@ -656,7 +658,17 @@ const api = exports({ for (let m of model.list()) { m.wireframe(wire, opt); } - prefs.save( prefs.map.space.wire = wire ); + prefs.save( mspace.wire = wire ); + api.updateFog(); + }, + + updateFog() { + const mspace = prefs.map.space; + if (mspace.wire) { + space.scene.setFog(3, mspace.dark ? 0 : 0xffffff); + } else { + space.scene.setFog(false); + } }, normals(state = {toggle:true}) { diff --git a/src/moto/space.js b/src/moto/space.js index 1c6edd3b..ea77c51a 100644 --- a/src/moto/space.js +++ b/src/moto/space.js @@ -1044,7 +1044,26 @@ gapp.register("moto.space", [], (root, exports) => { return SCENE.remove(o); }, - active: updateLastAction + active: updateLastAction, + + setFog: function(mult, color) { + if (mult) { + SCENE.fog = new THREE.Fog(color, 100, 1000); + SCENE.fog.mult = mult > 0 ? mult : 3; + } else { + SCENE.fog = undefined; + } + Space.scene.updateFog(); + }, + + updateFog: function() { + const { fog } = SCENE; + if (fog) { + const dist = camera.position.distanceTo(viewControl.target); + fog.near = dist; + fog.far = dist * fog.mult; + } + } }, world: { @@ -1230,6 +1249,7 @@ gapp.register("moto.space", [], (root, exports) => { if (moved && platformOnMove) { clearTimeout(platformMoveTimer); platformMoveTimer = setTimeout(platformOnMove, 500); + Space.scene.updateFog(); } updateLastAction(); }, (val) => {