x_ite
Version:
X_ITE X3D Browser, view and manipulate X3D, VRML, glTF and other 3D sources in HTML.
2 lines • 11 kB
JavaScript
/* X_ITE v11.5.0 */
const t=window[Symbol.for("X_ITE.X3D-11.5.0")];(()=>{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 u=t.VertexArray;var p=s.n(u);const x=t.Layer;var m=s.n(x);const f=t.Matrix4;var g=s.n(f);const b=t.Namespace;var w=s.n(b);function v(t){const e=t.getContext();this.browser=t,this.vertexArrayObject=new(p())(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(v.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 u=this.browser,p=u.getContext(),x=u.getViewport();l.bind(),p.viewport(...x),p.scissor(...x);const m=n*Math.abs(h.origin.z),f=h.xAxis.normalize().multiply(m),g=h.yAxis.normalize().multiply(m),b=h.zAxis.normalize().multiply(m);s.set(...f,0,...g,0,...b,0,...h.origin,1),t.set(d),e.set(s),p.depthMask(!1),p.disable(p.DEPTH_TEST),p.enable(p.BLEND),p.disable(p.CULL_FACE);{const s=u.getDefaultMaterial().getShader(this.circleGeometryContext);s.enable(p),s.setClipPlanes(p,r),p.uniformMatrix4fv(s.x3d_ProjectionMatrix,!1,t),p.uniformMatrix4fv(s.x3d_ModelViewMatrix,!1,e),p.uniformMatrix4fv(s.x3d_EyeMatrix,!1,i),p.uniform3f(s.x3d_EmissiveColor,0,0,0),p.uniform1f(s.x3d_Transparency,c),this.vertexArrayObject.enable(s.getProgram())&&s.enableVertexAttribute(p,this.circleVertexBuffer,0,0),p.drawArrays(p.LINES,0,this.circleNumVertices)}{const s=u.getDefaultMaterial().getShader(this.diskGeometryContext);s.enable(p),s.setClipPlanes(p,r),p.uniformMatrix4fv(s.x3d_ProjectionMatrix,!1,t),p.uniformMatrix4fv(s.x3d_ModelViewMatrix,!1,e),p.uniformMatrix4fv(s.x3d_EyeMatrix,!1,i),p.uniform3f(s.x3d_EmissiveColor,...a),p.uniform1f(s.x3d_Transparency,o),this.vertexArrayObject.enable(s.getProgram())&&s.enableVertexAttribute(p,this.diskVertexBuffer,0,0),p.drawArrays(p.TRIANGLES,0,this.diskNumVertices)}p.depthMask(!0),p.enable(p.DEPTH_TEST),p.disable(p.BLEND)}})(),dispose(){const t=this.browser.getContext();t.deleteBuffer(this.diskVertexBuffer),this.diskVertexArrayObject.dispose(t)}});const y=v,S=w().add("ScreenPoint",y),M=t.ViewVolume;var V=s.n(M);const R=t.Color3;var P=s.n(R);const A=t.Vector3;var C=s.n(A);const j=t.Rotation4;var E=s.n(j);const F=t.Lock;var _=s.n(F);const B=t.ExamineViewer;var D=s.n(B);Object.assign(D().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 N=t.X3DFlyViewer;var O=s.n(N);const L=new(C())(300,300,300);Object.assign(O().prototype,{gamepads:function(){const t=new(C());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 T=s.n(U);Object.assign(T().prototype,{gamepads(){}});var k=s(254);const I=Symbol(),X=Symbol(),z=Symbol(),G=Symbol(),H=Symbol(),W=Symbol(),q=Symbol(),Y=Symbol(),Z=Symbol(),J=Symbol();function K(){this[Z]=[]}Object.assign(K.prototype,{getPose(){return this[G]},xrAddButton(){k("<div></div>").attr("part","xr-button").attr("title","Start WebXR session.").addClass("x_ite-private-xr-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())},async xrStartSession(){return _().acquire(I,(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[X]=s,this[H]=!0,this[W]=new Set,this[q]=new(o())(this,4,2,.9),this[Y]=new S(this),Object.assign(this[Z],{action:!0}),this[G]={cameraSpaceMatrix:new(g()),viewMatrix:new(g()),views:[]},this.xrUpdateBaseLayer({},i),this.setSession(i),this.removeHit(this.getHit()),this.getRenderingProperties()._ContentScale.addInterest("xrContentScale",this),this.getRenderingProperties()._XRSession=!0}))},xrStopSession(){return _().acquire(I,(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[W])this.removeHit(t);this[X]=null,this[z]=null,this[G]=null,this[H]=!1,this[W]=null,this[q]=null,this[Y]=null,this[J]=null,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:function(){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[H]=!1;break;default:this[H]=!0}},xrUpdateInputSources(t){for(const e of t.added)this[W].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(C()),originalNormal:new(C())})})),e.gamepad&&(e.gamepad.hit=e.hit);for(const e of t.removed)this.removeHit(e.hit),this[W].delete(e);this.xrUpdateGamepads()},xrUpdateGamepads(){this[Z].length=0;for(const{gamepad:t}of this[W])t&&(t.axes.length<4||this[Z].push(t))},xrFrame(t){t&&(this[J]=t,this.xrUpdateNearFarPlanes(),this.getViewer().gamepads(this[Z]),this.xrUpdatePose(),this.addBrowserEvent())},xrUpdatePose(){const t=this[J].getViewerPose(this[X]),e=this[G];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:function(){const t=new(P())(.5,.75,1),e=new(g()),i=new(C())(0,0,-.5),s=new(C()),r=new(C()),n=new(C()),a=new(E());return function(){const o=this.getViewport().getValue(),c=this[G];for(const t of this[W]){const{targetRaySpace:e,matrix:i,inverse:s}=t,r=this[J].getPose(e,this[X]);t.active=!!r,r&&(i.assign(r.transform.matrix),s.assign(r.transform.inverse.matrix))}for(const t of this[W]){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[W]){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[H])for(const[h,{viewMatrix:d,projectionMatrix:l}]of c.views.entries()){const c=this.getFramebuffers()[h];for(const{active:h,gamepad:u,matrix:p,hit:x}of this[W]){if(!h)continue;const m=u?.buttons.some((t=>t.pressed)),f=m?t:P().White;if(e.assign(p).multRight(d),e.multVecMatrix(s.assign(C().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[q].setColor(f).display(s,r,c),!x.id)continue;const g=m?.005:.007;e.assign(p).multRight(d).translate(x.originalPoint).rotate(a.setFromToVec(C().zAxis,x.originalNormal)),this[Y].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 Q=K,$=w().add("X3DWebXRContext",Q);n().add({name:"WebXR",concreteNodes:[],abstractNodes:[],browserContext:$});w().add("WebXRComponent",undefined)})();