UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

69 lines (68 loc) 2.28 kB
"use strict"; import { TypedMatNode } from "../_Base"; import { BaseTextureMapController, BooleanParamOptions, NodePathOptions } from "./_BaseTextureController"; import { NodeParamsConfig, ParamConfig } from "../../utils/params/ParamsConfig"; export function AOMapParamConfig(Base) { return class Mixin extends Base { constructor() { super(...arguments); /** @param toggle if you want to use an ambient occlusion map */ this.useAOMap = ParamConfig.BOOLEAN(0, { separatorBefore: true, ...BooleanParamOptions(TextureAOMapController) }); /** @param specify the AO map COP node */ this.aoMap = ParamConfig.NODE_PATH("", NodePathOptions(TextureAOMapController, "useAOMap")); /** @param ambient occlusion intensity */ this.aoMapIntensity = ParamConfig.FLOAT(1, { range: [0, 1], rangeLocked: [false, false], visibleIf: { useAOMap: 1 } }); } }; } function _isValidMaterial(material) { if (!material) { return false; } return material.aoMapIntensity != null; } class TextureAOMapParamsConfig extends AOMapParamConfig(NodeParamsConfig) { } class TextureAOMapMatNode extends TypedMatNode { async material() { const container = await this.compute(); return container.material(); } } export class TextureAOMapController extends BaseTextureMapController { constructor(node) { super(node); this.node = node; } initializeNode() { this.add_hooks(this.node.p.useAOMap, this.node.p.aoMap); } static async update(node) { node.controllers.aoMap.update(); } async update() { const material = await this.node.material(); if (!_isValidMaterial(material)) { return; } await this.updateMaterial(material); } async updateMaterial(material) { await this._update(material, "aoMap", this.node.p.useAOMap, this.node.p.aoMap); material.aoMapIntensity = this.node.pv.aoMapIntensity; } getTextures(material, record) { record.set("aoMap", material.aoMap); } setParamsFromMaterial(material, record) { const mapNode = record.get("aoMap"); this.node.p.useAOMap.set(mapNode != null); if (mapNode) { this.node.p.aoMap.setNode(mapNode, { relative: true }); } this.node.p.aoMapIntensity.set(material.aoMapIntensity); } }