UNPKG

@openhps/core

Version:

Open Hybrid Positioning System - Core component

56 lines (55 loc) 1.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.billboarding = void 0; var _ModelNode = require("../accessors/ModelNode.js"); var _Camera = require("../accessors/Camera.js"); var _Position = require("../accessors/Position.js"); var _TSLBase = require("../tsl/TSLBase.js"); /** * This can be used to achieve a billboarding behavior for flat meshes. That means they are * oriented always towards the camera. * * ```js * material.vertexNode = billboarding(); * ``` * * @tsl * @function * @param {Object} config - The configuration object. * @param {?Node<vec3>} [config.position=null] - Can be used to define the vertex positions in world space. * @param {boolean} [config.horizontal=true] - Whether to follow the camera rotation horizontally or not. * @param {boolean} [config.vertical=false] - Whether to follow the camera rotation vertically or not. * @return {Node<vec3>} The updated vertex position in clip space. */ const billboarding = exports.billboarding = /*@__PURE__*/(0, _TSLBase.Fn)(({ position = null, horizontal = true, vertical = false }) => { let worldMatrix; if (position !== null) { worldMatrix = _ModelNode.modelWorldMatrix.toVar(); worldMatrix[3][0] = position.x; worldMatrix[3][1] = position.y; worldMatrix[3][2] = position.z; } else { worldMatrix = _ModelNode.modelWorldMatrix; } const modelViewMatrix = _Camera.cameraViewMatrix.mul(worldMatrix); if ((0, _TSLBase.defined)(horizontal)) { modelViewMatrix[0][0] = _ModelNode.modelWorldMatrix[0].length(); modelViewMatrix[0][1] = 0; modelViewMatrix[0][2] = 0; } if ((0, _TSLBase.defined)(vertical)) { modelViewMatrix[1][0] = 0; modelViewMatrix[1][1] = _ModelNode.modelWorldMatrix[1].length(); modelViewMatrix[1][2] = 0; } modelViewMatrix[2][0] = 0; modelViewMatrix[2][1] = 0; modelViewMatrix[2][2] = 1; return _Camera.cameraProjectionMatrix.mul(modelViewMatrix).mul(_Position.positionLocal); });