@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
2 lines (1 loc) • 2.46 kB
JavaScript
import{platform as t}from"../../core/platform.js";import{EventHandler as e}from"../../core/event-handler.js";import{XrView as s}from"./xr-view.js";import{XRDEPTHSENSINGFORMAT_L8A8 as i,XRDEPTHSENSINGFORMAT_F32 as a,XRDEPTHSENSINGUSAGE_GPU as r,XRTYPE_AR as h}from"./constants.js";import{PIXELFORMAT_LA8 as o,PIXELFORMAT_R32F as n}from"../../platform/graphics/constants.js";class p extends e{constructor(e){super(),this._manager=void 0,this._index=new Map,this._indexTmp=new Map,this._list=[],this._supportedColor=t.browser&&!!window.XRCamera&&!!window.XRWebGLBinding,this._supportedDepth=t.browser&&!!window.XRDepthInformation,this._availableColor=!1,this._availableDepth=!1,this._depthUsage="",this._depthFormat="",this._depthFormats={[i]:o,[a]:n},this._manager=e,this._manager.on("start",this._onSessionStart,this),this._manager.on("end",this._onSessionEnd,this)}get list(){return this._list}get supportedColor(){return this._supportedColor}get supportedDepth(){return this._supportedDepth}get availableColor(){return this._availableColor}get availableDepth(){return this._availableDepth}get depthUsage(){return this._depthUsage}get depthGpuOptimized(){return this._depthUsage===r}get depthFormat(){return this._depthFormat}get depthPixelFormat(){var t;return null!=(t=this._depthFormats[this._depthFormat])?t:null}update(t,e){for(let t=0;t<e.length;t++)this._indexTmp.set(e[t].eye,e[t]);for(const[i,a]of this._indexTmp){let r=this._index.get(i);r?r.update(t,a):(r=new s(this._manager,a,e.length),this._index.set(i,r),this._list.push(r),r.update(t,a),this.fire("add",r))}for(const[t,e]of this._index){if(this._indexTmp.has(t))continue;e.destroy(),this._index.delete(t);const s=this._list.indexOf(e);-1!==s&&this._list.splice(s,1),this.fire("remove",e)}this._indexTmp.clear()}get(t){return this._index.get(t)||null}_onSessionStart(){if(this._manager.type===h&&this._manager.session.enabledFeatures&&(this._availableColor=-1!==this._manager.session.enabledFeatures.indexOf("camera-access"),this._availableDepth=-1!==this._manager.session.enabledFeatures.indexOf("depth-sensing"),this._availableDepth)){const t=this._manager.session;this._depthUsage=t.depthUsage,this._depthFormat=t.depthDataFormat}}_onSessionEnd(){for(const t of this._index.values())t.destroy();this._index.clear(),this._availableColor=!1,this._availableDepth=!1,this._depthUsage="",this._depthFormat="",this._list.length=0}}p.EVENT_ADD="add",p.EVENT_REMOVE="remove";export{p as XrViews};