UNPKG

@babylonjs/viewer

Version:

The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.

170 lines (166 loc) 9.04 kB
import { F as FlowGraphBlock } from './KHR_interactivity-CEwUaqxQ.esm.js'; import { f as RichTypeVector3, h as RichTypeQuaternion, i as RichTypeMatrix, a as RichTypeBoolean, g as getRichTypeByFlowGraphType, d as RichTypeNumber } from './declarationMapper-CqO08-WM.esm.js'; import { M as Matrix, V as Vector3, aD as Quaternion, u as RegisterClass } from './index-MZPybX0H.esm.js'; import { F as FlowGraphUnaryOperationBlock } from './flowGraphUnaryOperationBlock-Bewxi-_r.esm.js'; import { F as FlowGraphBinaryOperationBlock } from './flowGraphBinaryOperationBlock-D6AJ5o7d.esm.js'; import './objectModelMapping-De5EKNEZ.esm.js'; import './spotLight.pure-CRdZC6Ci.esm.js'; import './flowGraphCachedOperationBlock-oE7khWes.esm.js'; /** This file must only contain pure code and pure imports */ /** * Transposes a matrix. */ class FlowGraphTransposeBlock extends FlowGraphUnaryOperationBlock { /** * Creates a new instance of the block. * @param config the configuration of the block */ constructor(config) { super(getRichTypeByFlowGraphType(config?.matrixType || "Matrix" /* FlowGraphTypes.Matrix */), getRichTypeByFlowGraphType(config?.matrixType || "Matrix" /* FlowGraphTypes.Matrix */), (a) => (a.transpose ? a.transpose() : Matrix.Transpose(a)), "FlowGraphTransposeBlock" /* FlowGraphBlockNames.Transpose */, config); } } /** * Gets the determinant of a matrix. */ class FlowGraphDeterminantBlock extends FlowGraphUnaryOperationBlock { /** * Creates a new instance of the block. * @param config the configuration of the block */ constructor(config) { super(getRichTypeByFlowGraphType(config?.matrixType || "Matrix" /* FlowGraphTypes.Matrix */), RichTypeNumber, (a) => a.determinant(), "FlowGraphDeterminantBlock" /* FlowGraphBlockNames.Determinant */, config); } } /** * Inverts a matrix. */ class FlowGraphInvertMatrixBlock extends FlowGraphUnaryOperationBlock { /** * Creates a new instance of the inverse block. * @param config the configuration of the block */ constructor(config) { super(getRichTypeByFlowGraphType(config?.matrixType || "Matrix" /* FlowGraphTypes.Matrix */), getRichTypeByFlowGraphType(config?.matrixType || "Matrix" /* FlowGraphTypes.Matrix */), (a) => (a.inverse ? a.inverse() : Matrix.Invert(a)), "FlowGraphInvertMatrixBlock" /* FlowGraphBlockNames.InvertMatrix */, config); } } /** * Multiplies two matrices. */ class FlowGraphMatrixMultiplicationBlock extends FlowGraphBinaryOperationBlock { /** * Creates a new instance of the multiplication block. * Note - this is similar to the math multiplication if not using matrix per-component multiplication. * @param config the configuration of the block */ constructor(config) { super(getRichTypeByFlowGraphType(config?.matrixType || "Matrix" /* FlowGraphTypes.Matrix */), getRichTypeByFlowGraphType(config?.matrixType || "Matrix" /* FlowGraphTypes.Matrix */), getRichTypeByFlowGraphType(config?.matrixType || "Matrix" /* FlowGraphTypes.Matrix */), (a, b) => b.multiply(a), "FlowGraphMatrixMultiplicationBlock" /* FlowGraphBlockNames.MatrixMultiplication */, config); } } /** * Matrix decompose block */ class FlowGraphMatrixDecomposeBlock extends FlowGraphBlock { constructor(config) { super(config); this.input = this.registerDataInput("input", RichTypeMatrix); this.position = this.registerDataOutput("position", RichTypeVector3); this.rotationQuaternion = this.registerDataOutput("rotationQuaternion", RichTypeQuaternion); this.scaling = this.registerDataOutput("scaling", RichTypeVector3); this.isValid = this.registerDataOutput("isValid", RichTypeBoolean, false); } _updateOutputs(context) { const cachedExecutionId = context._getExecutionVariable(this, "executionId", -1); const cachedPosition = context._getExecutionVariable(this, "cachedPosition", null); const cachedRotation = context._getExecutionVariable(this, "cachedRotation", null); const cachedScaling = context._getExecutionVariable(this, "cachedScaling", null); if (cachedExecutionId === context.executionId && cachedPosition && cachedRotation && cachedScaling) { this.position.setValue(cachedPosition, context); this.rotationQuaternion.setValue(cachedRotation, context); this.scaling.setValue(cachedScaling, context); } else { const matrix = this.input.getValue(context); const position = cachedPosition || new Vector3(); const rotation = cachedRotation || new Quaternion(); const scaling = cachedScaling || new Vector3(); // check matrix last column components should be 0,0,0,1 // round them to 4 decimal places const m3 = Math.round(matrix.m[3] * 10000) / 10000; const m7 = Math.round(matrix.m[7] * 10000) / 10000; const m11 = Math.round(matrix.m[11] * 10000) / 10000; const m15 = Math.round(matrix.m[15] * 10000) / 10000; if (m3 !== 0 || m7 !== 0 || m11 !== 0 || m15 !== 1) { this.isValid.setValue(false, context); this.position.setValue(Vector3.Zero(), context); this.rotationQuaternion.setValue(Quaternion.Identity(), context); this.scaling.setValue(Vector3.One(), context); return; } // make the checks for validity const valid = matrix.decompose(scaling, rotation, position); this.isValid.setValue(valid, context); this.position.setValue(position, context); this.rotationQuaternion.setValue(rotation, context); this.scaling.setValue(scaling, context); context._setExecutionVariable(this, "cachedPosition", position); context._setExecutionVariable(this, "cachedRotation", rotation); context._setExecutionVariable(this, "cachedScaling", scaling); context._setExecutionVariable(this, "executionId", context.executionId); } } getClassName() { return "FlowGraphMatrixDecompose" /* FlowGraphBlockNames.MatrixDecompose */; } } /** * Matrix compose block */ class FlowGraphMatrixComposeBlock extends FlowGraphBlock { constructor(config) { super(config); this.position = this.registerDataInput("position", RichTypeVector3); this.rotationQuaternion = this.registerDataInput("rotationQuaternion", RichTypeQuaternion); this.scaling = this.registerDataInput("scaling", RichTypeVector3); this.value = this.registerDataOutput("value", RichTypeMatrix); } _updateOutputs(context) { const cachedExecutionId = context._getExecutionVariable(this, "executionId", -1); const cachedMatrix = context._getExecutionVariable(this, "cachedMatrix", null); if (cachedExecutionId === context.executionId && cachedMatrix) { this.value.setValue(cachedMatrix, context); } else { const matrix = Matrix.Compose(this.scaling.getValue(context), this.rotationQuaternion.getValue(context), this.position.getValue(context)); this.value.setValue(matrix, context); context._setExecutionVariable(this, "cachedMatrix", matrix); context._setExecutionVariable(this, "executionId", context.executionId); } } getClassName() { return "FlowGraphMatrixCompose" /* FlowGraphBlockNames.MatrixCompose */; } } let _Registered = false; /** * Register side effects for flowGraphMatrixMathBlocks. * Safe to call multiple times; only the first call has an effect. */ function RegisterFlowGraphMatrixMathBlocks() { if (_Registered) { return; } _Registered = true; RegisterClass("FlowGraphTransposeBlock" /* FlowGraphBlockNames.Transpose */, FlowGraphTransposeBlock); RegisterClass("FlowGraphDeterminantBlock" /* FlowGraphBlockNames.Determinant */, FlowGraphDeterminantBlock); RegisterClass("FlowGraphInvertMatrixBlock" /* FlowGraphBlockNames.InvertMatrix */, FlowGraphInvertMatrixBlock); RegisterClass("FlowGraphMatrixMultiplicationBlock" /* FlowGraphBlockNames.MatrixMultiplication */, FlowGraphMatrixMultiplicationBlock); RegisterClass("FlowGraphMatrixDecompose" /* FlowGraphBlockNames.MatrixDecompose */, FlowGraphMatrixDecomposeBlock); RegisterClass("FlowGraphMatrixCompose" /* FlowGraphBlockNames.MatrixCompose */, FlowGraphMatrixComposeBlock); } /** * Re-exports pure implementation and applies runtime side effects. * Import flowGraphMatrixMathBlocks.pure for tree-shakeable, side-effect-free usage. */ RegisterFlowGraphMatrixMathBlocks(); export { FlowGraphDeterminantBlock, FlowGraphInvertMatrixBlock, FlowGraphMatrixComposeBlock, FlowGraphMatrixDecomposeBlock, FlowGraphMatrixMultiplicationBlock, FlowGraphTransposeBlock, RegisterFlowGraphMatrixMathBlocks }; //# sourceMappingURL=flowGraphMatrixMathBlocks-BMTR24-s.esm.js.map