@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
47 lines (46 loc) • 1.32 kB
JavaScript
;
import { BaseController } from "./_BaseController";
import { TypedMatNode } from "../_Base";
import { NodeParamsConfig, ParamConfig } from "../../utils/params/ParamsConfig";
import { isBooleanTrue } from "../../../../core/BooleanValue";
export function FogParamConfig(Base) {
return class Mixin extends Base {
constructor() {
super(...arguments);
/** @param toggle on if you have a fog in the scene and the material should be affected by it */
this.useFog = ParamConfig.BOOLEAN(0);
}
};
}
export function isValidMaterial(material) {
if (!material) {
return false;
}
return material.fog != null;
}
class FogParamsConfig extends FogParamConfig(NodeParamsConfig) {
}
class FogMatNode extends TypedMatNode {
async material() {
const container = await this.compute();
return container.material();
}
}
export class FogController extends BaseController {
constructor(node) {
super(node);
this.node = node;
}
static async update(node) {
const container = await node.compute();
const material = container.material();
if (!isValidMaterial(material)) {
return;
}
node.controllers.fog.updateMaterial(material);
}
updateMaterial(material) {
const pv = this.node.pv;
material.fog = isBooleanTrue(pv.useFog);
}
}