in packages/miew/src/Miew.js [3666:3821]
Miew.prototype._initOnSettingsChanged = function () {
const on = (props, func) => {
props = _.isArray(props) ? props : [props];
props.forEach((prop) => {
this.settings.addEventListener(`change:${prop}`, func);
});
};
on('modes.VD.frame', () => {
const volume = this._getVolumeVisual();
if (volume === null) return;
volume.showFrame(settings.now.modes.VD.frame);
this._needRender = true;
});
on('modes.VD.isoMode', () => {
const volume = this._getVolumeVisual();
if (volume === null) return;
volume.getMesh().material.updateDefines();
this._needRender = true;
});
on('bg.color', () => {
this._onBgColorChanged();
});
on('ao', () => {
if (settings.now.ao && !isAOSupported(this._gfx.renderer.getContext())) {
this.logger.warn('Your device or browser does not support ao');
settings.set('ao', false);
} else {
const values = { normalsToGBuffer: settings.now.ao };
this._setUberMaterialValues(values);
}
});
on('zSprites', () => {
if (settings.now.zSprites && !arezSpritesSupported(this._gfx.renderer.getContext())) {
this.logger.warn('Your device or browser does not support zSprites');
settings.set('zSprites', false);
}
this.rebuildAll();
});
on('fogColor', () => {
this._onFogColorChanged();
});
on('fogColorEnable', () => {
this._onFogColorChanged();
});
on('bg.transparent', (evt) => {
const gfx = this._gfx;
if (gfx) {
gfx.renderer.setClearColor(settings.now.bg.color, Number(!settings.now.bg.transparent));
}
// update materials
this._updateMaterials({ fogTransparent: evt.value });
this.rebuildAll();
});
on('draft.clipPlane', (evt) => {
// update materials
this._updateMaterials({ clipPlane: evt.value });
this.rebuildAll();
});
on('shadow.on', (evt) => {
// update materials
const values = { shadowmap: evt.value, shadowmapType: settings.now.shadow.type };
const gfx = this._gfx;
if (gfx) {
gfx.renderer.shadowMap.enabled = Boolean(values.shadowmap);
}
this._updateMaterials(values, true);
if (values.shadowmap) {
this._updateShadowCamera();
this._updateShadowmapMeshes(meshutils.createShadowmapMaterial);
} else {
this._updateShadowmapMeshes(meshutils.removeShadowmapMaterial);
}
this._needRender = true;
});
on('shadow.type', (evt) => {
// update materials if shadowmap is enable
if (settings.now.shadow.on) {
this._updateMaterials({ shadowmapType: evt.value }, true);
this._needRender = true;
}
});
on('shadow.radius', (evt) => {
for (let i = 0; i < this._gfx.scene.children.length; i++) {
if (this._gfx.scene.children[i].shadow !== undefined) {
const light = this._gfx.scene.children[i];
light.shadow.radius = evt.value;
this._needRender = true;
}
}
});
on('fps', () => {
this._fps.show(settings.now.fps);
});
on(['fog', 'fogNearFactor', 'fogFarFactor'], () => {
this._updateFog();
this._needRender = true;
});
on('fogAlpha', () => {
const { fogAlpha } = settings.now;
if (fogAlpha < 0 || fogAlpha > 1) {
this.logger.warn('fogAlpha must belong range [0,1]');
}
this._fogAlphaChanged();
this._needRender = true;
});
on('autoResolution', (evt) => {
if (evt.value && !this._gfxScore) {
this.logger.warn('Benchmarks are missed, autoresolution will not work! '
+ 'Autoresolution should be set during miew startup.');
}
});
on('stereo', () => {
this._embedWebXR(settings.now.stereo === 'WEBVR');
this._needRender = true;
});
on(['transparency', 'palette'], () => {
this.rebuildAll();
});
on('resolution', () => {
// update complex visuals
this.rebuildAll();
// update volume visual
const volume = this._getVolumeVisual();
if (volume) {
volume.getMesh().material.updateDefines();
this._needRender = true;
}
});
on(['axes', 'fxaa', 'ao',
'outline.on', 'outline.color', 'outline.threshold', 'outline.thickness'], () => {
this._needRender = true;
});
};