UNPKG

@openhps/core

Version:

Open Hybrid Positioning System - Core component

128 lines (119 loc) 5.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.cameraWorldMatrix = exports.cameraViewMatrix = exports.cameraProjectionMatrixInverse = exports.cameraProjectionMatrix = exports.cameraPosition = exports.cameraNormalMatrix = exports.cameraNear = exports.cameraIndex = exports.cameraFar = void 0; var _UniformNode = require("../core/UniformNode.js"); var _UniformGroupNode = require("../core/UniformGroupNode.js"); var _Vector = require("../../math/Vector3.js"); var _TSLBase = require("../tsl/TSLBase.js"); var _UniformArrayNode = require("./UniformArrayNode.js"); /** * TSL object that represents the current `index` value of the camera if used ArrayCamera. * * @tsl * @type {UniformNode<uint>} */ const cameraIndex = exports.cameraIndex = /*@__PURE__*/(0, _UniformNode.uniform)(0, 'uint').setGroup((0, _UniformGroupNode.sharedUniformGroup)('cameraIndex')).toVarying('v_cameraIndex'); /** * TSL object that represents the `near` value of the camera used for the current render. * * @tsl * @type {UniformNode<float>} */ const cameraNear = exports.cameraNear = /*@__PURE__*/(0, _UniformNode.uniform)('float').label('cameraNear').setGroup(_UniformGroupNode.renderGroup).onRenderUpdate(({ camera }) => camera.near); /** * TSL object that represents the `far` value of the camera used for the current render. * * @tsl * @type {UniformNode<float>} */ const cameraFar = exports.cameraFar = /*@__PURE__*/(0, _UniformNode.uniform)('float').label('cameraFar').setGroup(_UniformGroupNode.renderGroup).onRenderUpdate(({ camera }) => camera.far); /** * TSL object that represents the projection matrix of the camera used for the current render. * * @tsl * @type {UniformNode<mat4>} */ const cameraProjectionMatrix = exports.cameraProjectionMatrix = /*@__PURE__*/(0, _TSLBase.Fn)(({ camera }) => { let cameraProjectionMatrix; if (camera.isArrayCamera && camera.cameras.length > 0) { const matrices = []; for (const subCamera of camera.cameras) { matrices.push(subCamera.projectionMatrix); } const cameraProjectionMatrices = (0, _UniformArrayNode.uniformArray)(matrices).setGroup(_UniformGroupNode.renderGroup).label('cameraProjectionMatrices'); cameraProjectionMatrix = cameraProjectionMatrices.element(cameraIndex).toVar('cameraProjectionMatrix'); } else { cameraProjectionMatrix = (0, _UniformNode.uniform)('mat4').label('cameraProjectionMatrix').setGroup(_UniformGroupNode.renderGroup).onRenderUpdate(({ camera }) => camera.projectionMatrix); } return cameraProjectionMatrix; }).once()(); /** * TSL object that represents the inverse projection matrix of the camera used for the current render. * * @tsl * @type {UniformNode<mat4>} */ const cameraProjectionMatrixInverse = exports.cameraProjectionMatrixInverse = /*@__PURE__*/(0, _UniformNode.uniform)('mat4').label('cameraProjectionMatrixInverse').setGroup(_UniformGroupNode.renderGroup).onRenderUpdate(({ camera }) => camera.projectionMatrixInverse); /** * TSL object that represents the view matrix of the camera used for the current render. * * @tsl * @type {UniformNode<mat4>} */ const cameraViewMatrix = exports.cameraViewMatrix = /*@__PURE__*/(0, _TSLBase.Fn)(({ camera }) => { let cameraViewMatrix; if (camera.isArrayCamera && camera.cameras.length > 0) { const matrices = []; for (const subCamera of camera.cameras) { matrices.push(subCamera.matrixWorldInverse); } const cameraViewMatrices = (0, _UniformArrayNode.uniformArray)(matrices).setGroup(_UniformGroupNode.renderGroup).label('cameraViewMatrices'); cameraViewMatrix = cameraViewMatrices.element(cameraIndex).toVar('cameraViewMatrix'); } else { cameraViewMatrix = (0, _UniformNode.uniform)('mat4').label('cameraViewMatrix').setGroup(_UniformGroupNode.renderGroup).onRenderUpdate(({ camera }) => camera.matrixWorldInverse); } return cameraViewMatrix; }).once()(); /** * TSL object that represents the world matrix of the camera used for the current render. * * @tsl * @type {UniformNode<mat4>} */ const cameraWorldMatrix = exports.cameraWorldMatrix = /*@__PURE__*/(0, _UniformNode.uniform)('mat4').label('cameraWorldMatrix').setGroup(_UniformGroupNode.renderGroup).onRenderUpdate(({ camera }) => camera.matrixWorld); /** * TSL object that represents the normal matrix of the camera used for the current render. * * @tsl * @type {UniformNode<mat3>} */ const cameraNormalMatrix = exports.cameraNormalMatrix = /*@__PURE__*/(0, _UniformNode.uniform)('mat3').label('cameraNormalMatrix').setGroup(_UniformGroupNode.renderGroup).onRenderUpdate(({ camera }) => camera.normalMatrix); /** * TSL object that represents the position in world space of the camera used for the current render. * * @tsl * @type {UniformNode<vec3>} */ const cameraPosition = exports.cameraPosition = /*@__PURE__*/(0, _UniformNode.uniform)(new _Vector.Vector3()).label('cameraPosition').setGroup(_UniformGroupNode.renderGroup).onRenderUpdate(({ camera }, self) => self.value.setFromMatrixPosition(camera.matrixWorld));