UNPKG

@animech-public/playcanvas

Version:
79 lines (73 loc) 2.37 kB
import { Entity } from '../entity.js'; import { GSplatInstance } from '../../scene/gsplat/gsplat-instance.js'; import { GSplat } from '../../scene/gsplat/gsplat.js'; import { GSplatCompressed } from '../../scene/gsplat/gsplat-compressed.js'; /** * The resource for the gsplat asset type. * * @category Graphics */ class GSplatResource { /** * @param {import('../../platform/graphics/graphics-device.js').GraphicsDevice} device - The graphics device. * @param {import('../../scene/gsplat/gsplat-data.js').GSplatData} splatData - The splat data. * @ignore */ constructor(device, splatData) { /** * @type {import('../../platform/graphics/graphics-device.js').GraphicsDevice} * @ignore */ this.device = void 0; /** * @type {import('../../scene/gsplat/gsplat-data.js').GSplatData} * @ignore */ this.splatData = void 0; /** * @type {GSplat | GSplatCompressed | null} * @ignore */ this.splat = null; this.device = device; this.splatData = splatData; } destroy() { var _this$splat; this.device = null; this.splatData = null; (_this$splat = this.splat) == null || _this$splat.destroy(); this.splat = null; } createSplat() { if (!this.splat) { this.splat = this.splatData.isCompressed ? new GSplatCompressed(this.device, this.splatData) : new GSplat(this.device, this.splatData); } return this.splat; } /** * Instantiates an entity with a {@link GSplatComponent}. * * @param {import('../../scene/gsplat/gsplat-material.js').SplatMaterialOptions} [options] - The options. * @returns {Entity} The entity with {@link GSplatComponent}. */ instantiate(options = {}) { const splatInstance = this.createInstance(options); const entity = new Entity(); const component = entity.addComponent('gsplat', { instance: splatInstance }); // the ply scene data no longer gets automatically rotated on load, so do // it here instead. entity.setLocalEulerAngles(0, 0, 180); // set custom aabb component.customAabb = splatInstance.splat.aabb.clone(); return entity; } createInstance(options = {}) { // shared splat between instances const splat = this.createSplat(); return new GSplatInstance(splat, options); } } export { GSplatResource };