UNPKG

@polygonjs/polygonjs

Version:

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

51 lines (50 loc) 1.61 kB
"use strict"; import { BaseController } from "./_BaseController"; import { TypedMatNode } from "../_Base"; import { NodeParamsConfig, ParamConfig } from "../../utils/params/ParamsConfig"; import { isBooleanTrue } from "../../../../core/BooleanValue"; export function WireframeShaderMaterialParamsConfig(Base) { return class Mixin extends Base { constructor() { super(...arguments); /** @param toggle on to set material to wireframe */ this.wireframe = ParamConfig.BOOLEAN(0); /** @param wireframe line width */ this.wireframeLinewidth = ParamConfig.FLOAT(1, { range: [0, 5], rangeLocked: [true, false], visibleIf: { wireframe: 1 } }); } }; } class WireframeShaderParamsConfig extends WireframeShaderMaterialParamsConfig(NodeParamsConfig) { } class WireframedShaderMatNode extends TypedMatNode { async material() { const container = await this.compute(); return container.material(); } } export class WireframeShaderMaterialController extends BaseController { constructor(node) { super(node); this.node = node; } static async update(node) { const material = await node.material(); if (!material) { return; } node.controllers.wireframeShader.updateMaterial(material); } updateMaterial(material) { const pv = this.node.pv; const shaderMaterial = material; if (shaderMaterial.wireframe != null) { shaderMaterial.wireframe = isBooleanTrue(pv.wireframe); shaderMaterial.wireframeLinewidth = pv.wireframeLinewidth; shaderMaterial.needsUpdate = true; } } }