UNPKG

playcanvas

Version:

PlayCanvas WebGL game engine

106 lines (105 loc) 3.87 kB
/** * @import { GSplatResource } from '../gsplat/gsplat-resource.js' * @import { GSplatOctreeNodeLod } from './gsplat-octree-node.js' * @import { GSplatAssetLoaderBase } from './gsplat-asset-loader-base.js' */ export class GSplatOctree { /** * @param {string} assetFileUrl - The file URL of the container asset. * @param {Object} data - The parsed JSON data containing info, filenames and tree. */ constructor(assetFileUrl: string, data: any); /** * @type {GSplatOctreeNode[]} */ nodes: GSplatOctreeNode[]; /** * @type {{ url: string, lodLevel: number }[]} */ files: { url: string; lodLevel: number; }[]; /** * @type {number} */ lodLevels: number; /** * The file URL of the container asset, used as the base for resolving relative URLs. * * @type {string} */ assetFileUrl: string; /** * Resources of individual files, identified by their file index. * * @type {Map<number, GSplatResource>} */ fileResources: Map<number, GSplatResource>; /** * Reference counts for each file by file index. Index is fileIndex, value is reference count. * When a file reaches zero references, it is scheduled for cooldown and unload. * * @type {Int32Array} */ fileRefCounts: Int32Array; /** * Cooldown timers for files that reached zero references. Key is fileIndex, value is ticks * remaining. * * @type {Map<number, number>} */ cooldowns: Map<number, number>; /** * Trace out per-LOD counts of currently loaded file resources. * @private */ private _traceLodCounts; /** * Recursively extracts leaf nodes (nodes with 'lods' property) from the hierarchical tree. * * @param {Object} node - The current tree node to process. * @param {Array} leafNodes - Array to collect leaf nodes. * @private */ private _extractLeafNodes; getFileResource(fileIndex: any): GSplatResource; /** * Increments reference count for a file by index and cancels any pending cooldown. * * @param {number} fileIndex - Index of the file in `files` array. */ incRefCount(fileIndex: number): void; /** * Decrements reference count for a file by index. When it reaches zero, start cooldown. * * @param {number} fileIndex - Index of the file in `files` array. * @param {number} cooldownTicks - Number of update ticks before unloading when unused. */ decRefCount(fileIndex: number, cooldownTicks: number): void; /** * Unloads a resource for a file index if currently loaded. * * @param {number} fileIndex - Index of the file in `files` array. * @param {GSplatAssetLoaderBase} assetLoader - Asset loader used to unload the resource. */ unloadResource(fileIndex: number, assetLoader: GSplatAssetLoaderBase): void; /** * Advances cooldowns for zero-ref files and unloads those whose timers expired. * * @param {GSplatAssetLoaderBase} assetLoader - Asset loader used to unload expired resources. */ updateCooldownTick(assetLoader: GSplatAssetLoaderBase): void; /** * Ensures a file resource is loaded and available. This function: * - Starts loading if not already started * - Checks if loading completed and stores the resource if available * * @param {number} fileIndex - The index of the file in the `files` array. * @param {GSplatAssetLoaderBase} assetLoader - The asset loader. */ ensureFileResource(fileIndex: number, assetLoader: GSplatAssetLoaderBase): void; } import { GSplatOctreeNode } from './gsplat-octree-node.js'; import type { GSplatResource } from '../gsplat/gsplat-resource.js'; import type { GSplatAssetLoaderBase } from './gsplat-asset-loader-base.js';