UNPKG

@openhps/core

Version:

Open Hybrid Positioning System - Core component

165 lines (146 loc) 5.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _NodeMaterial = _interopRequireDefault(require("./NodeMaterial.js")); var _PropertyNode = require("../../nodes/core/PropertyNode.js"); var _MathNode = require("../../nodes/math/MathNode.js"); var _MaterialNode = require("../../nodes/accessors/MaterialNode.js"); var _getRoughness = _interopRequireDefault(require("../../nodes/functions/material/getRoughness.js")); var _PhysicalLightingModel = _interopRequireDefault(require("../../nodes/functions/PhysicalLightingModel.js")); var _EnvironmentNode = _interopRequireDefault(require("../../nodes/lighting/EnvironmentNode.js")); var _TSLBase = require("../../nodes/tsl/TSLBase.js"); var _MeshStandardMaterial = require("../MeshStandardMaterial.js"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const _defaultValues = /*@__PURE__*/new _MeshStandardMaterial.MeshStandardMaterial(); /** * Node material version of {@link MeshStandardMaterial}. * * @augments NodeMaterial */ class MeshStandardNodeMaterial extends _NodeMaterial.default { static get type() { return 'MeshStandardNodeMaterial'; } /** * Constructs a new mesh standard node material. * * @param {Object} [parameters] - The configuration parameter. */ constructor(parameters) { super(); /** * This flag can be used for type testing. * * @type {boolean} * @readonly * @default true */ this.isMeshStandardNodeMaterial = true; /** * Set to `true` because standard materials react on lights. * * @type {boolean} * @default true */ this.lights = true; /** * The emissive color of standard materials is by default inferred from the `emissive`, * `emissiveIntensity` and `emissiveMap` properties. This node property allows to * overwrite the default and define the emissive color with a node instead. * * If you don't want to overwrite the emissive color but modify the existing * value instead, use {@link materialEmissive}. * * @type {?Node<vec3>} * @default null */ this.emissiveNode = null; /** * The metalness of standard materials is by default inferred from the `metalness`, * and `metalnessMap` properties. This node property allows to * overwrite the default and define the metalness with a node instead. * * If you don't want to overwrite the metalness but modify the existing * value instead, use {@link materialMetalness}. * * @type {?Node<float>} * @default null */ this.metalnessNode = null; /** * The roughness of standard materials is by default inferred from the `roughness`, * and `roughnessMap` properties. This node property allows to * overwrite the default and define the roughness with a node instead. * * If you don't want to overwrite the roughness but modify the existing * value instead, use {@link materialRoughness}. * * @type {?Node<float>} * @default null */ this.roughnessNode = null; this.setDefaultValues(_defaultValues); this.setValues(parameters); } /** * Overwritten since this type of material uses {@link EnvironmentNode} * to implement the PBR (PMREM based) environment mapping. Besides, the * method honors `Scene.environment`. * * @param {NodeBuilder} builder - The current node builder. * @return {?EnvironmentNode<vec3>} The environment node. */ setupEnvironment(builder) { let envNode = super.setupEnvironment(builder); if (envNode === null && builder.environmentNode) { envNode = builder.environmentNode; } return envNode ? new _EnvironmentNode.default(envNode) : null; } /** * Setups the lighting model. * * @return {PhysicalLightingModel} The lighting model. */ setupLightingModel( /*builder*/ ) { return new _PhysicalLightingModel.default(); } /** * Setups the specular related node variables. */ setupSpecular() { const specularColorNode = (0, _MathNode.mix)((0, _TSLBase.vec3)(0.04), _PropertyNode.diffuseColor.rgb, _PropertyNode.metalness); _PropertyNode.specularColor.assign(specularColorNode); _PropertyNode.specularF90.assign(1.0); } /** * Setups the standard specific node variables. * * @param {NodeBuilder} builder - The current node builder. */ setupVariants() { // METALNESS const metalnessNode = this.metalnessNode ? (0, _TSLBase.float)(this.metalnessNode) : _MaterialNode.materialMetalness; _PropertyNode.metalness.assign(metalnessNode); // ROUGHNESS let roughnessNode = this.roughnessNode ? (0, _TSLBase.float)(this.roughnessNode) : _MaterialNode.materialRoughness; roughnessNode = (0, _getRoughness.default)({ roughness: roughnessNode }); _PropertyNode.roughness.assign(roughnessNode); // SPECULAR COLOR this.setupSpecular(); // DIFFUSE COLOR _PropertyNode.diffuseColor.assign((0, _TSLBase.vec4)(_PropertyNode.diffuseColor.rgb.mul(metalnessNode.oneMinus()), _PropertyNode.diffuseColor.a)); } copy(source) { this.emissiveNode = source.emissiveNode; this.metalnessNode = source.metalnessNode; this.roughnessNode = source.roughnessNode; return super.copy(source); } } var _default = exports.default = MeshStandardNodeMaterial;