playcanvas
Version:
PlayCanvas WebGL game engine
87 lines (84 loc) • 3.14 kB
JavaScript
import { BoundingBox } from '../../core/shape/bounding-box.js';
import { Debug } from '../../core/debug.js';
/**
* @import { GraphNode } from '../graph-node.js'
* @import { GSplatResource } from '../gsplat/gsplat-resource.js'
* @import { GSplatOctreeResource } from './gsplat-octree.resource.js'
* @import { Vec2 } from '../../core/math/vec2.js'
*/ /**
* Class representing a placement of a gsplat resource.
*
* @ignore
*/ class GSplatPlacement {
/**
* Create a new GSplatPlacement.
*
* @param {GSplatResource|null} resource - The resource of the splat.
* @param {GraphNode} node - The node that the gsplat is linked to.
* @param {number} lodIndex - The LOD index for this placement.
*/ constructor(resource, node, lodIndex = 0){
/**
* Map of intervals for octree nodes using this placement.
* Key is octree node index, value is Vec2 representing start and end index (inclusive).
*
* @type {Map<number, Vec2>}
*/ this.intervals = new Map();
/**
* The LOD index for this placement.
*
* @type {number}
*/ this.lodIndex = 0;
/**
* LOD distance thresholds for octree-based gsplat. Only used when the
* resource is an octree resource; otherwise ignored and kept null.
*
* @type {number[]|null}
*/ this._lodDistances = null;
/**
* Target number of splats to render for this placement. Set to 0 to disable (default).
*
* @type {number}
*/ this.splatBudget = 0;
/**
* The axis-aligned bounding box for this placement, in local space.
*
* @type {BoundingBox}
*/ this._aabb = new BoundingBox();
this.resource = resource;
this.node = node;
this.lodIndex = lodIndex;
}
set aabb(aabb) {
this._aabb.copy(aabb);
}
get aabb() {
return this._aabb;
}
/**
* Sets LOD distance thresholds. Only applicable for octree resources. The provided array is
* copied. If the resource has an octree with N LOD levels, the array should contain N-1
* elements. For non-octree resources, the value is ignored and kept null.
*
* @type {number[]|null}
*/ set lodDistances(distances) {
const isOctree = !!(this.resource && /** @type {any} */ this.resource.octree);
if (isOctree) {
if (distances) {
const lodLevels = /** @type {any} */ this.resource.octree?.lodLevels ?? 1;
Debug.assert(Array.isArray(distances), 'lodDistances must be an array');
Debug.assert(distances.length >= lodLevels, 'lodDistances must have at least octree LOD levels - 1 entries, privided:', distances.length, 'expected:', lodLevels);
this._lodDistances = distances.slice();
} else {
this._lodDistances = null;
}
}
}
/**
* Gets a copy of LOD distance thresholds, or null when not set.
*
* @type {number[]|null}
*/ get lodDistances() {
return this._lodDistances ? this._lodDistances.slice() : null;
}
}
export { GSplatPlacement };