auto-fog in wireframe mode to make detailed close examination easier on busy models

This commit is contained in:
Stewart Allen 2022-04-15 10:37:57 -04:00
commit 0a0f892c4e
2 changed files with 35 additions and 3 deletions

View file

@ -120,6 +120,7 @@ const selection = {
group.wireframe(prefs.map.space.wire || false); group.wireframe(prefs.map.space.wire || false);
group.normals(prefs.map.space.norm || false); group.normals(prefs.map.space.norm || false);
} }
api.updateFog();
// prevent selection of model and its group // prevent selection of model and its group
let mgsel = selected.filter(s => s instanceof mesh.model).map(m => m.group); let mgsel = selected.filter(s => s instanceof mesh.model).map(m => m.group);
selected = selected.filter(sel => !mgsel.contains(sel)).filter(v => v); selected = selected.filter(sel => !mgsel.contains(sel)).filter(v => v);
@ -647,7 +648,8 @@ const api = exports({
}, },
wireframe(state = {toggle:true}, opt = { }) { wireframe(state = {toggle:true}, opt = { }) {
let wire = prefs.map.space.wire; const mspace = prefs.map.space;
let wire = mspace.wire;
if (state.toggle) { if (state.toggle) {
wire = !wire; wire = !wire;
} else { } else {
@ -656,7 +658,17 @@ const api = exports({
for (let m of model.list()) { for (let m of model.list()) {
m.wireframe(wire, opt); 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}) { normals(state = {toggle:true}) {

View file

@ -1044,7 +1044,26 @@ gapp.register("moto.space", [], (root, exports) => {
return SCENE.remove(o); 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: { world: {
@ -1230,6 +1249,7 @@ gapp.register("moto.space", [], (root, exports) => {
if (moved && platformOnMove) { if (moved && platformOnMove) {
clearTimeout(platformMoveTimer); clearTimeout(platformMoveTimer);
platformMoveTimer = setTimeout(platformOnMove, 500); platformMoveTimer = setTimeout(platformOnMove, 500);
Space.scene.updateFog();
} }
updateLastAction(); updateLastAction();
}, (val) => { }, (val) => {