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.

122 lines (118 loc) 4.39 kB
import { F as FlowGraphBlock } from './KHR_interactivity-CEwUaqxQ.esm.js'; import { R as RichTypeAny } from './declarationMapper-CqO08-WM.esm.js'; import { u as RegisterClass } from './index-MZPybX0H.esm.js'; import './objectModelMapping-De5EKNEZ.esm.js'; import './spotLight.pure-CRdZC6Ci.esm.js'; /** This file must only contain pure code and pure imports */ /** * Maximum number of log entries stored by the debug block. */ // eslint-disable-next-line @typescript-eslint/naming-convention const MAX_LOG_ENTRIES = 100; /** * A passthrough block used to debug data values flowing through connections. * Spliced into a data connection to observe the value passing through it. */ class FlowGraphDebugBlock extends FlowGraphBlock { constructor(config) { super(config); /** * Log of values that have passed through this block. * Each entry is a [displayString, tooltipString] tuple. */ this.log = []; /** * Whether this block is a debug block. * Used by the editor to identify debug blocks. */ this._isDebug = true; this.input = this.registerDataInput("input", RichTypeAny); this.output = this.registerDataOutput("output", RichTypeAny); } /** * @internal */ _updateOutputs(context) { const value = this.input.getValue(context); this.output.setValue(value, context); this._logValue(value); } /** * Format and store a value in the log. * @param value */ _logValue(value) { if (value === null || value === undefined) { this.log.push(["null", "null"]); } else { const formatted = FlowGraphDebugBlock._FormatValue(value); this.log.push([formatted, String(value)]); } if (this.log.length > MAX_LOG_ENTRIES) { this.log.shift(); } } /** * Type-aware value formatting. * @param value the value to format * @returns a human-readable string */ static _FormatValue(value) { if (typeof value === "number") { return Number.isInteger(value) ? value.toString() : value.toFixed(4); } if (typeof value === "boolean" || typeof value === "string") { return String(value); } // Vector-like objects with x, y, z, w if (value && typeof value === "object") { if ("w" in value && "x" in value && "y" in value && "z" in value) { return `(${value.x.toFixed(3)}, ${value.y.toFixed(3)}, ${value.z.toFixed(3)}, ${value.w.toFixed(3)})`; } if ("z" in value && "x" in value && "y" in value) { return `(${value.x.toFixed(3)}, ${value.y.toFixed(3)}, ${value.z.toFixed(3)})`; } if ("x" in value && "y" in value) { return `(${value.x.toFixed(3)}, ${value.y.toFixed(3)})`; } // Color3/Color4 with r, g, b if ("r" in value && "g" in value && "b" in value) { const a = "a" in value ? `, ${value.a.toFixed(3)}` : ""; return `(${value.r.toFixed(3)}, ${value.g.toFixed(3)}, ${value.b.toFixed(3)}${a})`; } if (typeof value.toString === "function" && value.toString !== Object.prototype.toString) { return value.toString(); } } try { const str = JSON.stringify(value); return str.length > 64 ? str.substring(0, 61) + "..." : str; } catch { return String(value); } } getClassName() { return "FlowGraphDebugBlock" /* FlowGraphBlockNames.DebugBlock */; } } let _Registered = false; /** * Register side effects for flowGraphDebugBlock. * Safe to call multiple times; only the first call has an effect. */ function RegisterFlowGraphDebugBlock() { if (_Registered) { return; } _Registered = true; RegisterClass("FlowGraphDebugBlock" /* FlowGraphBlockNames.DebugBlock */, FlowGraphDebugBlock); } /** * Re-exports pure implementation and applies runtime side effects. * Import flowGraphDebugBlock.pure for tree-shakeable, side-effect-free usage. */ RegisterFlowGraphDebugBlock(); export { FlowGraphDebugBlock, RegisterFlowGraphDebugBlock }; //# sourceMappingURL=flowGraphDebugBlock-DcfxoFQm.esm.js.map