UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 4.58 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{getTranslation as t,multiply as e,invert as a,copy as s,fromTranslation as r}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{IDENTITY as i,create as o}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{h as n}from"../../../../chunks/vec32.js";import{create as m}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{perObjectElevationAligner as l}from"./ElevationAligners.js";import{evaluateElevationInfoAtPoint as f}from"./elevationAlignmentUtils.js";import{setContextFeature as d}from"./featureExpressionInfoUtils.js";import{Graphics3DObject3DGraphicLayer as c}from"./Graphics3DObject3DGraphicLayer.js";import{meshAutoFastUpdateConstants as h}from"./meshAutoFastUpdateConstants.js";class p extends c{constructor(){super(...arguments),this.fastTransformUpdatesAllowed=!1,this._originalGeometries=[],this._fastTransformUpdatesEnabled=!1,this._autoDisableFastUpdatesTimeoutId=0}get fastTransformUpdatesEnabled(){return this._fastTransformUpdatesEnabled}destroy(){super.destroy(),this._cancelAutoDisableFastUpdates()}enableFastTransformUpdates(e,a){if(!this.fastTransformUpdatesAllowed||this._fastTransformUpdatesEnabled)return;this._cancelAutoDisableFastUpdates(),this._fastTransformUpdatesEnabled=!0;const{stageObject:s}=this,r=s.geometries.slice();s.removeAllGeometries();const i=t(g,s.transformation),o=a.getOrigin(i);for(const t of r){const a=e(t.material),r=t.instantiate({material:a});r.localOrigin=o,s.addGeometry(r)}this._originalGeometries=r}autoDisableFastTransformUpdates(t){this._cancelAutoDisableFastUpdates(),this._autoDisableFastUpdatesTimeoutId=setTimeout((()=>{this._autoDisableFastUpdatesTimeoutId=0,t()}),h.disableDelayMs)}updateAutoDisableFastTransformUpdates(t){this._autoDisableFastUpdatesTimeoutId&&this.autoDisableFastTransformUpdates(t)}_cancelAutoDisableFastUpdates(){clearTimeout(this._autoDisableFastUpdatesTimeoutId),this._autoDisableFastUpdatesTimeoutId=0}disableFastTransformUpdates(t){if(!this._fastTransformUpdatesEnabled)return;this._cancelAutoDisableFastUpdates(),this._fastTransformUpdatesEnabled=!1;const{stageObject:e}=this,a=e.geometries.map((e=>t(e.material)));e.removeAllGeometries();for(let s=0;s<this._originalGeometries.length;s++){const t=this._originalGeometries[s],r=a[s];r.setParameters({modelTransformation:null}),r===t.material?e.addGeometry(t):e.addGeometry(t.instantiate({material:r}))}this._originalGeometries.length=0}updateFastLocalOrigin(e,a,s){if(!this._fastTransformUpdatesEnabled)return;const{stageObject:r}=this;if(0===r.geometries.length)return;const o=r.geometries[0].localOrigin,n=t(g,e),m=s.getOrigin(n);if(m===o)return;const l=a?.localMatrix??i;r.shaderTransformation=null,r.transformation=e,r.geometries.forEach((t=>{t.transformation=l,t.localOrigin=m}))}updateTransform(t,s,r){const{stageObject:o}=this,n=s?.localMatrix??i;if(!this._fastTransformUpdatesEnabled)return o.shaderTransformation=null,o.transformation=t,o.geometries.forEach((t=>t.transformation=n)),void this._updateEdgeTransform(r);const m=o.transformation,l=o.geometries[0].transformation,f=t,d=n,c=e(u,m,l),h=e(T,f,d),p=e(_,h,a(_,l));o.shaderTransformation=p,this._setFastMaterialTransformation({matA:c,matB:h}),this._updateEdgeTransform(r)}alignWithElevation(t,a,r,i){if(!this._fastTransformUpdatesEnabled)return void super.alignWithElevation(t,a,r,i);null!=r&&d(this.elevationContext.featureExpressionInfoContext,r);const o=(e,s)=>f(e,t,this.elevationContext,a,s),{stageObject:n}=this;if(!n.geometries[0].material.parameters.modelTransformation)return;const m=n.transformation,c=n.geometries[0].transformation,h=e(u,m,c),p=n.effectiveTransformation,g=s(b,p);this.alignedSampledElevation=l(this,this.elevationContext,t.spatialReference,o,a,g),n.shaderTransformation=g;const _=n.geometries[0].transformation,U=e(T,g,_);this._setFastMaterialTransformation({matA:h,matB:U}),this._updateEdgeTransform(i)}_setFastMaterialTransformation({matA:t,matB:s}){const{stageObject:i}=this;if(0===i.geometries.length)return;const o=i.geometries[0].localOrigin,m=r(F,n(g,o.vec3,-1)),l=e(U,m,t),f=e(E,m,s),d=a(U,l),c=e(E,f,d);for(const e of i.geometries)e.material.setParameters({modelTransformation:c})}_updateEdgeTransform(t){const{stageObject:e,_stageLayer:a}=this;a.stage.renderer.withEdgeView((a=>{a.fastUpdateObject3DEdgesTransform(e)||this.resetEdgeObject(t)}))}}const g=m(),u=o(),T=o(),b=o(),_=o(),U=o(),E=o(),F=o();export{p as Graphics3DMeshObject3DGraphicLayer};