UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 5.75 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ 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 a}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as o}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{i as n,t as h,l as f,b as l,f as m}from"../../../../chunks/vec32.js";import{create as p}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{c,a as _}from"../../../../chunks/sphere.js";import{ViewingMode as u}from"../../../ViewingMode.js";import{Obb as g,computeOffsetObb as M}from"../../support/orientedBoundingBox.js";class b{constructor(){this._transform=o(),this._transformInverse=new v({value:this._transform},r,o),this._transformInverseTranspose=new v(this._transformInverse,e,o),this._transformTranspose=new v({value:this._transform},e,o),this._transformInverseRotation=new v({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){a(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 v{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 T{constructor(t=0){this.offset=t,this.tmpVertex=p()}applyToVertex(t,s,r){const e=n(q,t,s,r),i=m(z,e,this.localOrigin),a=this.offset/f(i);return l(this.tmpVertex,e,i,a),this.tmpVertex}applyToAabb(t){const s=A,r=R,e=B;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 a=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];a(e)}let o=0;for(let n=0;n<3;++n){s[n]*r[n]<0&&(o|=1<<n)}if(0!==o&&7!==o)for(let n=0;n<8;++n)if(0===(o&n)){for(let t=0;t<3;++t)e[t]=o&1<<t?0:n&1<<t?s[t]:r[t];a(e)}for(let n=0;n<3;++n)t[n]-=this.localOrigin[n],t[n+3]-=this.localOrigin[n];return t}}class x{constructor(t=0){this.componentLocalOriginLength=0,this._totalOffset=0,this._offset=0,this._tmpVertex=p(),this._tmpMbs=c(),this._tmpObb=new g,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(q,t,s,r),i=n(z,t,s,r+this.componentLocalOriginLength),a=this._totalOffset/f(i);return l(this._tmpVertex,e,i,a),this._tmpVertex}applyToAabb(t){const s=this.componentLocalOriginLength,r=t[0],e=t[1],i=t[2]+s,a=t[3],o=t[4],n=t[5]+s,h=Math.abs(r),f=Math.abs(e),l=Math.abs(i),m=Math.abs(a),p=Math.abs(o),c=Math.abs(n),_=.5*(1+Math.sign(r*a))*Math.min(h,m),u=.5*(1+Math.sign(e*o))*Math.min(f,p),g=.5*(1+Math.sign(i*n))*Math.min(l,c),M=Math.max(h,m),b=Math.max(f,p),v=Math.max(l,c),T=Math.sqrt(_*_+u*u+g*g),x=Math.sign(h+r),O=Math.sign(f+e),y=Math.sign(l+i),d=Math.sign(m+a),V=Math.sign(p+o),L=Math.sign(c+n),j=this._totalOffset;if(T<j)return t[0]-=(1-x)*j,t[1]-=(1-O)*j,t[2]-=(1-y)*j,t[3]+=d*j,t[4]+=V*j,t[5]+=L*j,t;const I=j/Math.sqrt(M*M+b*b+v*v),w=j/T,q=w-I,z=-q;return t[0]+=r*(x*z+w),t[1]+=e*(O*z+w),t[2]+=i*(y*z+w),t[3]+=a*(d*q+I),t[4]+=o*(V*q+I),t[5]+=n*(L*q+I),t}applyToMbs(t){const s=f(_(t)),r=this._totalOffset/s;return l(_(this._tmpMbs),_(t),_(t),r),this._tmpMbs[3]=t[3]+t[3]*this._totalOffset/s,this._tmpMbs}applyToObb(t){return M(t,this._totalOffset,this._totalOffset,u.Global,this._tmpObb),this._tmpObb}}class O{constructor(t=0){this.offset=t,this.sphere=c(),this.tmpVertex=p()}applyToVertex(t,s,r){const e=this.objectTransform.transform,i=n(q,t,s,r),a=h(i,i,e),o=this.offset/f(a);l(a,a,a,o);const m=this.objectTransform.inverse;return h(this.tmpVertex,a,m),this.tmpVertex}applyToMinMax(t,s){const r=this.offset/f(t);l(t,t,t,r);const e=this.offset/f(s);l(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=f(_(t)),r=this.offset/s;return l(_(this.sphere),_(t),_(t),r),this.sphere[3]=t[3]+t[3]*this.offset/s,this.sphere}}const y=new O;function d(t){return null!=t?(y.offset=t,y):null}const V=new x;function L(t){return null!=t?(V.offset=t,V):null}const j=new T;function I(t){return null!=t?(j.offset=t,j):null}const w="terrain",q=p(),z=p(),A=p(),R=p(),B=p();export{x as I3SVerticalOffsetGlobalViewingMode,b as IntersectorTransform,O as Object3DVerticalOffsetGlobalViewingMode,T as TerrainVerticalOffsetGlobalViewingMode,L as getVerticalOffsetI3S,d as getVerticalOffsetObject3D,I as getVerticalOffsetTerrain,w as terrainId};