@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
66 lines (65 loc) • 2.11 kB
JavaScript
;
import { TypedSopNode } from "./_Base";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { NodeContext } from "../../poly/NodeContext";
import { SopType } from "../../poly/registers/nodes/types/Sop";
import { GroundProjectedSkybox } from "../../../core/geometry/builders/groundProjectedSkybox/GroundProjectedSkybox";
class GroundProjectedSkyboxSopParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param envMap */
this.envMap = ParamConfig.NODE_PATH("", {
nodeSelection: {
context: NodeContext.COP
},
dependentOnFoundNode: false
});
/** @param scale */
this.scale = ParamConfig.FLOAT(50, {
range: [0, 100],
rangeLocked: [true, false]
});
/** @param radius */
this.radius = ParamConfig.FLOAT(200, {
range: [0, 1e3],
rangeLocked: [true, false]
});
/** @param height */
this.height = ParamConfig.FLOAT(20, {
range: [0, 100],
rangeLocked: [true, false]
});
}
}
const ParamsConfig = new GroundProjectedSkyboxSopParamsConfig();
export class GroundProjectedSkyboxSopNode extends TypedSopNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return SopType.GROUND_PROJECTED_SKYBOX;
}
initializeNode() {
this.io.inputs.setCount(0);
}
async cook(inputCoreGroups) {
var _a, _b;
const textureNode = this.pv.envMap.nodeWithContext(NodeContext.COP, (_a = this.states) == null ? void 0 : _a.error);
if (!textureNode) {
(_b = this.states) == null ? void 0 : _b.error.set(`no texture node found`);
return;
}
const container = await textureNode.compute();
const texture = container.texture();
const skybox = new GroundProjectedSkybox();
const scale = this.pv.scale;
skybox.scale.set(scale, scale, scale);
skybox.updateMatrix();
skybox.matrixAutoUpdate = false;
skybox.setTexture(texture);
skybox.radius = this.pv.radius;
skybox.height = this.pv.height;
this.setObject(skybox);
}
}