UNPKG

@polygonjs/polygonjs

Version:

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

65 lines (64 loc) 2.52 kB
"use strict"; import { TypeAssert } from "../../../../poly/Assert"; import { NodeParamsConfig } from "../../../utils/params/ParamsConfig"; import { CustomMaterialName } from "../../../../../core/geometry/Material"; import { ParamConfig } from "../../../utils/params/ParamsConfig"; import { BaseBuilderParamConfig } from "../../_BaseBuilder"; import { isBooleanTrue } from "../../../../../core/Type"; import { TypedMatNode } from "../../_Base"; import { CUSTOM_MAT_PARAM_OPTIONS } from "./_CustomMaterialBase"; export function CustomMaterialMeshParamConfig(Base) { return class Mixin extends Base { constructor() { super(...arguments); /** @param toggle on to choose which customMaterials will be generated */ this.overrideCustomMaterials = ParamConfig.BOOLEAN(0, { ...CUSTOM_MAT_PARAM_OPTIONS, separatorBefore: true, separatorAfter: true }); /** @param distance material used for shadows from points lights */ this.createCustomMatDistance = ParamConfig.BOOLEAN(1, { visibleIf: { overrideCustomMaterials: 1 }, ...CUSTOM_MAT_PARAM_OPTIONS }); /** @param depth material used for shadows from spot lights and directional lights */ this.createCustomMatDepth = ParamConfig.BOOLEAN(1, { visibleIf: { overrideCustomMaterials: 1 }, ...CUSTOM_MAT_PARAM_OPTIONS }); /** @param depth DOF */ this.createCustomMatDepthDOF = ParamConfig.BOOLEAN(1, { visibleIf: { overrideCustomMaterials: 1 }, ...CUSTOM_MAT_PARAM_OPTIONS, separatorAfter: true }); } }; } class CustomMaterialMeshParamsConfig extends CustomMaterialMeshParamConfig(BaseBuilderParamConfig(NodeParamsConfig)) { } class CustomMaterialMatNode extends TypedMatNode { } export function materialMeshAssemblerCustomMaterialRequested(node, customName) { const param = node.p.overrideCustomMaterials; if (!param) { console.warn(`param overrideCustomMaterials not found on ${node.path()}, creating all customMaterials`); return true; } if (!isBooleanTrue(node.pv.overrideCustomMaterials)) { return true; } switch (customName) { case CustomMaterialName.DISTANCE: { return isBooleanTrue(node.pv.createCustomMatDistance); } case CustomMaterialName.DEPTH: { return isBooleanTrue(node.pv.createCustomMatDepth); } case CustomMaterialName.DEPTH_DOF: { return isBooleanTrue(node.pv.createCustomMatDepthDOF); } } TypeAssert.unreachable(customName); }