UNPKG

@openhps/core

Version:

Open Hybrid Positioning System - Core component

73 lines (69 loc) 2.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.userData = exports.default = void 0; var _ReferenceNode = _interopRequireDefault(require("./ReferenceNode.js")); var _TSLBase = require("../tsl/TSLBase.js"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * A special type of reference node that allows to link values in * `userData` fields to node objects. * ```js * sprite.userData.rotation = 1; // stores individual rotation per sprite * * const material = new THREE.SpriteNodeMaterial(); * material.rotationNode = userData( 'rotation', 'float' ); * ``` * Since `UserDataNode` is extended from {@link ReferenceNode}, the node value * will automatically be updated when the `rotation` user data field changes. * * @augments ReferenceNode */ class UserDataNode extends _ReferenceNode.default { static get type() { return 'UserDataNode'; } /** * Constructs a new user data node. * * @param {string} property - The property name that should be referenced by the node. * @param {string} inputType - The node data type of the reference. * @param {?Object} [userData=null] - A reference to the `userData` object. If not provided, the `userData` property of the 3D object that uses the node material is evaluated. */ constructor(property, inputType, userData = null) { super(property, inputType, userData); /** * A reference to the `userData` object. If not provided, the `userData` * property of the 3D object that uses the node material is evaluated. * * @type {?Object} * @default null */ this.userData = userData; } /** * Overwritten to make sure {@link ReferenceNode#reference} points to the correct * `userData` field. * * @param {(NodeFrame|NodeBuilder)} state - The current state to evaluate. * @return {Object} A reference to the `userData` field. */ updateReference(state) { this.reference = this.userData !== null ? this.userData : state.object.userData; return this.reference; } } var _default = exports.default = UserDataNode; /** * TSL function for creating a user data node. * * @tsl * @function * @param {string} name - The property name that should be referenced by the node. * @param {string} inputType - The node data type of the reference. * @param {?Object} userData - A reference to the `userData` object. If not provided, the `userData` property of the 3D object that uses the node material is evaluated. * @returns {UserDataNode} */ const userData = (name, inputType, userData) => (0, _TSLBase.nodeObject)(new UserDataNode(name, inputType, userData)); exports.userData = userData;