UNPKG

@polygonjs/polygonjs

Version:

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

152 lines (151 loc) 5.67 kB
"use strict"; import { NodeParamsConfig } from "../utils/params/ParamsConfig"; import { UniformsTransparencyParamConfig, UniformsTransparencyController } from "./utils/UniformsTransparencyController"; import { AdvancedCommonController, AdvancedCommonParamConfig } from "./utils/AdvancedCommonController"; import { MapParamConfig, TextureMapController } from "./utils/TextureMapController"; import { AlphaMapParamConfig, TextureAlphaMapController } from "./utils/TextureAlphaMapController"; import { TextureBumpMapController, BumpMapParamConfig } from "./utils/TextureBumpMapController"; import { TextureEmissiveMapController, EmissiveMapParamConfig } from "./utils/TextureEmissiveMapController"; import { TextureEnvMapController, EnvMapParamConfig } from "./utils/TextureEnvMapController"; import { TextureAOMapController, AOMapParamConfig } from "./utils/TextureAOMapController"; import { TextureNormalMapController, NormalMapParamConfig } from "./utils/TextureNormalMapController"; import { TextureMetalnessRoughnessMapController, MetalnessRoughnessMapParamConfig } from "./utils/TextureMetalnessRoughnessMapController"; import { TextureLightMapController, LightMapParamConfig } from "./utils/TextureLightMapController"; import { MeshPhysicalController, MeshPhysicalParamConfig } from "./utils/MeshPhysicalController"; import { TextureDisplacementMapController, DisplacementMapParamConfig } from "./utils/TextureDisplacementMapController"; import { BaseBuilderParamConfig, TypedBuilderMatNode } from "./_BaseBuilder"; import { AssemblerName } from "../../poly/registers/assemblers/_BaseRegister"; import { Poly } from "../../Poly"; import { FogParamConfig, UniformFogController } from "./utils/UniformsFogController"; import { WireframeShaderMaterialController, WireframeShaderMaterialParamsConfig } from "./utils/WireframeShaderMaterialController"; import { DefaultFolderParamConfig } from "./utils/DefaultFolder"; import { TexturesFolderParamConfig } from "./utils/TexturesFolder"; import { AdvancedFolderParamConfig } from "./utils/AdvancedFolder"; import { PCSSController, PCSSParamConfig } from "./utils/PCSSController"; import { CustomMaterialMeshParamConfig, materialMeshAssemblerCustomMaterialRequested } from "./utils/customMaterials/CustomMaterialMesh"; import { MatType } from "../../poly/registers/nodes/types/Mat"; function AdvancedMeshPhysicalParamConfig(Base) { return class Mixin extends PCSSParamConfig( FogParamConfig(WireframeShaderMaterialParamsConfig(AdvancedCommonParamConfig(BaseBuilderParamConfig(Base)))) ) { }; } class MeshPhysicalBuilderMatParamsConfig extends CustomMaterialMeshParamConfig( AdvancedMeshPhysicalParamConfig( /* advanced */ AdvancedFolderParamConfig( MeshPhysicalParamConfig( MetalnessRoughnessMapParamConfig( NormalMapParamConfig( LightMapParamConfig( EnvMapParamConfig( EmissiveMapParamConfig( DisplacementMapParamConfig( BumpMapParamConfig( AOMapParamConfig( AlphaMapParamConfig( MapParamConfig( /* textures */ TexturesFolderParamConfig( UniformsTransparencyParamConfig( DefaultFolderParamConfig(NodeParamsConfig) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) { } const ParamsConfig = new MeshPhysicalBuilderMatParamsConfig(); export class MeshPhysicalBuilderMatNode extends TypedBuilderMatNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; this.controllers = { advancedCommon: new AdvancedCommonController(this), alphaMap: new TextureAlphaMapController(this), aoMap: new TextureAOMapController(this), bumpMap: new TextureBumpMapController(this), displacementMap: new TextureDisplacementMapController(this), emissiveMap: new TextureEmissiveMapController(this), envMap: new TextureEnvMapController(this), uniformFog: new UniformFogController(this), lightMap: new TextureLightMapController(this), map: new TextureMapController(this), metalnessRoughnessMap: new TextureMetalnessRoughnessMapController(this), normalMap: new TextureNormalMapController(this), physical: new MeshPhysicalController(this), PCSS: new PCSSController(this), uniformTransparency: new UniformsTransparencyController(this), wireframeShader: new WireframeShaderMaterialController(this) }; this.controllersList = Object.values(this.controllers); } static type() { return MatType.MESH_PHYSICAL_BUILDER; } usedAssembler() { return AssemblerName.GL_MESH_PHYSICAL; } _createAssemblerController() { return Poly.assemblersRegister.assembler(this, this.usedAssembler()); } customMaterialRequested(customName) { return materialMeshAssemblerCustomMaterialRequested(this, customName); } createMaterial() { const material = super.createMaterial(); material.isMeshStandardMaterial = true; material.isMeshPhysicalMaterial = true; return material; } async cook() { this._material = this._material || this.createMaterial(); await Promise.all(this.controllersPromises(this._material)); this.compileIfRequired(this._material); this.setMaterial(this._material); } }