UNPKG

x_ite

Version:

X_ITE X3D Browser, view and manipulate X3D, VRML, glTF and other 3D sources in HTML.

2 lines 11.2 kB
/* X_ITE v12.2.3 */ const t=window[Symbol.for("X_ITE.X3D-12.2.3")];(()=>{var e={254:e=>{e.exports=t.jquery}},i={};function s(t){var r=i[t];if(void 0!==r)return r.exports;var n=i[t]={exports:{}};return e[t](n,n.exports,s),n.exports}s.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return s.d(e,{a:e}),e},s.d=(t,e)=>{for(var i in e)s.o(e,i)&&!s.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},s.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);const r=t.Components;var n=s.n(r);const a=t.ScreenLine;var o=s.n(a);const c=t.GeometryContext;var h=s.n(c);const d=t.AlphaMode;var l=s.n(d);const p=t.VertexArray;var u=s.n(p);const x=t.Layer;var m=s.n(x);const f=t.Matrix4;var g=s.n(f);const b=t.Namespace;var v=s.n(b);function w(t){const e=t.getContext();this.browser=t,this.vertexArrayObject=new(u())(e),this.circleVertexBuffer=e.createBuffer(),this.circleGeometryContext=new(h())({renderObject:new(m())(t.getPrivateScene()),alphaMode:l().BLEND,geometryType:1}),this.circleGeometryContext.renderObject.setup();const i=t.getCircle2DOptions().getGeometry().getVertices();this.circleNumVertices=i.length/4,e.bindBuffer(e.ARRAY_BUFFER,this.circleVertexBuffer),e.bufferData(e.ARRAY_BUFFER,i.getValue(),e.STATIC_DRAW),this.diskVertexBuffer=e.createBuffer(),this.diskGeometryContext=new(h())({renderObject:this.circleGeometryContext.renderObject,alphaMode:l().BLEND,geometryType:3});const s=t.getDisk2DOptions().getDiskVertices();this.diskNumVertices=s.length/4,e.bindBuffer(e.ARRAY_BUFFER,this.diskVertexBuffer),e.bufferData(e.ARRAY_BUFFER,s.getValue(),e.STATIC_DRAW)}Object.assign(w.prototype,{display:(()=>{const t=new Float32Array(g().IDENTITY),e=new Float32Array(g().IDENTITY),i=new Float32Array(g().IDENTITY),s=new(g()),r=[];return function(n,a,o,c,h,d,l){const p=this.browser,u=p.getContext(),x=p.getViewport();l.bind(),u.viewport(...x),u.scissor(...x),u.blendFuncSeparate(u.SRC_ALPHA,u.ONE_MINUS_SRC_ALPHA,u.ONE,u.ONE_MINUS_SRC_ALPHA);const m=n*Math.abs(h.origin.z),f=h.X_AXIS.normalize().multiply(m),g=h.Y_AXIS.normalize().multiply(m),b=h.Z_AXIS.normalize().multiply(m);s.set(...f,0,...g,0,...b,0,...h.origin,1),t.set(d),e.set(s),u.depthMask(!1),u.disable(u.DEPTH_TEST),u.enable(u.BLEND),u.disable(u.CULL_FACE);{const s=p.getDefaultMaterial().getShader(this.circleGeometryContext);s.enable(u),s.setClipPlanes(u,r),u.uniformMatrix4fv(s.x3d_ProjectionMatrix,!1,t),u.uniformMatrix4fv(s.x3d_ModelViewMatrix,!1,e),u.uniformMatrix4fv(s.x3d_EyeMatrix,!1,i),u.uniform3f(s.x3d_EmissiveColor,0,0,0),u.uniform1f(s.x3d_Transparency,c),this.vertexArrayObject.enable(s.getProgram())&&s.enableVertexAttribute(u,this.circleVertexBuffer,0,0),u.drawArrays(u.LINES,0,this.circleNumVertices)}{const s=p.getDefaultMaterial().getShader(this.diskGeometryContext);s.enable(u),s.setClipPlanes(u,r),u.uniformMatrix4fv(s.x3d_ProjectionMatrix,!1,t),u.uniformMatrix4fv(s.x3d_ModelViewMatrix,!1,e),u.uniformMatrix4fv(s.x3d_EyeMatrix,!1,i),u.uniform3f(s.x3d_EmissiveColor,...a),u.uniform1f(s.x3d_Transparency,o),this.vertexArrayObject.enable(s.getProgram())&&s.enableVertexAttribute(u,this.diskVertexBuffer,0,0),u.drawArrays(u.TRIANGLES,0,this.diskNumVertices)}u.depthMask(!0),u.enable(u.DEPTH_TEST),u.disable(u.BLEND)}})(),dispose(){const t=this.browser.getContext();t.deleteBuffer(this.diskVertexBuffer),this.diskVertexArrayObject.dispose(t)}});const S=w,y=v().add("ScreenPoint",S),M=t.ViewVolume;var V=s.n(M);const R=t.Color3;var A=s.n(R);const P=t.Vector3;var _=s.n(P);const C=t.Rotation4;var E=s.n(C);const j=t.Lock;var N=s.n(j);const D=t.gettext;var B=s.n(D);const F=t.ExamineViewer;var O=s.n(F);Object.assign(O().prototype,{gamepads(t){const e=t.find(({axes:t})=>t[2]||t[3]);if(!e)return void(t.action&&(t.action=!1,this.disconnect()));const i=e.buttons[0].pressed,s=e.buttons[1].pressed;t.button0===i&&t.button1===s||(t.button0=i,t.button1=s,this.disconnect());const r=60/this.getBrowser().currentFrameRate;t.action=!0,i?this.zoom(.005*e.axes[3]*r,Math.sign(-e.axes[3])):s?(this.startPan(0,0),this.pan(5*-e.axes[2]*r,5*e.axes[3]*r)):(this.startRotate(0,0,1),this.rotate(10*-e.axes[2]*r,10*e.axes[3]*r))}});const I=t.X3DFlyViewer;var T=s.n(I);const L=new(_())(300);Object.assign(T().prototype,{gamepads:(()=>{const t=new(_());return function(e){const i=e.find(({axes:t})=>t[2]||t[3]);if(!i)return void(this.startTime=Date.now());const s=i.buttons[0].pressed;i.buttons[1].pressed?(t.set(i.axes[2],-i.axes[3],0).multVec(L),this.direction.add(t).divide(2),this.pan()):(t.set(i.axes[2],0,i.axes[3]).multVec(L).multiply(s?2:1),this.direction.add(t).divide(2),this.fly())}})()});const U=t.X3DViewer;var X=s.n(U);Object.assign(X().prototype,{gamepads(){}});var k=s(254);const H=Symbol(),G=Symbol(),z=Symbol(),W=Symbol(),Y=Symbol(),q=Symbol(),Z=Symbol(),J=Symbol(),K=Symbol(),Q=Symbol();function $(){this[K]=[]}Object.assign($.prototype,{getPose(){return this[W]},xrAddButton(){k("<div></div>").attr("title",B()("Start WebXR session.")).addClass(["x_ite-private-xr-button","x_ite-private-button"]).on("mousedown touchstart",!1).on("mouseup touchend",t=>{t.preventDefault(),t.stopImmediatePropagation(),t.stopPropagation(),this.startAudioElements(),this.getSession()===window?this.xrStartSession():this.xrStopSession()}).appendTo(this.getSurface().find(".x_ite-private-buttons"))},async xrStartSession(){return N().acquire(H,async()=>{if(this.getSession()!==window)return;const t=this.getContext(),e=this.getBrowserOption("XRSessionMode").toLowerCase().replaceAll("_","-"),i=await navigator.xr.requestSession(e),s=await i.requestReferenceSpace("local");await t.makeXRCompatible(),this.finishedEvents().addInterest("xrUpdatePointers",this),i.addEventListener("visibilitychange",()=>this.xrUpdateVisibility()),i.addEventListener("inputsourceschange",t=>this.xrUpdateInputSources(t)),i.addEventListener("end",()=>this.xrStopSession()),this[G]=s,this[Y]=!0,this[q]=new Set,this[Z]=new(o())(this,4,2,.9),this[J]=new y(this),Object.assign(this[K],{action:!0}),this[W]={cameraSpaceMatrix:new(g()),viewMatrix:new(g()),views:[]},this.xrUpdateBaseLayer({},i),this.setSession(i),this.removeHit(this.getHit()),this.getBrowserOptions().checkUpdate(),this.getRenderingProperties()._ContentScale.addInterest("xrContentScale",this),this.getRenderingProperties()._XRSession=!0})},xrStopSession(){return N().acquire(H,async()=>{if(this.getSession()!==window){await this.getSession().end().catch(Function.prototype),this.finishedEvents().removeInterest("xrUpdatePointers",this),this.setSession(window),this.setDefaultFramebuffer(null);for(const{hit:t}of this[q])this.removeHit(t);this[G]=null,this[z]=null,this[W]=null,this[Y]=!1,this[q]=null,this[Z]=null,this[J]=null,this[Q]=null,this.getBrowserOptions().checkUpdate(),this.getRenderingProperties()._ContentScale.removeInterest("xrContentScale",this),this.getRenderingProperties()._XRSession=!1}})},xrContentScale(){this.xrUpdateBaseLayer()},xrUpdateBaseLayer(t={},e=this.getSession()){if(e===window)return;const i=new XRWebGLLayer(e,this.getContext(),Object.assign({antialias:!1,alpha:!0,depth:!1,ignoreDepthValues:!0,framebufferScaleFactor:this.getRenderingProperty("ContentScale")},t));this[z]=i,e.updateRenderState({baseLayer:i}),this.setDefaultFramebuffer(i.framebuffer)},xrUpdateNearFarPlanes:(()=>{const t={};return function(){const e=this.getActiveNavigationInfo(),i=this.getActiveViewpoint();i?(t.depthNear=i.getNearDistance(e),t.depthFar=i.getFarDistance(e)):(t.depthNear=.1,t.depthFar=1e4),this.getSession().updateRenderState(t)}})(),xrUpdateVisibility(t){switch(this.getSession().visibilityState){case"visible-blurred":case"hidden":this[Y]=!1;break;default:this[Y]=!0}},xrUpdateInputSources(t){for(const e of t.added)this[q].add(Object.assign(e,{active:!1,matrix:new(g()),inverse:new(g()),hit:Object.assign(this.getHit().copy(),{button:!1,pressed:!1,pulse:!0,poseViewMatrix:new(g()),originalPoint:new(_()),originalNormal:new(_())})})),e.gamepad&&(e.gamepad.hit=e.hit);for(const e of t.removed)this.removeHit(e.hit),this[q].delete(e);this.xrUpdateGamepads()},xrUpdateGamepads(){this[K].length=0;for(const{gamepad:t}of this[q])t&&(t.axes.length<4||this[K].push(t))},xrFrame(t){t&&(this[Q]=t,this.xrUpdateNearFarPlanes(),this.getViewer().gamepads(this[K]),this.xrUpdatePose(),this.addBrowserEvent())},xrUpdatePose(){const t=this[Q].getViewerPose(this[G]),e=this[W];e.cameraSpaceMatrix.assign(t.transform.matrix),e.viewMatrix.assign(t.transform.inverse.matrix);let i=0;for(const s of t.views){const{x:t,y:r,width:n,height:a}=this[z].getViewport(s);if(!n)continue;this.reshapeFramebuffer(i,t,r,n,a);const o=e.views[i]??={projectionMatrix:new(g()),cameraSpaceMatrix:new(g()),viewMatrix:new(g()),matrix:new(g()),inverse:new(g())};o.projectionMatrix.assign(s.projectionMatrix),o.cameraSpaceMatrix.assign(s.transform.matrix),o.viewMatrix.assign(s.transform.inverse.matrix),o.matrix.assign(e.cameraSpaceMatrix).multRight(o.viewMatrix),o.inverse.assign(o.cameraSpaceMatrix).multRight(e.viewMatrix),++i}this.getFramebuffers().length=i,e.views.length=i},xrUpdatePointers:(()=>{const t=new(A())(.5,.75,1),e=new(g()),i=new(_())(0,0,-.5),s=new(_()),r=new(_()),n=new(_()),a=new(E());return function(){const o=this.getViewport().getValue(),c=this[W];for(const t of this[q]){const{targetRaySpace:e,matrix:i,inverse:s}=t,r=this[Q].getPose(e,this[G]);t.active=!!r,r&&(i.assign(r.transform.matrix),s.assign(r.transform.inverse.matrix))}for(const t of this[q]){const{active:i,gamepad:s,matrix:r,hit:n}=t;if(!i)continue;if(this.touch(o[2]/2,o[3]/2,n,t),this.xrSensorHitPulse(n,s),!n.id)continue;const a=c.views[0].projectionMatrix;n.pressed||n.poseViewMatrix.assign(c.viewMatrix),e.assign(r).multRight(n.poseViewMatrix);for(const t of n.sensors.values())t.projectionMatrix.assign(a),t.modelViewMatrix.multRight(e);V().projectPoint(n.point,e,a,o,n.pointer),n.originalPoint.assign(n.point),n.originalNormal.assign(n.normal),n.ray.multLineMatrix(e),e.multVecMatrix(n.point),e.submatrix.inverse().multMatrixVec(n.normal)}for(const{active:t,gamepad:e,hit:i}of this[q]){if(!t)continue;const s=e?.buttons[0];s?.pressed?i.button||(i.button=!0,i.pressed||=this.buttonPressEvent(0,0,i)):(i.button=!1,i.pressed&&(i.pressed=!1,this.buttonReleaseEvent(i))),this.motionNotifyEvent(0,0,i)}if(this[Y])for(const[h,{viewMatrix:d,projectionMatrix:l}]of c.views.entries()){const c=this.getFramebuffers()[h];for(const{active:h,gamepad:p,matrix:u,hit:x}of this[q]){if(!h)continue;const m=p?.buttons.some(t=>t.pressed),f=m?t:A().WHITE;if(e.assign(u).multRight(d),e.multVecMatrix(s.assign(_().ZERO)),e.multVecMatrix(r.assign(i)),e.multVecMatrix(n.assign(x.originalPoint)),x.id&&n.distance(s)<r.distance(s)&&r.assign(n),s.z>0||r.z>0)continue;if(V().projectPointMatrix(s,l,o,s),V().projectPointMatrix(r,l,o,r),s.z=0,r.z=0,this[Z].setColor(f).display(s,r,c),!x.id)continue;const g=m?.005:.007;e.assign(u).multRight(d).translate(x.originalPoint).rotate(a.setFromToVec(_().Z_AXIS,x.originalNormal)),this[J].display(g,f,.3,.8,e,l,c)}}}})(),xrSensorHitPulse(t,e){t.sensors.size?t.pulse&&(e?.hapticActuators?.[0]?.pulse(.25,10),t.pulse=!1):t.pulse=!0}});const tt=$,et=v().add("X3DWebXRContext",tt);n().add({name:"WebXR",concreteNodes:[],abstractNodes:[],browserContext:et});v().add("WebXRComponent",undefined)})();