UNPKG

@polygonjs/polygonjs

Version:

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

65 lines (64 loc) 2.01 kB
"use strict"; import { TypedMatNode } from "../_Base"; import { BaseTextureMapController, BooleanParamOptions, NodePathOptions } from "./_BaseTextureController"; import { NodeParamsConfig, ParamConfig } from "../../utils/params/ParamsConfig"; export function AlphaMapParamConfig(Base) { return class Mixin extends Base { constructor() { super(...arguments); /** @param toggle if you want to use an alpha map */ this.useAlphaMap = ParamConfig.BOOLEAN(0, { separatorBefore: true, ...BooleanParamOptions(TextureAlphaMapController) }); /** @param specify the alpha map COP node */ this.alphaMap = ParamConfig.NODE_PATH("", NodePathOptions(TextureAlphaMapController, "useAlphaMap")); } }; } function _isValidMaterial(material) { if (!material) { return false; } return true; } class TextureAlphaMapParamsConfig extends AlphaMapParamConfig(NodeParamsConfig) { } class TextureAlphaMapMatNode extends TypedMatNode { async material() { const container = await this.compute(); return container.material(); } } export class TextureAlphaMapController extends BaseTextureMapController { constructor(node) { super(node); this.node = node; } initializeNode() { this.add_hooks(this.node.p.useAlphaMap, this.node.p.alphaMap); } static async update(node) { node.controllers.alphaMap.update(); } async update() { const material = await this.node.material(); if (!_isValidMaterial(material)) { return; } await this.updateMaterial(material); } async updateMaterial(material) { await this._update(material, "alphaMap", this.node.p.useAlphaMap, this.node.p.alphaMap); } getTextures(material, record) { record.set("alphaMap", material.alphaMap); } setParamsFromMaterial(material, record) { const mapNode = record.get("aoMap"); this.node.p.useAlphaMap.set(mapNode != null); if (mapNode) { this.node.p.alphaMap.setNode(mapNode, { relative: true }); } } }