cione-comp-lib
Version:
`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`
2 lines (1 loc) • 3.28 kB
JavaScript
;Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var e=require("../../../build/three.module.js");const t=new e.Vector3,n=new e.Quaternion,r=new e.Vector3;class s extends e.Object3D{constructor(e=document.createElement("div")){super(),this.element=e,this.element.style.position="absolute",this.element.style.pointerEvents="auto",this.element.style.userSelect="none",this.element.setAttribute("draggable",!1),this.addEventListener("removed",(function(){this.traverse((function(e){e.element instanceof Element&&null!==e.element.parentNode&&e.element.parentNode.removeChild(e.element)}))}))}copy(e,t){return super.copy(e,t),this.element=e.element.cloneNode(!0),this}}s.prototype.isCSS3DObject=!0;class o extends s{constructor(e){super(e),this.rotation2D=0}copy(e,t){return super.copy(e,t),this.rotation2D=e.rotation2D,this}}o.prototype.isCSS3DSprite=!0;const i=new e.Matrix4,l=new e.Matrix4;exports.CSS3DObject=s,exports.CSS3DRenderer=class{constructor(e={}){const s=this;let o,a,c,p;const m={camera:{fov:0,style:""},objects:new WeakMap},d=void 0!==e.element?e.element:document.createElement("div");d.style.overflow="hidden",this.domElement=d;const u=document.createElement("div");function h(e){return Math.abs(e)<1e-10?0:e}function y(e){const t=e.elements;return"matrix3d("+h(t[0])+","+h(-t[1])+","+h(t[2])+","+h(t[3])+","+h(t[4])+","+h(-t[5])+","+h(t[6])+","+h(t[7])+","+h(t[8])+","+h(-t[9])+","+h(t[10])+","+h(t[11])+","+h(t[12])+","+h(-t[13])+","+h(t[14])+","+h(t[15])+")"}function x(e){const t=e.elements;return"translate(-50%,-50%)"+("matrix3d("+h(t[0])+","+h(t[1])+","+h(t[2])+","+h(t[3])+","+h(-t[4])+","+h(-t[5])+","+h(-t[6])+","+h(-t[7])+","+h(t[8])+","+h(t[9])+","+h(t[10])+","+h(t[11])+","+h(t[12])+","+h(t[13])+","+h(t[14])+","+h(t[15])+")")}function v(e,o,a,c){if(e.isCSS3DObject){let c;e.onBeforeRender(s,o,a),e.isCSS3DSprite?(i.copy(a.matrixWorldInverse),i.transpose(),0!==e.rotation2D&&i.multiply(l.makeRotationZ(e.rotation2D)),e.matrixWorld.decompose(t,n,r),i.setPosition(t),i.scale(r),i.elements[3]=0,i.elements[7]=0,i.elements[11]=0,i.elements[15]=1,c=x(i)):c=x(e.matrixWorld);const p=e.element,d=m.objects.get(e);if(void 0===d||d.style!==c){p.style.transform=c;const t={style:c};m.objects.set(e,t)}p.style.display=e.visible?"":"none",p.parentNode!==u&&u.appendChild(p),e.onAfterRender(s,o,a)}for(let t=0,n=e.children.length;t<n;t++)v(e.children[t],o,a)}u.style.transformStyle="preserve-3d",u.style.pointerEvents="none",d.appendChild(u),this.getSize=function(){return{width:o,height:a}},this.render=function(e,t){const n=t.projectionMatrix.elements[5]*p;let r,s;m.camera.fov!==n&&(d.style.perspective=t.isPerspectiveCamera?n+"px":"",m.camera.fov=n),!0===e.autoUpdate&&e.updateMatrixWorld(),null===t.parent&&t.updateMatrixWorld(),t.isOrthographicCamera&&(r=-(t.right+t.left)/2,s=(t.top+t.bottom)/2);const o=(t.isOrthographicCamera?"scale("+n+")translate("+h(r)+"px,"+h(s)+"px)"+y(t.matrixWorldInverse):"translateZ("+n+"px)"+y(t.matrixWorldInverse))+"translate("+c+"px,"+p+"px)";m.camera.style!==o&&(u.style.transform=o,m.camera.style=o),v(e,e,t)},this.setSize=function(e,t){o=e,a=t,c=o/2,p=a/2,d.style.width=e+"px",d.style.height=t+"px",u.style.width=e+"px",u.style.height=t+"px"}}},exports.CSS3DSprite=o;