@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
38 lines (37 loc) • 1.13 kB
JavaScript
;
import { Plane } from "three";
import { UpdateMatNode } from "./_Base";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
class ClippingPlaneMatParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param plane normal */
this.normal = ParamConfig.VECTOR3([0, 1, 0]);
/** @param plane constant */
this.constant = ParamConfig.FLOAT(0, {
range: [-1, 1],
rangeLocked: [false, false]
});
}
}
const ParamsConfig = new ClippingPlaneMatParamsConfig();
export class ClippingPlaneMatNode extends UpdateMatNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
this._plane = new Plane();
}
static type() {
return "clippingPlane";
}
async cook(inputMaterials) {
const inputMaterial = inputMaterials[0];
this._plane.normal.copy(this.pv.normal);
this._plane.constant = this.pv.constant;
if (!inputMaterial.clippingPlanes) {
inputMaterial.clippingPlanes = [];
}
inputMaterial.clippingPlanes.push(this._plane);
this.setMaterial(inputMaterial);
}
}