@openhps/core
Version:
Open Hybrid Positioning System - Core component
127 lines (113 loc) • 3.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _NodeMaterial = _interopRequireDefault(require("./NodeMaterial.js"));
var _PropertyNode = require("../../nodes/core/PropertyNode.js");
var _MaterialNode = require("../../nodes/accessors/MaterialNode.js");
var _TSLBase = require("../../nodes/tsl/TSLBase.js");
var _BasicEnvironmentNode = _interopRequireDefault(require("../../nodes/lighting/BasicEnvironmentNode.js"));
var _PhongLightingModel = _interopRequireDefault(require("../../nodes/functions/PhongLightingModel.js"));
var _MeshPhongMaterial = require("../MeshPhongMaterial.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const _defaultValues = /*@__PURE__*/new _MeshPhongMaterial.MeshPhongMaterial();
/**
* Node material version of {@link MeshPhongMaterial}.
*
* @augments NodeMaterial
*/
class MeshPhongNodeMaterial extends _NodeMaterial.default {
static get type() {
return 'MeshPhongNodeMaterial';
}
/**
* Constructs a new mesh lambert 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.isMeshPhongNodeMaterial = true;
/**
* Set to `true` because phong materials react on lights.
*
* @type {boolean}
* @default true
*/
this.lights = true;
/**
* The shininess of phong materials is by default inferred from the `shininess`
* property. This node property allows to overwrite the default
* and define the shininess with a node instead.
*
* If you don't want to overwrite the shininess but modify the existing
* value instead, use {@link materialShininess}.
*
* @type {?Node<float>}
* @default null
*/
this.shininessNode = null;
/**
* The specular color of phong materials is by default inferred from the
* `specular` property. This node property allows to overwrite the default
* and define the specular color with a node instead.
*
* If you don't want to overwrite the specular color but modify the existing
* value instead, use {@link materialSpecular}.
*
* @type {?Node<vec3>}
* @default null
*/
this.specularNode = null;
this.setDefaultValues(_defaultValues);
this.setValues(parameters);
}
/**
* Overwritten since this type of material uses {@link BasicEnvironmentNode}
* to implement the default environment mapping.
*
* @param {NodeBuilder} builder - The current node builder.
* @return {?BasicEnvironmentNode<vec3>} The environment node.
*/
setupEnvironment(builder) {
const envNode = super.setupEnvironment(builder);
return envNode ? new _BasicEnvironmentNode.default(envNode) : null;
}
/**
* Setups the lighting model.
*
* @return {PhongLightingModel} The lighting model.
*/
setupLightingModel( /*builder*/
) {
return new _PhongLightingModel.default();
}
/**
* Setups the phong specific node variables.
*
* @param {NodeBuilder} builder - The current node builder.
*/
setupVariants( /*builder*/
) {
// SHININESS
const shininessNode = (this.shininessNode ? (0, _TSLBase.float)(this.shininessNode) : _MaterialNode.materialShininess).max(1e-4); // to prevent pow( 0.0, 0.0 )
_PropertyNode.shininess.assign(shininessNode);
// SPECULAR COLOR
const specularNode = this.specularNode || _MaterialNode.materialSpecular;
_PropertyNode.specularColor.assign(specularNode);
}
copy(source) {
this.shininessNode = source.shininessNode;
this.specularNode = source.specularNode;
return super.copy(source);
}
}
var _default = exports.default = MeshPhongNodeMaterial;