@openhps/core
Version:
Open Hybrid Positioning System - Core component
173 lines (157 loc) • 5.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.modelWorldMatrixInverse = exports.modelWorldMatrix = exports.modelViewPosition = exports.modelViewMatrix = exports.modelScale = exports.modelRadius = exports.modelPosition = exports.modelNormalMatrix = exports.modelDirection = exports.mediumpModelViewMatrix = exports.highpModelViewMatrix = exports.highpModelNormalViewMatrix = exports.default = void 0;
var _Object3DNode = _interopRequireDefault(require("./Object3DNode.js"));
var _TSLBase = require("../tsl/TSLBase.js");
var _UniformNode = require("../core/UniformNode.js");
var _Matrix = require("../../math/Matrix4.js");
var _Camera = require("./Camera.js");
var _Matrix2 = require("../../math/Matrix3.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* This type of node is a specialized version of `Object3DNode`
* with larger set of model related metrics. Unlike `Object3DNode`,
* `ModelNode` extracts the reference to the 3D object from the
* current node frame state.
*
* @augments Object3DNode
*/
class ModelNode extends _Object3DNode.default {
static get type() {
return 'ModelNode';
}
/**
* Constructs a new object model node.
*
* @param {('position'|'viewPosition'|'direction'|'scale'|'worldMatrix')} scope - The node represents a different type of transformation depending on the scope.
*/
constructor(scope) {
super(scope);
}
/**
* Extracts the model reference from the frame state and then
* updates the uniform value depending on the scope.
*
* @param {NodeFrame} frame - The current node frame.
*/
update(frame) {
this.object3d = frame.object;
super.update(frame);
}
}
var _default = exports.default = ModelNode;
/**
* TSL object that represents the object's direction in world space.
*
* @tsl
* @type {ModelNode<vec3>}
*/
const modelDirection = exports.modelDirection = /*@__PURE__*/(0, _TSLBase.nodeImmutable)(ModelNode, ModelNode.DIRECTION);
/**
* TSL object that represents the object's world matrix.
*
* @tsl
* @type {ModelNode<mat4>}
*/
const modelWorldMatrix = exports.modelWorldMatrix = /*@__PURE__*/(0, _TSLBase.nodeImmutable)(ModelNode, ModelNode.WORLD_MATRIX);
/**
* TSL object that represents the object's position in world space.
*
* @tsl
* @type {ModelNode<vec3>}
*/
const modelPosition = exports.modelPosition = /*@__PURE__*/(0, _TSLBase.nodeImmutable)(ModelNode, ModelNode.POSITION);
/**
* TSL object that represents the object's scale in world space.
*
* @tsl
* @type {ModelNode<vec3>}
*/
const modelScale = exports.modelScale = /*@__PURE__*/(0, _TSLBase.nodeImmutable)(ModelNode, ModelNode.SCALE);
/**
* TSL object that represents the object's position in view/camera space.
*
* @tsl
* @type {ModelNode<vec3>}
*/
const modelViewPosition = exports.modelViewPosition = /*@__PURE__*/(0, _TSLBase.nodeImmutable)(ModelNode, ModelNode.VIEW_POSITION);
/**
* TSL object that represents the object's radius.
*
* @tsl
* @type {ModelNode<float>}
*/
const modelRadius = exports.modelRadius = /*@__PURE__*/(0, _TSLBase.nodeImmutable)(ModelNode, ModelNode.RADIUS);
/**
* TSL object that represents the object's normal matrix.
*
* @tsl
* @type {UniformNode<mat3>}
*/
const modelNormalMatrix = exports.modelNormalMatrix = /*@__PURE__*/(0, _UniformNode.uniform)(new _Matrix2.Matrix3()).onObjectUpdate(({
object
}, self) => self.value.getNormalMatrix(object.matrixWorld));
/**
* TSL object that represents the object's inverse world matrix.
*
* @tsl
* @type {UniformNode<mat4>}
*/
const modelWorldMatrixInverse = exports.modelWorldMatrixInverse = /*@__PURE__*/(0, _UniformNode.uniform)(new _Matrix.Matrix4()).onObjectUpdate(({
object
}, self) => self.value.copy(object.matrixWorld).invert());
/**
* TSL object that represents the object's model view matrix.
*
* @tsl
* @type {Node<mat4>}
*/
const modelViewMatrix = exports.modelViewMatrix = /*@__PURE__*/(0, _TSLBase.Fn)(builder => {
return builder.renderer.nodes.modelViewMatrix || mediumpModelViewMatrix;
}).once()().toVar('modelViewMatrix');
// GPU Precision
/**
* TSL object that represents the object's model view in `mediump` precision.
*
* @tsl
* @type {Node<mat4>}
*/
const mediumpModelViewMatrix = exports.mediumpModelViewMatrix = /*@__PURE__*/_Camera.cameraViewMatrix.mul(modelWorldMatrix);
// CPU Precision
/**
* TSL object that represents the object's model view in `highp` precision
* which is achieved by computing the matrix in JS and not in the shader.
*
* @tsl
* @type {Node<mat4>}
*/
const highpModelViewMatrix = exports.highpModelViewMatrix = /*@__PURE__*/(0, _TSLBase.Fn)(builder => {
builder.context.isHighPrecisionModelViewMatrix = true;
return (0, _UniformNode.uniform)('mat4').onObjectUpdate(({
object,
camera
}) => {
return object.modelViewMatrix.multiplyMatrices(camera.matrixWorldInverse, object.matrixWorld);
});
}).once()().toVar('highpModelViewMatrix');
/**
* TSL object that represents the object's model normal view in `highp` precision
* which is achieved by computing the matrix in JS and not in the shader.
*
* @tsl
* @type {Node<mat3>}
*/
const highpModelNormalViewMatrix = exports.highpModelNormalViewMatrix = /*@__PURE__*/(0, _TSLBase.Fn)(builder => {
const isHighPrecisionModelViewMatrix = builder.context.isHighPrecisionModelViewMatrix;
return (0, _UniformNode.uniform)('mat3').onObjectUpdate(({
object,
camera
}) => {
if (isHighPrecisionModelViewMatrix !== true) {
object.modelViewMatrix.multiplyMatrices(camera.matrixWorldInverse, object.matrixWorld);
}
return object.normalMatrix.getNormalMatrix(object.modelViewMatrix);
});
}).once()().toVar('highpModelNormalViewMatrix');