x_ite
Version:
X_ITE X3D Browser, view and manipulate X3D, VRML, glTF and other 3D sources in HTML.
2 lines • 18.4 kB
JavaScript
/* X_ITE v11.6.6 */
const e=window[Symbol.for("X_ITE.X3D-11.6.6")];(()=>{var t={254:t=>{t.exports=e.jquery}},r={};function i(e){var s=r[e];if(void 0!==s)return s.exports;var a=r[e]={exports:{}};return t[e](a,a.exports,i),a.exports}i.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return i.d(t,{a:t}),t},i.d=(e,t)=>{for(var r in t)i.o(t,r)&&!i.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);const s=e.Components;var a=i.n(s);const n=e.Namespace;var o=i.n(n);const u=o().add("Panorama2.fs","#version 300 es\nprecision highp float;precision highp int;precision highp sampler2D;const float M_PI=3.1415926535897932384626433832795;in vec2 texCoord;out vec4 x3d_FragColor;uniform sampler2D x3d_PanoramaTextureEXT;uniform int x3d_CurrentFaceEXT;vec3 uvToXYZ(const in int face,const in vec2 uv){switch(face){case 0:return vec3(1.,uv.y,uv.x);case 1:return vec3(-1.,uv.y,-uv.x);case 2:return vec3(uv.x,uv.y,-1.);case 3:return vec3(-uv.x,uv.y,1.);case 4:return vec3(uv.y,-1.,uv.x);default:return vec3(-uv.y,1.,uv.x);}}vec2 dirToUV(const in vec3 dir){return vec2(.5+.5*atan(dir.z,dir.x)/M_PI,1.-acos(dir.y)/M_PI);}vec3 panoramaToCubeMap(const in int face,const in vec2 texCoord){vec3 scan=uvToXYZ(face,texCoord);vec3 direction=normalize(scan);vec2 src=dirToUV(direction);return texture(x3d_PanoramaTextureEXT,src).rgb;}void main(){x3d_FragColor=vec4(panoramaToCubeMap(x3d_CurrentFaceEXT,texCoord),1.);}"),h=Symbol();function d(){}Object.assign(d.prototype,{getPanoramaShader(){return this[h]??=this.createShader("Panorama","FullScreen",`data:x-shader/x-fragment,${u}`,[],["x3d_PanoramaTextureEXT","x3d_CurrentFaceEXT"])}});const T=d,p=o().add("X3DCubeMapTexturingContext",T),c=e.Fields;var g=i.n(c);const x=e.X3DFieldDefinition;var l=i.n(x);const _=e.FieldDefinitionArray;var E=i.n(_);const f=e.X3DNode;var m=i.n(f);const w=e.X3DSingleTextureNode;var b=i.n(w);const R=e.X3DConstants;var M=i.n(R);function S(e){b().call(this,e),this.addType(M().X3DEnvironmentTextureNode);const t=this.getBrowser().getContext();this.target=t.TEXTURE_CUBE_MAP,this.targets=[t.TEXTURE_CUBE_MAP_POSITIVE_Z,t.TEXTURE_CUBE_MAP_NEGATIVE_Z,t.TEXTURE_CUBE_MAP_NEGATIVE_X,t.TEXTURE_CUBE_MAP_POSITIVE_X,t.TEXTURE_CUBE_MAP_POSITIVE_Y,t.TEXTURE_CUBE_MAP_NEGATIVE_Y],this.size=1,this.levels=0}Object.assign(Object.setPrototypeOf(S.prototype,b().prototype),{getTarget(){return this.target},getTextureType:()=>4,getTargets(){return this.targets},getSize(){return this.size},setSize(e){this.size=e,this.levels=Math.floor(Math.log2(Math.max(e,1)))},getLevels(){return this.levels},clearTexture:(()=>{const e=new Uint8Array([255,255,255,255]);return function(){const t=this.getBrowser().getContext();t.bindTexture(this.getTarget(),this.getTexture());for(const r of this.getTargets())t.texImage2D(r,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,e);this.setSize(1),this.setTransparent(!1),this.updateTextureParameters()}})(),updateTextureParameters(){b().prototype.updateTextureParameters.call(this,this.target,this._textureProperties.getValue(),this.texturePropertiesNode,this.size,this.size,!1,!1,!1)},setShaderUniforms(e,t,r,i=t.x3d_Texture[0]){const s=this.getBrowser().getTextureUnit();e.activeTexture(e.TEXTURE0+s),e.bindTexture(e.TEXTURE_CUBE_MAP,this.getTexture()),e.uniform1i(i.textureCube,s)}}),Object.defineProperties(S,m().getStaticProperties("X3DEnvironmentTextureNode","CubeMapTexturing",1));const v=S,C=o().add("X3DEnvironmentTextureNode",v),U=e.X3DCast;var y=i.n(U);const O=e.BitSet;var A=i.n(O);function P(e){C.call(this,e),this.addType(M().ComposedCubeMapTexture),this.addChildObjects(M().outputOnly,"update",new(g().SFTime)),e.getSpecificationVersion()<=3.3&&(this.addAlias("front",this._frontTexture),this.addAlias("back",this._backTexture),this.addAlias("left",this._leftTexture),this.addAlias("right",this._rightTexture),this.addAlias("top",this._topTexture),this.addAlias("bottom",this._bottomTexture)),this.textureNodes=[null,null,null,null,null,null],this.textureBits=new(A())}Object.assign(Object.setPrototypeOf(P.prototype,C.prototype),{initialize(){C.prototype.initialize.call(this);const e=this.getBrowser().getContext();this.frameBuffer=e.createFramebuffer(),this.clearTexture(),this._frontTexture.addInterest("set_texture__",this,0),this._backTexture.addInterest("set_texture__",this,1),this._leftTexture.addInterest("set_texture__",this,2),this._rightTexture.addInterest("set_texture__",this,3),this._topTexture.addInterest("set_texture__",this,5),this._bottomTexture.addInterest("set_texture__",this,4),this._update.addInterest("update",this),this.set_texture__(0,this._frontTexture),this.set_texture__(1,this._backTexture),this.set_texture__(2,this._leftTexture),this.set_texture__(3,this._rightTexture),this.set_texture__(4,this._topTexture),this.set_texture__(5,this._bottomTexture)},set_texture__(e,t){let r=this.textureNodes[e];r?.removeInterest(`set_loadState${e}__`,this),r=this.textureNodes[e]=y()(M().X3DTexture2DNode,t),r?.addInterest(`set_loadState${e}__`,this,e,r),this.set_loadState__(e,r)},set_loadState__(e,t){this.setTextureBit(e,t?.checkLoadState()),this._update.addEvent()},setTextureBit(e,t){this.textureBits.set(e,t===M().COMPLETE_STATE)},isComplete(){if(63!==+this.textureBits)return!1;const e=this.textureNodes,t=e[0].getWidth();for(const r of e){if(r.getWidth()!==t)return!1;if(r.getHeight()!==t)return!1}return!0},update(){if(this.isComplete()){const e=this.getBrowser().getContext(),t=this.textureNodes,r=t[0].getWidth();if(r!==this.getSize()){const t=new Uint8Array(r*r*4);e.bindTexture(this.getTarget(),this.getTexture());for(let i=0;i<6;++i)e.texImage2D(this.getTargets()[i],0,e.RGBA,r,r,0,e.RGBA,e.UNSIGNED_BYTE,t);this.setSize(r),this.updateTextureParameters()}e.bindFramebuffer(e.FRAMEBUFFER,this.frameBuffer);for(let i=0;i<6;++i){const s=t[i];if(e.bindTexture(e.TEXTURE_2D,s.getTexture()),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,s.getTexture(),0),e.bindTexture(this.getTarget(),this.getTexture()),1===s.getTextureType())e.copyTexSubImage2D(this.getTargets()[i],0,0,0,0,0,r,r);else for(let t=0;t<r;++t)e.copyTexSubImage2D(this.getTargets()[i],0,0,r-t-1,0,t,r,1)}this.setTransparent(t.some(e=>e.isTransparent())),this.setLinear(t.some(e=>e.isLinear())),this.setMipMaps(t.every(e=>e.canMipMaps())),this.updateTextureParameters(),this.addNodeEvent()}else this.clearTexture(),this.addNodeEvent()}}),Object.defineProperties(P,{...m().getStaticProperties("ComposedCubeMapTexture","CubeMapTexturing",1,"texture","3.1"),fieldDefinitions:{value:new(E())([new(l())(M().inputOutput,"metadata",new(g().SFNode)),new(l())(M().inputOutput,"description",new(g().SFString)),new(l())(M().inputOutput,"frontTexture",new(g().SFNode)),new(l())(M().inputOutput,"backTexture",new(g().SFNode)),new(l())(M().inputOutput,"leftTexture",new(g().SFNode)),new(l())(M().inputOutput,"rightTexture",new(g().SFNode)),new(l())(M().inputOutput,"topTexture",new(g().SFNode)),new(l())(M().inputOutput,"bottomTexture",new(g().SFNode)),new(l())(M().initializeOnly,"textureProperties",new(g().SFNode))]),enumerable:!0}});for(let e=0;e<6;++e)P.prototype[`set_loadState${e}__`]=function(e,t){this.set_loadState__(e,t)};const F=P,I=o().add("ComposedCubeMapTexture",F),N=e.X3DBaseNode;var D=i.n(N);const B=e.X3DRenderObject;var X=i.n(B);const L=e.TraverseType;var z=i.n(L);function V(e,t,r){D().call(this,e),X().call(this,e),this.renderObject=t,this.node=r,this.framebuffers=[]}Object.assign(Object.setPrototypeOf(V.prototype,D().prototype),X().prototype,{initialize(){D().prototype.initialize.call(this),X().prototype.initialize.call(this)},isIndependent:()=>!1,getNode(){return this.node},getLayer(){return this.renderObject.getLayer()},getBackground(){return this.renderObject.getBackground()},getFog(){return this.renderObject.getFog()},getNavigationInfo(){return this.renderObject.getNavigationInfo()},getViewpoint(){return this.renderObject.getViewpoint()},getViewpointStack(){return this.renderObject.getViewpointStack()},getLightContainer(){return this.renderObject.getLights()[this.lightIndex++]},getFramebuffers(){return this.framebuffers},setFramebuffer(e){this.framebuffers[0]=e},render(e,t,r){switch(e){case z().COLLISION:case z().SHADOW:X().prototype.render.call(this,e,t,r);break;case z().DISPLAY:this.lightIndex=0,X().prototype.render.call(this,e,t,r);for(const e of this.renderObject.getLights())e.modelViewMatrix.pop()}}});for(const e of Object.keys(V.prototype))Object.defineProperty(V.prototype,e,{enumerable:!1});const j=V,G=o().add("DependentRenderer",j),k=e.TextureBuffer;var Y=i.n(k);const W=e.Camera;var H=i.n(W);const $=e.ViewVolume;var K=i.n($);const Z=e.Rotation4;var q=i.n(Z);const J=e.Vector3;var Q=i.n(J);const ee=e.Vector4;var te=i.n(ee);const re=e.Matrix4;var ie=i.n(re);const se=e.Algorithm;var ae=i.n(se);function ne(e){C.call(this,e),this.addType(M().GeneratedCubeMapTexture),this.dependentRenderers=new WeakMap,this.projectionMatrix=new(ie()),this.modelMatrix=new(ie()),this.viewVolume=new(K())}Object.assign(Object.setPrototypeOf(ne.prototype,C.prototype),{initialize(){C.prototype.initialize.call(this),this.clearTexture(),this._size.addInterest("set_size__",this),this.set_size__()},set_size__(){const e=this.getBrowser().getContext(),t=this._size.getValue();if(t>0){const r=new Uint8Array(t*t*4);e.bindTexture(this.getTarget(),this.getTexture());for(const i of this.getTargets())e.texImage2D(i,0,e.RGBA,t,t,0,e.RGBA,e.UNSIGNED_BYTE,r);this.updateTextureParameters(),this.viewport=new(te())(0,0,t,t),this.frameBuffer=new(Y())({browser:this.getBrowser(),width:t,height:t}),this.setSize(t)}else this.frameBuffer=null,this.setSize(0)},traverse(e,t){"NONE"!==this._update.getValue()&&t.isIndependent()&&this.frameBuffer&&(t.getGeneratedCubeMapTextures().push(this),this.modelMatrix.assign(t.getModelViewMatrix().get()).multRight(t.getCameraSpaceMatrix().get()))},renderTexture:(()=>{const e=[new(q())(Q().zAxis,new(Q())(0,0,-1)),new(q())(Q().zAxis,new(Q())(0,0,1)),new(q())(Q().zAxis,new(Q())(1,0,0)),new(q())(Q().zAxis,new(Q())(-1,0,0)),new(q())(Q().zAxis,new(Q())(0,-1,0)),new(q())(Q().zAxis,new(Q())(0,1,0))],t=[new(Q())(-1,-1,1),new(Q())(-1,-1,1),new(Q())(-1,-1,1),new(Q())(-1,-1,1),new(Q())(1,1,1),new(Q())(1,1,1)],r=new(ie());return function(i){if(!this.dependentRenderers.has(i)){const e=new G(this.getExecutionContext(),i,this);e.setup(),this.dependentRenderers.set(i,e)}const s=this.dependentRenderers.get(i),a=this.getBrowser(),n=i.getLayer(),o=a.getContext(),u=s.getBackground(),h=s.getNavigationInfo(),d=s.getViewpoint(),T=a.getHeadlight(),p=h._headlight.getValue(),c=d.getNearDistance(h),g=d.getFarDistance(h),x=H().perspective(ae().radians(90),c,g,1,1,this.projectionMatrix),l=this.frameBuffer.getWidth(),_=this.frameBuffer.getHeight();this.setTransparent(u.isTransparent()),s.setFramebuffer(this.frameBuffer),s.getViewVolumes().push(this.viewVolume.set(x,this.viewport,this.viewport)),s.getProjectionMatrix().push(x),o.bindTexture(this.getTarget(),this.getTexture());for(let i=0;i<6;++i)o.clear(o.COLOR_BUFFER_BIT),s.getCameraSpaceMatrix().push(this.modelMatrix),s.getCameraSpaceMatrix().rotate(e[i]),s.getCameraSpaceMatrix().scale(t[i]),s.getViewMatrix().push(r.assign(s.getCameraSpaceMatrix().get()).inverse()),s.getModelViewMatrix().push(r),p&&(T.modelViewMatrix.push(r),T.modelViewMatrix.multLeft(d.getCameraSpaceMatrix())),n.traverse(z().DISPLAY,s),p&&T.modelViewMatrix.pop(),s.getModelViewMatrix().pop(),s.getCameraSpaceMatrix().pop(),s.getViewMatrix().pop(),o.bindTexture(this.getTarget(),this.getTexture()),o.copyTexSubImage2D(this.getTargets()[i],0,0,0,0,0,l,_);this.updateTextureParameters(),s.getProjectionMatrix().pop(),s.getViewVolumes().pop(),"NEXT_FRAME_ONLY"===this._update.getValue()&&(this._update="NONE")}})(),setShaderUniforms:(()=>{const e=new Float32Array(16);return function(t,r,i,s){C.prototype.setShaderUniforms.call(this,t,r,i,s),i.getNode()===this&&t.uniformMatrix4fv(r.x3d_ModelViewMatrix,!1,e)}})()}),Object.defineProperties(ne,{...m().getStaticProperties("GeneratedCubeMapTexture","CubeMapTexturing",3,"texture","3.0"),fieldDefinitions:{value:new(E())([new(l())(M().inputOutput,"metadata",new(g().SFNode)),new(l())(M().inputOutput,"description",new(g().SFString)),new(l())(M().inputOutput,"update",new(g().SFString)("NONE")),new(l())(M().initializeOnly,"size",new(g().SFInt32)(128)),new(l())(M().initializeOnly,"textureProperties",new(g().SFNode))]),enumerable:!0}});const oe=ne,ue=o().add("GeneratedCubeMapTexture",oe),he=e.X3DUrlObject;var de=i.n(he);const Te=e.Vector2;var pe=i.n(Te);const ce=e.DEVELOPMENT;var ge=i.n(ce),xe=i(254);function le(e){C.call(this,e),de().call(this,e),this.addType(M().ImageCubeMapTexture),this.image=xe("<img></img>"),this.urlStack=new(g().MFString)}Object.assign(Object.setPrototypeOf(le.prototype,C.prototype),de().prototype,{initialize(){C.prototype.initialize.call(this),de().prototype.initialize.call(this),this.clearTexture(),this.image.on("load",this.setImage.bind(this)).on("abort error",this.setError.bind(this)).attr("crossorigin","anonymous"),this.requestImmediateLoad().catch(Function.prototype)},unloadData(){this.clearTexture()},loadData(){this.urlStack.setValue(this._url),this.loadNext()},loadNext(){if(0===this.urlStack.length)return this.clearTexture(),this.setLoadState(M().FAILED_STATE),void this.addNodeEvent();this.URL=new URL(this.urlStack.shift(),this.getExecutionContext().getBaseURL()),this.URL.pathname.match(/\.ktx2?(?:\.gz)?$/)||this.URL.href.match(/^data:image\/ktx2[;,]/)?(this.setLinear(!0),this.setMipMaps(!1),this.getBrowser().getKTXDecoder().then(e=>e.loadKTXFromURL(this.URL,this.getCache())).then(e=>this.setKTXTexture(e)).catch(e=>this.setError({type:e.message}))):(this.setLinear(!1),this.setMipMaps(!0),"data:"!==this.URL.protocol&&(this.getCache()||this.URL.searchParams.set("_",Date.now())),this.image.attr("src",this.URL))},setError(e){"data:"!==this.URL.protocol&&console.warn(`Error loading image '${decodeURI(this.URL)}':`,e.type),this.loadNext()},setKTXTexture(e){if(e.target!==this.getTarget())return this.setError({type:"Invalid KTX texture target, must be 'TEXTURE_CUBE_MAP'."});ge()&&"data:"!==this.URL.protocol&&console.info(`Done loading image cube map texture '${decodeURI(this.URL)}'.`);try{this.setTexture(e),this.setTransparent(!1),this.setSize(e.baseWidth),this.updateTextureParameters(),this.setLoadState(M().COMPLETE_STATE),this.addNodeEvent()}catch(e){this.setError({type:e.message})}},setImage(){ge()&&"data:"!==this.URL.protocol&&console.info(`Done loading image cube map texture '${decodeURI(this.URL)}'.`);try{const e=this.getBrowser().getContext(),t=e.createTexture();e.bindTexture(e.TEXTURE_2D,t),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,this.image[0]),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),this.imageToCubeMap(t,this.image.prop("width"),this.image.prop("height"),!1),this.setLoadState(M().COMPLETE_STATE),this.addNodeEvent()}catch(e){this.setError({type:e.message})}},imageToCubeMap(e,t,r){const i=t/r;Math.abs(i-4/3)<.01&&this.skyBoxToCubeMap(e,t,r),Math.abs(i-2)<.01&&this.panoramaToCubeMap(e,t,r),this.updateTextureParameters()},skyBoxToCubeMap:(()=>{const e=[new(pe())(1,1),new(pe())(3,1),new(pe())(0,1),new(pe())(2,1),new(pe())(1,0),new(pe())(1,2)];return function(t,r,i){const s=this.getBrowser().getContext(),a=s.createFramebuffer(),n=Math.floor(r/4),o=Math.floor(i/3),u=new Uint8Array(n*o*4);s.bindTexture(this.getTarget(),this.getTexture());for(let e=0;e<6;++e)s.texImage2D(this.getTargets()[e],0,s.RGBA,n,o,0,s.RGBA,s.UNSIGNED_BYTE,null);s.bindFramebuffer(s.FRAMEBUFFER,a),s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0,s.TEXTURE_2D,t,0);let h=!1;s.bindTexture(this.getTarget(),this.getTexture());for(let t=0;t<6;++t)s.copyTexSubImage2D(this.getTargets()[t],0,0,0,e[t].x*n,e[t].y*o,n,o),h||(s.readPixels(e[t].x*n,e[t].y*o,n,o,s.RGBA,s.UNSIGNED_BYTE,u),h=this.isImageTransparent(u));s.deleteFramebuffer(a),s.deleteTexture(t),this.setTransparent(h),this.setSize(n)}})(),panoramaToCubeMap(e,t,r){const i=this.getBrowser(),s=i.getContext(),a=i.getPanoramaShader(),n=s.createFramebuffer(),o=i.getTextureUnit(),u=Math.floor(r/2),h=new Uint8Array(u*u*4);s.bindTexture(s.TEXTURE_2D,e),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.MIRRORED_REPEAT),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.MIRRORED_REPEAT),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.LINEAR),s.bindTexture(this.getTarget(),this.getTexture());for(let e=0;e<6;++e)s.texImage2D(this.getTargets()[e],0,s.RGBA,u,u,0,s.RGBA,s.UNSIGNED_BYTE,null);s.useProgram(a.getProgram()),s.activeTexture(s.TEXTURE0+o),s.bindTexture(s.TEXTURE_2D,e),s.uniform1i(a.x3d_PanoramaTextureEXT,o),s.bindFramebuffer(s.FRAMEBUFFER,n),s.viewport(0,0,u,u),s.scissor(0,0,u,u),s.disable(s.DEPTH_TEST),s.enable(s.CULL_FACE),s.frontFace(s.CCW),s.clearColor(0,0,0,0),s.bindVertexArray(i.getFullscreenVertexArrayObject());let d=!1;for(let e=0;e<6;++e)s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0,this.getTargets()[e],this.getTexture(),0),s.clear(s.COLOR_BUFFER_BIT),s.uniform1i(a.x3d_CurrentFaceEXT,e),s.drawArrays(s.TRIANGLES,0,6),d||(s.readPixels(0,0,u,u,s.RGBA,s.UNSIGNED_BYTE,h),d=this.isImageTransparent(h));s.enable(s.DEPTH_TEST),s.deleteFramebuffer(n),s.deleteTexture(e),i.resetTextureUnits(),this.setTransparent(d),this.setSize(u)},dispose(){de().prototype.dispose.call(this),C.prototype.dispose.call(this)}}),Object.defineProperties(le,{...m().getStaticProperties("ImageCubeMapTexture","CubeMapTexturing",2,"texture","3.0"),fieldDefinitions:{value:new(E())([new(l())(M().inputOutput,"metadata",new(g().SFNode)),new(l())(M().inputOutput,"description",new(g().SFString)),new(l())(M().inputOutput,"load",new(g().SFBool)(!0)),new(l())(M().inputOutput,"url",new(g().MFString)),new(l())(M().inputOutput,"autoRefresh",new(g().SFTime)(0)),new(l())(M().inputOutput,"autoRefreshTimeLimit",new(g().SFTime)(3600)),new(l())(M().initializeOnly,"textureProperties",new(g().SFNode))]),enumerable:!0}});const _e=le,Ee=o().add("ImageCubeMapTexture",_e);a().add({name:"CubeMapTexturing",concreteNodes:[I,ue,Ee],abstractNodes:[C],browserContext:p});o().add("CubeMapTexturingComponent",undefined)})();