@openhps/core
Version:
Open Hybrid Positioning System - Core component
121 lines (112 loc) • 4.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.backgroundRotation = exports.backgroundIntensity = exports.backgroundBlurriness = void 0;
var _constants = require("../../constants.js");
var _Euler = require("../../math/Euler.js");
var _Matrix = require("../../math/Matrix4.js");
var _Node = _interopRequireDefault(require("../core/Node.js"));
var _UniformGroupNode = require("../core/UniformGroupNode.js");
var _TSLBase = require("../tsl/TSLBase.js");
var _ReferenceNode = require("./ReferenceNode.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const _e1 = /*@__PURE__*/new _Euler.Euler();
const _m1 = /*@__PURE__*/new _Matrix.Matrix4();
/**
* This module allows access to a collection of scene properties. The following predefined TSL objects
* are available for easier use:
*
* - `backgroundBlurriness`: A node that represents the scene's background blurriness.
* - `backgroundIntensity`: A node that represents the scene's background intensity.
* - `backgroundRotation`: A node that represents the scene's background rotation.
*
* @augments Node
*/
class SceneNode extends _Node.default {
static get type() {
return 'SceneNode';
}
/**
* Constructs a new scene node.
*
* @param {('backgroundBlurriness'|'backgroundIntensity'|'backgroundRotation')} scope - The scope defines the type of scene property that is accessed.
* @param {?Scene} [scene=null] - A reference to the scene.
*/
constructor(scope = SceneNode.BACKGROUND_BLURRINESS, scene = null) {
super();
/**
* The scope defines the type of scene property that is accessed.
*
* @type {('backgroundBlurriness'|'backgroundIntensity'|'backgroundRotation')}
*/
this.scope = scope;
/**
* A reference to the scene that is going to be accessed.
*
* @type {?Scene}
* @default null
*/
this.scene = scene;
}
/**
* Depending on the scope, the method returns a different type of node that represents
* the respective scene property.
*
* @param {NodeBuilder} builder - The current node builder.
* @return {Node} The output node.
*/
setup(builder) {
const scope = this.scope;
const scene = this.scene !== null ? this.scene : builder.scene;
let output;
if (scope === SceneNode.BACKGROUND_BLURRINESS) {
output = (0, _ReferenceNode.reference)('backgroundBlurriness', 'float', scene);
} else if (scope === SceneNode.BACKGROUND_INTENSITY) {
output = (0, _ReferenceNode.reference)('backgroundIntensity', 'float', scene);
} else if (scope === SceneNode.BACKGROUND_ROTATION) {
output = (0, _TSLBase.uniform)('mat4').label('backgroundRotation').setGroup(_UniformGroupNode.renderGroup).onRenderUpdate(() => {
const background = scene.background;
if (background !== null && background.isTexture && background.mapping !== _constants.UVMapping) {
_e1.copy(scene.backgroundRotation);
// accommodate left-handed frame
_e1.x *= -1;
_e1.y *= -1;
_e1.z *= -1;
_m1.makeRotationFromEuler(_e1);
} else {
_m1.identity();
}
return _m1;
});
} else {
console.error('THREE.SceneNode: Unknown scope:', scope);
}
return output;
}
}
SceneNode.BACKGROUND_BLURRINESS = 'backgroundBlurriness';
SceneNode.BACKGROUND_INTENSITY = 'backgroundIntensity';
SceneNode.BACKGROUND_ROTATION = 'backgroundRotation';
var _default = exports.default = SceneNode;
/**
* TSL object that represents the scene's background blurriness.
*
* @tsl
* @type {SceneNode}
*/
const backgroundBlurriness = exports.backgroundBlurriness = /*@__PURE__*/(0, _TSLBase.nodeImmutable)(SceneNode, SceneNode.BACKGROUND_BLURRINESS);
/**
* TSL object that represents the scene's background intensity.
*
* @tsl
* @type {SceneNode}
*/
const backgroundIntensity = exports.backgroundIntensity = /*@__PURE__*/(0, _TSLBase.nodeImmutable)(SceneNode, SceneNode.BACKGROUND_INTENSITY);
/**
* TSL object that represents the scene's background rotation.
*
* @tsl
* @type {SceneNode}
*/
const backgroundRotation = exports.backgroundRotation = /*@__PURE__*/(0, _TSLBase.nodeImmutable)(SceneNode, SceneNode.BACKGROUND_ROTATION);