@vci/quick-three
Version:
quick three
63 lines (59 loc) • 1.82 kB
JavaScript
import { Fog, FogExp2 } from "three";
import { createTweenModifier } from "./../../helper/TweenHelper";
function createFogHelper(qt, fog, key) {
// 改变雾密度
fog.modifyDensity = createTweenModifier(
qt.tw,
{
instance: fog,
keyModifyProperty: "density",
twKey: key
}
);
// 重置雾密度
fog.resetDensity = async twOption => await fog.modifyDensity(fog._density, twOption);
}
function createFog(qt, color = "#fff", near = 100, far = 500) {
const fog = new Fog(color, near, far);
// 创建辅助函数
createFogHelper(qt, fog, "fog.modifyDensity");
// 调试
if (qt.debug && qt.gui) {
qt.gui.guis.fog = qt.gui.gui().addFolder("雾");
const params = { color };
qt.gui.guis.fog.add(fog, "near").step(.5e3).max(1e4).min(0);
qt.gui.guis.fog.add(fog, "far").step(.5e3).max(1e4).min(0);
qt.gui.guis.fog
.addColor(params, "color")
.onChange(e => {
fog.color.setStyle(e);
qt.scene.background.isColor && qt.scene.background.setStyle(e);
});
}
qt.scene.fog = fog;
return fog;
}
function createFogExp2(qt, color = "#fff", density = 0.005) {
const fog = new FogExp2(color, density);
// 创建辅助函数
createFogHelper(qt, fog, "fog.modifyDensity");
// 调试
if (qt.debug && qt.gui) {
qt.gui.guis.fog = qt.gui.gui().addFolder("雾Exp2");
const params = { color };
qt.gui.guis.fog
.add(fog, "density")
.step(0.001)
.max(0.1)
.min(0);
qt.gui.guis.fog
.addColor(params, "color")
.onChange(e => {
fog.color.setStyle(e);
qt.scene.background.isColor && qt.scene.background.setStyle(e);
});
}
qt.scene.fog = fog;
return fog;
}
export { createFog, createFogExp2 };