UNPKG

@polygonjs/polygonjs

Version:

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

62 lines (61 loc) 1.97 kB
"use strict"; import { TypedMatNode } from "../_Base"; import { BaseTextureMapController, BooleanParamOptions, NodePathOptions } from "./_BaseTextureController"; import { NodeParamsConfig, ParamConfig } from "../../utils/params/ParamsConfig"; export function MatcapMapParamConfig(Base) { return class Mixin extends Base { constructor() { super(...arguments); /** @param toggle if you want to use a matcap map */ this.useMatcapMap = ParamConfig.BOOLEAN(0, BooleanParamOptions(TextureMatcapMapController)); /** @param specify the matcap map COP node */ this.matcapMap = ParamConfig.NODE_PATH("", NodePathOptions(TextureMatcapMapController, "useMatcapMap")); } }; } function _isValidMaterial(material) { if (!material) { return false; } return true; } class TextureMatcapMapParamsConfig extends MatcapMapParamConfig(NodeParamsConfig) { } class TextureMatcapMapMatNode extends TypedMatNode { async material() { const container = await this.compute(); return container.material(); } } export class TextureMatcapMapController extends BaseTextureMapController { constructor(node) { super(node); this.node = node; } initializeNode() { this.add_hooks(this.node.p.useMatcapMap, this.node.p.matcapMap); } static async update(node) { node.controllers.matcap.update(); } async update() { const material = await this.node.material(); if (!_isValidMaterial(material)) { return; } await this.updateMaterial(material); } async updateMaterial(material) { await this._update(material, "matcap", this.node.p.useMatcapMap, this.node.p.matcapMap); } getTextures(material, record) { record.set("matcap", material.matcap); } setParamsFromMaterial(material, record) { const mapNode = record.get("matcap"); this.node.p.useMatcapMap.set(mapNode != null); if (mapNode) { this.node.p.matcapMap.setNode(mapNode, { relative: true }); } } }