UNPKG

@tomorrowevening/hermes

Version:

An extendable set of Web Tools controlled via a separate window for non-intereference with content.

2 lines (1 loc) 6.43 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("three"),c=new n.BufferGeometry;c.setAttribute("position",new n.Float32BufferAttribute([-.5,-.5,0,1.5,-.5,0,-.5,1.5,0],3));c.setAttribute("normal",new n.Float32BufferAttribute([0,0,1,0,0,1],3));c.setAttribute("uv",new n.Float32BufferAttribute([0,0,2,0,0,2],2));const A=new n.OrthographicCamera(-.5,.5,.5,-.5,0,100),l=e=>{e?.dispose()},u=e=>{if(e)if(Array.isArray(e))e.forEach(t=>u(t));else{for(const t in e){const i=e[t];i!==null&&i instanceof n.Texture&&l(i)}if(e.isShaderMaterial===!0){const t=e;for(const i in t.uniforms){const s=t.uniforms[i];s.value!==null&&s.value instanceof n.Texture&&l(s.value)}}e.dispose()}},d=e=>{if(e){for(;e.children.length>0;){const t=e.children[0];t.type==="Audio"?(t.pause(),t.parent&&t.parent.remove(t)):d(t)}if(e.parent&&e.parent.remove(e),e.isMesh){const t=e;t.geometry?.dispose(),u(t.material)}e.dispose!==void 0&&e.dispose()}};exports.totalThreeObjects=0;const g=()=>{exports.totalThreeObjects=0},h=e=>{if(!e)return;let t=e.name.replaceAll(" ","").replaceAll("/",".");if(t.length===0&&(t=`obj_${exports.totalThreeObjects}`,exports.totalThreeObjects++),e.parent!==null&&e.parent.uuid.length>0&&(t=`${e.parent.uuid}.${t}`),e.uuid=t,e.isMesh!==void 0){const i=e;if(Array.isArray(i.material))i.material.forEach((s,r)=>{s.uuid=`${t}.material.${r}`});else{const s=i.material;s.uuid=`${t}.material`}}e.children.forEach(i=>h(i))};class m{static renderer;static canvas;static context=null;static scene=null;static camera=null;static material=null;static inited=!1;static width=100;static height=100;static init(){this.inited||(this.canvas=document.createElement("canvas"),this.canvas.width=this.width,this.canvas.height=this.height,this.context=this.canvas.getContext("2d"),this.inited=!0)}static renderToBlob(t){this.init();const i=t.repeat.clone(),s=t.offset.clone();if(t.repeat.set(1,1),t.offset.set(0,0),this.context!==null){this.context.clearRect(0,0,this.width,this.height);const r=t.image;if(r!=null&&r.width>0){this.canvas.title=t.sourceFile;const a=this.canvas.width/r.width,o=this.renderToCanvas(t);this.context.drawImage(o,0,0,r.width*a,r.height*a)}}return t.repeat.copy(i),t.offset.copy(s),this.canvas.toDataURL("image/png")}static renderToCanvas(t){if(this.material===null){this.camera=new n.OrthographicCamera(-.5,.5,.5,-.5,0,100),this.scene=new n.Scene,this.material=new n.MeshBasicMaterial;const i=new n.BufferGeometry;i.setAttribute("position",new n.Float32BufferAttribute([-.5,-.5,0,1.5,-.5,0,-.5,1.5,0],3)),i.setAttribute("normal",new n.Float32BufferAttribute([0,0,1,0,0,1],3)),i.setAttribute("uv",new n.Float32BufferAttribute([0,0,2,0,0,2],2));const s=new n.Mesh(i,this.material);this.scene.add(s)}if(t.isRenderTargetTexture)this.material.map=t,this.renderer.render(this.scene,this.camera);else{const i=this.renderer.outputColorSpace,s=t.colorSpace;this.renderer.outputColorSpace=n.LinearSRGBColorSpace,t.colorSpace=n.LinearSRGBColorSpace,this.material.map=t,this.renderer.render(this.scene,this.camera),this.renderer.outputColorSpace=i,t.colorSpace=s}return this.renderer.domElement}}function O(e){return new Promise(t=>{const i=new n.ObjectLoader;i.parseAsync(e.scene).then(s=>{const r=new n.AnimationMixer(s);if(e.animations.length>0){const o=e.animations.map(S=>n.AnimationClip.parse(S));r.clipAction(o[0]).play(),r.getRoot().animations=e.animations,r.getRoot().mixer=r}const a=[];e.cameras&&e.cameras.length>0&&e.cameras.forEach(o=>{const p=i.parse(o);a.push(p)}),t({animations:e.animations,model:s,mixer:r,cameras:a})})})}const M=(e,t,i,s)=>{e.setRenderTarget(s),e.clear(),e.render(t,i)};function f(e,t,i,s){e.applyMatrix4(new n.Matrix4().makeTranslation(t,-i,-s))}function v(e){e.computeBoundingBox();const t=e.boundingBox,i=(t.max.x-t.min.x)/2,s=(t.max.y-t.min.y)/2;f(e,i,s,0)}function F(e,t,i){e.left=t/-2,e.right=t/2,e.top=i/2,e.bottom=i/-2,e.position.x=t/2,e.position.y=i/-2,e.updateProjectionMatrix()}function y(e,t,i){const s=1.7777777777777777,r=t/i;let a=t,o=i;r>s?a=i*s:o=t/s,e.left=a/-2,e.right=a/2,e.top=o/2,e.bottom=o/-2,e.updateProjectionMatrix()}function b(){let t="transferControlToOffscreen"in document.createElement("canvas");if(/^((?!chrome|android).)*safari/i.test(navigator.userAgent)){const s=navigator.userAgent.match(/version\/(\d+)/i);t=(s?parseInt(s[1]):0)>=17}return t}function T(e,t,i=!0,s=!1){e.renderOrder=-t;const r=e.material;Array.isArray(r)?r.forEach(a=>{a.colorWrite=i,a.depthWrite=s,a.stencilWrite=!0,a.stencilRef=t,a.stencilFunc=n.AlwaysStencilFunc,a.stencilFail=n.ReplaceStencilOp,a.stencilZFail=n.ReplaceStencilOp,a.stencilZPass=n.ReplaceStencilOp}):(r.colorWrite=i,r.depthWrite=s,r.stencilWrite=!0,r.stencilRef=t,r.stencilFunc=n.AlwaysStencilFunc,r.stencilFail=n.ReplaceStencilOp,r.stencilZFail=n.ReplaceStencilOp,r.stencilZPass=n.ReplaceStencilOp)}function w(e,t,i=!1){const s=e.material;Array.isArray(s)?s.forEach(r=>{r.stencilWrite=!0,r.stencilRef=t,r.stencilFunc=i?n.NotEqualStencilFunc:n.EqualStencilFunc,r.stencilFail=n.KeepStencilOp,r.stencilZFail=n.KeepStencilOp,r.stencilZPass=n.KeepStencilOp}):(s.stencilWrite=!0,s.stencilRef=t,s.stencilFunc=i?n.NotEqualStencilFunc:n.EqualStencilFunc,s.stencilFail=n.KeepStencilOp,s.stencilZFail=n.KeepStencilOp,s.stencilZPass=n.KeepStencilOp)}function B(e){e.blending=n.NormalBlending,e.blendEquation=n.AddEquation,e.blendSrc=n.SrcAlphaFactor,e.blendDst=n.OneMinusSrcAlphaFactor,e.needsUpdate=!0}function C(e){e.blending=n.CustomBlending,e.blendEquation=n.AddEquation,e.blendSrc=n.SrcAlphaFactor,e.blendDst=n.OneFactor,e.needsUpdate=!0}function x(e){e.blending=n.CustomBlending,e.blendEquation=n.AddEquation,e.blendSrc=n.DstColorFactor,e.blendDst=n.OneMinusSrcAlphaFactor,e.needsUpdate=!0}function E(e){e.blending=n.CustomBlending,e.blendEquation=n.AddEquation,e.blendSrc=n.OneMinusDstColorFactor,e.blendDst=n.OneFactor,e.needsUpdate=!0}exports.ExportTexture=m;exports.anchorGeometry=f;exports.anchorGeometryTL=v;exports.createMask=T;exports.dispose=d;exports.disposeMaterial=u;exports.disposeTexture=l;exports.hierarchyUUID=h;exports.orthoCamera=A;exports.parseModelLite=O;exports.renderToTexture=M;exports.resetThreeObjects=g;exports.setMaterialBlendAdd=C;exports.setMaterialBlendMultiply=x;exports.setMaterialBlendNormal=B;exports.setMaterialBlendScreen=E;exports.supportsOffscreenCanvas=b;exports.triangle=c;exports.updateCameraOrtho=F;exports.updateCameraOrtho16x9=y;exports.useMask=w;