@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 5.72 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */
import{normalFromMat4Legacy as t}from"../../../../core/libs/gl-matrix-2/math/mat3.js";import{create as s}from"../../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{invert as r,transpose as e,copy as i,multiply as o}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as a}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{set as n,transformMat4 as h,length as f,scaleAndAdd as m,add as l}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as p}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{Sphere as c}from"../../../../geometry/support/sphere.js";import{Obb as _,computeOffsetObb as u}from"../../support/orientedBoundingBox.js";class g{constructor(){this._transform=a(),this._transformInverse=new M({value:this._transform},r,a),this._transformInverseTranspose=new M(this._transformInverse,e,a),this._transformTranspose=new M({value:this._transform},e,a),this._transformInverseRotation=new M({value:this._transform},t,s)}_invalidateLazyTransforms(){this._transformInverse.invalidate(),this._transformInverseTranspose.invalidate(),this._transformTranspose.invalidate(),this._transformInverseRotation.invalidate()}get transform(){return this._transform}get inverse(){return this._transformInverse.value}get inverseTranspose(){return this._transformInverseTranspose.value}get inverseRotation(){return this._transformInverseRotation.value}get transpose(){return this._transformTranspose.value}setTransformMatrix(t){i(this._transform,t)}multiplyTransform(t){o(this._transform,this._transform,t)}set(t){i(this._transform,t),this._invalidateLazyTransforms()}setAndInvalidateLazyTransforms(t,s){this.setTransformMatrix(t),this.multiplyTransform(s),this._invalidateLazyTransforms()}}class M{constructor(t,s,r){this._original=t,this._update=s,this._dirty=!0,this._transform=r()}invalidate(){this._dirty=!0}get value(){return this._dirty&&(this._update(this._transform,this._original.value),this._dirty=!1),this._transform}}class v{constructor(t=0){this.offset=t,this.tmpVertex=p()}applyToVertex(t,s,r){const e=n(j,t,s,r),i=l(w,e,this.localOrigin),o=this.offset/f(i);return m(this.tmpVertex,e,i,o),this.tmpVertex}applyToAabb(t){const s=S,r=q,e=z;for(let n=0;n<3;++n)s[n]=t[0+n]+this.localOrigin[n],r[n]=t[3+n]+this.localOrigin[n],e[n]=s[n];const i=this.applyToVertex(s[0],s[1],s[2]);for(let n=0;n<3;++n)t[n]=i[n],t[n+3]=i[n];const o=s=>{const r=this.applyToVertex(s[0],s[1],s[2]);for(let e=0;e<3;++e)t[e]=Math.min(t[e],r[e]),t[e+3]=Math.max(t[e+3],r[e])};for(let n=1;n<8;++n){for(let t=0;t<3;++t)e[t]=n&1<<t?r[t]:s[t];o(e)}let a=0;for(let n=0;n<3;++n){s[n]*r[n]<0&&(a|=1<<n)}if(0!==a&&7!==a)for(let n=0;n<8;++n)if(0===(a&n)){for(let t=0;t<3;++t)e[t]=a&1<<t?0:n&1<<t?s[t]:r[t];o(e)}for(let n=0;n<3;++n)t[n]-=this.localOrigin[n],t[n+3]-=this.localOrigin[n];return t}}class b{constructor(t=0){this.componentLocalOriginLength=0,this._totalOffset=0,this._offset=0,this._tmpVertex=p(),this._tmpMbs=new c,this._tmpObb=new _,this._resetOffset(t)}_resetOffset(t){this._offset=t,this._totalOffset=t}set offset(t){this._resetOffset(t)}get offset(){return this._offset}set componentOffset(t){this._totalOffset=this._offset+t}set localOrigin(t){this.componentLocalOriginLength=f(t)}applyToVertex(t,s,r){const e=n(j,t,s,r),i=n(w,t,s,r+this.componentLocalOriginLength),o=this._totalOffset/f(i);return m(this._tmpVertex,e,i,o),this._tmpVertex}applyToAabb(t){const s=this.componentLocalOriginLength,r=t[0],e=t[1],i=t[2]+s,o=t[3],a=t[4],n=t[5]+s,h=Math.abs(r),f=Math.abs(e),m=Math.abs(i),l=Math.abs(o),p=Math.abs(a),c=Math.abs(n),_=.5*(1+Math.sign(r*o))*Math.min(h,l),u=.5*(1+Math.sign(e*a))*Math.min(f,p),g=.5*(1+Math.sign(i*n))*Math.min(m,c),M=Math.max(h,l),v=Math.max(f,p),b=Math.max(m,c),x=Math.sqrt(_*_+u*u+g*g),T=Math.sign(h+r),O=Math.sign(f+e),d=Math.sign(m+i),y=Math.sign(l+o),V=Math.sign(p+a),L=Math.sign(c+n),I=this._totalOffset;if(x<I)return t[0]-=(1-T)*I,t[1]-=(1-O)*I,t[2]-=(1-d)*I,t[3]+=y*I,t[4]+=V*I,t[5]+=L*I,t;const j=I/Math.sqrt(M*M+v*v+b*b),w=I/x,S=w-j,q=-S;return t[0]+=r*(T*q+w),t[1]+=e*(O*q+w),t[2]+=i*(d*q+w),t[3]+=o*(y*S+j),t[4]+=a*(V*S+j),t[5]+=n*(L*S+j),t}applyToMbs(t){const s=t.center,r=f(s),e=this._totalOffset/r;return m(this._tmpMbs.center,s,s,e),this._tmpMbs.radius=t.radius+t.radius*this._totalOffset/r,this._tmpMbs}applyToObb(t){return u(t,this._totalOffset,this._totalOffset,1,this._tmpObb),this._tmpObb}}class x{constructor(t=0){this.offset=t,this.tmpVertex=p(),this._tmpSphere=new c}applyToVertex(t,s,r){const e=this.objectTransform.transform,i=n(j,t,s,r),o=h(i,i,e),a=this.offset/f(o);m(o,o,o,a);const l=this.objectTransform.inverse;return h(this.tmpVertex,o,l),this.tmpVertex}applyToMinMax(t,s){const r=this.offset/f(t);m(t,t,t,r);const e=this.offset/f(s);m(s,s,s,e)}applyToAabb(t){const s=this.offset/Math.sqrt(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]);t[0]+=t[0]*s,t[1]+=t[1]*s,t[2]+=t[2]*s;const r=this.offset/Math.sqrt(t[3]*t[3]+t[4]*t[4]+t[5]*t[5]);return t[3]+=t[3]*r,t[4]+=t[4]*r,t[5]+=t[5]*r,t}applyToBoundingSphere(t){const s=t.center,r=f(s),e=this.offset/r;return m(this._tmpSphere.center,s,s,e),this._tmpSphere.radius=t.radius+t.radius*this.offset/r,this._tmpSphere}}const T=new x;function O(t){return null!=t?(T.offset=t,T):null}const d=new b;function y(t){return null!=t?(d.offset=t,d):null}const V=new v;function L(t){return null!=t?(V.offset=t,V):null}const I="terrain",j=p(),w=p(),S=p(),q=p(),z=p();export{b as I3SVerticalOffsetGlobalViewingMode,g as IntersectorTransform,x as Object3DVerticalOffsetGlobalViewingMode,v as TerrainVerticalOffsetGlobalViewingMode,y as getVerticalOffsetI3S,O as getVerticalOffsetObject3D,L as getVerticalOffsetTerrain,I as terrainId};