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.

3 lines (2 loc) 12 kB
import{A as e,ci as t,cj as i,C as n,ck as s,cl as r,cm as h,cn as c}from"./index-BPURObVq.esm.min.js";import{_ as l}from"./textureLoaderManager-CGf6Ha4H.esm.min.js";let a=!1;a||(a=!0,e.prototype.displayLoadingUI=function(){if(!t())return;const e=this.loadingScreen;e&&e.displayLoadingUI()},e.prototype.hideLoadingUI=function(){if(!t())return;const e=this._loadingScreen;e&&e.hideLoadingUI()},Object.defineProperty(e.prototype,"loadingScreen",{get:function(){return!this._loadingScreen&&this._renderingCanvas&&(this._loadingScreen=e.DefaultLoadingScreenFactory(this._renderingCanvas)),this._loadingScreen},set:function(e){this._loadingScreen=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"loadingUIText",{set:function(e){this.loadingScreen.loadingUIText=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"loadingUIBackgroundColor",{set:function(e){this.loadingScreen.loadingUIBackgroundColor=e},enumerable:!0,configurable:!0})),i();let u=!1;u||(u=!0,e.prototype.getInputElement=function(){return this._renderingCanvas},e.prototype.getDepthFunction=function(){return this._depthCullingState.depthFunc},e.prototype.setDepthFunction=function(e){this._depthCullingState.depthFunc=e},e.prototype.setDepthFunctionToGreater=function(){this.setDepthFunction(n.GREATER)},e.prototype.setDepthFunctionToGreaterOrEqual=function(){this.setDepthFunction(n.GEQUAL)},e.prototype.setDepthFunctionToLess=function(){this.setDepthFunction(n.LESS)},e.prototype.setDepthFunctionToLessOrEqual=function(){this.setDepthFunction(n.LEQUAL)},e.prototype.getDepthWrite=function(){return this._depthCullingState.depthMask},e.prototype.setDepthWrite=function(e){this._depthCullingState.depthMask=e},e.prototype.setAlphaConstants=function(e,t,i,n){this._alphaState.setAlphaBlendConstants(e,t,i,n)},e.prototype.getAlphaMode=function(e=0){return this._alphaMode[e]},e.prototype.getAlphaEquation=function(e=0){return this._alphaEquation[e]});let p=!1;p||(p=!0,e.prototype.getStencilBuffer=function(){return this._stencilState.stencilTest},e.prototype.setStencilBuffer=function(e){this._stencilState.stencilTest=e},e.prototype.getStencilMask=function(){return this._stencilState.stencilMask},e.prototype.setStencilMask=function(e){this._stencilState.stencilMask=e},e.prototype.getStencilFunction=function(){return this._stencilState.stencilFunc},e.prototype.getStencilBackFunction=function(){return this._stencilState.stencilBackFunc},e.prototype.getStencilFunctionReference=function(){return this._stencilState.stencilFuncRef},e.prototype.getStencilFunctionMask=function(){return this._stencilState.stencilFuncMask},e.prototype.setStencilFunction=function(e){this._stencilState.stencilFunc=e},e.prototype.setStencilBackFunction=function(e){this._stencilState.stencilBackFunc=e},e.prototype.setStencilFunctionReference=function(e){this._stencilState.stencilFuncRef=e},e.prototype.setStencilFunctionMask=function(e){this._stencilState.stencilFuncMask=e},e.prototype.getStencilOperationFail=function(){return this._stencilState.stencilOpStencilFail},e.prototype.getStencilBackOperationFail=function(){return this._stencilState.stencilBackOpStencilFail},e.prototype.getStencilOperationDepthFail=function(){return this._stencilState.stencilOpDepthFail},e.prototype.getStencilBackOperationDepthFail=function(){return this._stencilState.stencilBackOpDepthFail},e.prototype.getStencilOperationPass=function(){return this._stencilState.stencilOpStencilDepthPass},e.prototype.getStencilBackOperationPass=function(){return this._stencilState.stencilBackOpStencilDepthPass},e.prototype.setStencilOperationFail=function(e){this._stencilState.stencilOpStencilFail=e},e.prototype.setStencilBackOperationFail=function(e){this._stencilState.stencilBackOpStencilFail=e},e.prototype.setStencilOperationDepthFail=function(e){this._stencilState.stencilOpDepthFail=e},e.prototype.setStencilBackOperationDepthFail=function(e){this._stencilState.stencilBackOpDepthFail=e},e.prototype.setStencilOperationPass=function(e){this._stencilState.stencilOpStencilDepthPass=e},e.prototype.setStencilBackOperationPass=function(e){this._stencilState.stencilBackOpStencilDepthPass=e},e.prototype.cacheStencilState=function(){this._cachedStencilBuffer=this.getStencilBuffer(),this._cachedStencilFunction=this.getStencilFunction(),this._cachedStencilMask=this.getStencilMask(),this._cachedStencilOperationPass=this.getStencilOperationPass(),this._cachedStencilOperationFail=this.getStencilOperationFail(),this._cachedStencilOperationDepthFail=this.getStencilOperationDepthFail(),this._cachedStencilReference=this.getStencilFunctionReference()},e.prototype.restoreStencilState=function(){this.setStencilFunction(this._cachedStencilFunction),this.setStencilMask(this._cachedStencilMask),this.setStencilBuffer(this._cachedStencilBuffer),this.setStencilOperationPass(this._cachedStencilOperationPass),this.setStencilOperationFail(this._cachedStencilOperationFail),this.setStencilOperationDepthFail(this._cachedStencilOperationDepthFail),this.setStencilFunctionReference(this._cachedStencilReference)}),s(),r();let o=!1;o||(o=!0,h(),e.prototype._loadFileAsync=async function(e,t,i){return await new Promise((n,s)=>{this._loadFile(e,e=>{n(e)},void 0,t,i,(e,t)=>{s(t)})})}),e.GetCompatibleTextureLoader=l;class _{get depthStencilTexture(){return this._depthStencilTexture}setDepthStencilTexture(e,t=!0){t&&this._depthStencilTexture&&this._depthStencilTexture.dispose(),this._depthStencilTexture=e,this._generateDepthBuffer=this._generateStencilBuffer=this._depthStencilTextureWithStencil=!1,e&&(this._generateDepthBuffer=!0,this._generateStencilBuffer=this._depthStencilTextureWithStencil=c(e.format))}get depthStencilTextureWithStencil(){return this._depthStencilTextureWithStencil}get isCube(){return this._isCube}get isMulti(){return this._isMulti}get is2DArray(){return this.layers>0}get is3D(){return this.depth>0}get size(){return this.width}get width(){return this._size.width??this._size}get height(){return this._size.height??this._size}get layers(){return this._size.layers||0}get depth(){return this._size.depth||0}get texture(){return this._textures?.[0]??null}get textures(){return this._textures}get faceIndices(){return this._faceIndices}get layerIndices(){return this._layerIndices}getBaseArrayLayer(e){if(!this._textures)return-1;const t=this._textures[e],i=this._layerIndices?.[e]??0,n=this._faceIndices?.[e]??0;return t.isCube?6*i+n:t.is3D?0:i}get samples(){return this._samples}setSamples(e,t=!0,i=!1){if(this.samples===e&&!i)return e;const n=this._isMulti?this._engine.updateMultipleRenderTargetTextureSampleCount(this,e,t):this._engine.updateRenderTargetTextureSampleCount(this,e);return this._samples=e,n}resolveMSAATextures(){this.isMulti?this._engine.resolveMultiFramebuffer(this):this._engine.resolveFramebuffer(this)}generateMipMaps(){this._engine._currentRenderTarget===this&&(this.isMulti?this._engine.unBindMultiColorAttachmentFramebuffer(this,!0):this._engine.unBindFramebuffer(this,!0)),this.isMulti?this._engine.generateMipMapsMultiFramebuffer(this):this._engine.generateMipMapsFramebuffer(this)}constructor(e,t,i,n,s){this._textures=null,this._faceIndices=null,this._layerIndices=null,this._samples=1,this._attachments=null,this._generateStencilBuffer=!1,this._generateDepthBuffer=!1,this._depthStencilTextureWithStencil=!1,this.disableAutomaticMSAAResolve=!1,this.resolveMSAAColors=!0,this.resolveMSAADepth=!1,this.resolveMSAAStencil=!1,this.depthReadOnly=!1,this.stencilReadOnly=!1,this._isMulti=e,this._isCube=t,this._size=i,this._engine=n,this._depthStencilTexture=null,this.label=s}setTextures(e){Array.isArray(e)?this._textures=e:this._textures=e?[e]:null}setTexture(e,t=0,i=!0){this._textures||(this._textures=[]),this._textures[t]!==e&&(this._textures[t]&&i&&this._textures[t].dispose(),this._textures[t]=e)}setLayerAndFaceIndices(e,t){this._layerIndices=e,this._faceIndices=t}setLayerAndFaceIndex(e=0,t,i){this._layerIndices||(this._layerIndices=[]),this._faceIndices||(this._faceIndices=[]),void 0!==t&&t>=0&&(this._layerIndices[e]=t),void 0!==i&&i>=0&&(this._faceIndices[e]=i)}createDepthStencilTexture(e=0,t=!0,i=!1,s=1,r=n.TEXTUREFORMAT_DEPTH32_FLOAT,h){return this._depthStencilTexture?.dispose(),this._depthStencilTextureWithStencil=i,this._depthStencilTextureLabel=h,this._depthStencilTexture=this._engine.createDepthStencilTexture(this._size,{bilinearFiltering:t,comparisonFunction:e,generateStencil:i,isCube:this._isCube,samples:s,depthTextureFormat:r,label:h},this),this._depthStencilTexture}_shareDepth(e){this.shareDepth(e)}shareDepth(e){this._depthStencilTexture&&(e._depthStencilTexture&&e._depthStencilTexture.dispose(),e._depthStencilTexture=this._depthStencilTexture,e._depthStencilTextureWithStencil=this._depthStencilTextureWithStencil,this._depthStencilTexture.incrementReferences())}_swapAndDie(e){this.texture&&this.texture._swapAndDie(e),this._textures=null,this.dispose(!0)}_cloneRenderTargetWrapper(){let e=null;if(this._isMulti){const t=this.textures;if(t&&t.length>0){let i=!1,s=t.length,r=-1;const h=t[t.length-1]._source;14!==h&&12!==h||(i=!0,r=t[t.length-1].format,s--);const c=[],l=[],a=[],u=[],p=[],o=[],_=[],d={};for(let e=0;e<s;++e){const i=t[e];c.push(i.samplingMode),l.push(i.type),a.push(i.format);void 0!==d[i.uniqueId]?(u.push(-1),_.push(0)):(d[i.uniqueId]=e,i.is2DArray?(u.push(n.TEXTURE_2D_ARRAY),_.push(i.depth)):i.isCube?(u.push(n.TEXTURE_CUBE_MAP),_.push(0)):i.is3D?(u.push(n.TEXTURE_3D),_.push(i.depth)):(u.push(n.TEXTURE_2D),_.push(0))),this._faceIndices&&p.push(this._faceIndices[e]??0),this._layerIndices&&o.push(this._layerIndices[e]??0)}const S={samplingModes:c,generateMipMaps:t[0].generateMipMaps,generateDepthBuffer:this._generateDepthBuffer,generateStencilBuffer:this._generateStencilBuffer,generateDepthTexture:i,depthTextureFormat:r,types:l,formats:a,textureCount:s,targetTypes:u,faceIndex:p,layerIndex:o,layerCounts:_,label:this.label},f={width:this.width,height:this.height,depth:this.depth};e=this._engine.createMultipleRenderTarget(f,S);for(let i=0;i<s;++i){if(-1!==u[i])continue;const n=d[t[i].uniqueId];e.setTexture(e.textures[n],i)}}}else{const t={};if(t.generateDepthBuffer=this._generateDepthBuffer,t.generateMipMaps=this.texture?.generateMipMaps??!1,t.generateStencilBuffer=this._generateStencilBuffer,t.samplingMode=this.texture?.samplingMode,t.type=this.texture?.type,t.format=this.texture?.format,t.noColorAttachment=!this._textures,t.label=this.label,this.isCube)e=this._engine.createRenderTargetCubeTexture(this.width,t);else{const i={width:this.width,height:this.height,layers:this.is2DArray||this.is3D?this.texture?.depth:void 0};e=this._engine.createRenderTargetTexture(i,t)}e.texture&&(e.texture.isReady=!0)}return e}_swapRenderTargetWrapper(e){if(this._textures&&e._textures)for(let t=0;t<this._textures.length;++t)this._textures[t]._swapAndDie(e._textures[t],!1),e._textures[t].isReady=!0;this._depthStencilTexture&&e._depthStencilTexture&&(this._depthStencilTexture._swapAndDie(e._depthStencilTexture),e._depthStencilTexture.isReady=!0),this._textures=null,this._depthStencilTexture=null}_rebuild(){const e=this._cloneRenderTargetWrapper();if(e){if(this._depthStencilTexture){const t=this._depthStencilTexture.samplingMode,i=this._depthStencilTexture.format,s=t===n.TEXTURE_BILINEAR_SAMPLINGMODE||t===n.TEXTURE_TRILINEAR_SAMPLINGMODE||t===n.TEXTURE_LINEAR_LINEAR_MIPNEAREST;e.createDepthStencilTexture(this._depthStencilTexture._comparisonFunction,s,this._depthStencilTextureWithStencil,this._depthStencilTexture.samples,i,this._depthStencilTextureLabel)}this.samples>1&&e.setSamples(this.samples),e._swapRenderTargetWrapper(this),e.dispose()}}releaseTextures(){if(this._textures)for(let e=0;e<this._textures.length;++e)this._textures[e].dispose();this._textures=null}dispose(e=!1){e||(this._depthStencilTexture?.dispose(),this._depthStencilTexture=null,this.releaseTextures()),this._engine._releaseRenderTargetWrapper(this)}}export{_ as R}; //# sourceMappingURL=renderTargetWrapper-BsxrLXvO.esm.min.js.map