@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 5.68 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{transformMat4 as e,add as t}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as i}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{setMin as s,setMax as a,create as n,isPoint as r,empty as l,center as g,offset as c}from"../../../../geometry/support/aaBoundingBox.js";import{evaluateElevationInfoAtPoint as o}from"./elevationAlignmentUtils.js";import{demResolutionForBoundingBox as h}from"./graphicUtils.js";class d{constructor(e,t,i){this.baseMaterial=e,this.edgeMaterial=t,this.hasSlicePlane=i}}class b{_getFlag(e){return(this._flags&e)===e}_setFlag(e,t){t?this._flags|=e:this._flags&=~e}get needsElevationUpdates(){return this._getFlag(2)}set needsElevationUpdates(e){this._setFlag(2,e)}get useObjectOriginAsAttachmentOrigin(){return this._getFlag(4)}set useObjectOriginAsAttachmentOrigin(e){this._setFlag(4,e)}get hiddenIfDeconflicted(){return this._getFlag(8)}set hiddenIfDeconflicted(e){this._setFlag(8,e)}get isElevationSource(){return!!this.stageObject.lastValidElevationBB}constructor(e,t,i,s,a,n=null){this.graphics3DSymbolLayer=e,this.stageObject=t,this._sharedResource=i,this.elevationAligner=s,this.elevationContext=a,this._edgeState=n,this.type="object3d",this._stageLayer=null,this._flags=0,this.alignedSampledElevation=0}initialize(e){this._stageLayer=e,this.hiddenIfDeconflicted&&(e.add(this.stageObject),this._setFlag(1,!0))}destroy(){if(!this._stageLayer)return;const e=this._stageLayer.stage;this._getFlag(1)&&(this._stageLayer.remove(this.stageObject),this._setFlag(1,!1)),e.renderer.edgeView?.removeObject(this.stageObject),this.stageObject.dispose(),this._sharedResource?.release(),this._stageLayer=null}get usedMemory(){return this.graphics3DSymbolLayer.usedMemory}layerOpacityChanged(e,t){const{stageObject:i,_edgeState:s,_stageLayer:a}=this;if(null==s)return;const n=u(s.baseMaterial);s.edgeMaterial.objectTransparency!==n&&(s.edgeMaterial.objectTransparency=n,this.resetEdgeObject(t)),a.stage.renderer.withEdgeView(t=>t.updateAllComponentOpacities(i,[e]))}updateMaterial(e){this.stageObject.geometries.map(t=>t.instantiate({material:e})).forEach(e=>{this.stageObject.addGeometry(e),this.stageObject.removeGeometry(0)})}updateHighlights(e){}slicePlaneEnabledChanged(e,t){const{stageObject:i,_edgeState:s,_stageLayer:a}=this;null!=s&&a.stage.renderer.withEdgeView(a=>{a.updateAllComponentMaterials(i,s.edgeMaterial,e,!t),s.hasSlicePlane=e})}setVisibility(e){const{_edgeState:t,stageObject:i,_stageLayer:s}=this;null!=s&&this.visible!==e&&(i.visible=e,e&&!this._getFlag(1)&&(s.add(i),this._setFlag(1,!0)),null!=t&&s.stage.renderer.withEdgeView(s=>{s.hasObject(i)?s.updateObjectVisibility(i,e):e&&this._addOrUpdateEdgeObject(t,s,!1)}))}get visible(){return this._getFlag(1)&&this.stageObject.visible}alignWithElevation(e,t,i){if(null==this.elevationAligner)return;const s=(i,s)=>o(i,e,this.elevationContext,t,s);this.alignedSampledElevation=this.elevationAligner(this,this.elevationContext,e.spatialReference,s,t),this.resetEdgeObject(i)}alignWithAbsoluteElevation(e,t,i){const s=(t,i)=>{i.sampledElevation=e,i.verticalDistanceToGround=0,i.z=e};this.alignedSampledElevation=this.elevationAligner(this,this.elevationContext,this.graphics3DSymbolLayer.view.spatialReference,s,t),this.resetEdgeObject(i)}getCenterObjectSpace(){return this.stageObject.boundingVolumeObjectSpace.bounds.center}getBoundingBoxObjectSpace(e=n()){const t=this.stageObject.boundingVolumeObjectSpace;return s(e,t.min),a(e,t.max),e}computeAttachmentOrigin(i){const s=this.stageObject.effectiveTransformation;if(this.useObjectOriginAsAttachmentOrigin)i.render.origin[0]+=s[12],i.render.origin[1]+=s[13],i.render.origin[2]+=s[14],i.render.num++;else for(const a of this.stageObject.geometries)a.computeAttachmentOrigin(m)&&(e(m,m,s),t(i.render.origin,i.render.origin,m),i.render.num++)}async getProjectedBoundingBox(t,i,s,a,n){const o=this.getBoundingBoxObjectSpace(n),d=p,b=r(o)?1:d.length;for(let r=0;r<b;r++){const t=d[r];j[0]=o[t[0]],j[1]=o[t[1]],j[2]=o[t[2]],e(j,j,this.stageObject.transformation),O[3*r]=j[0],O[3*r+1]=j[1],O[3*r+2]=j[2]}if(!t(O,0,b))return null;l(o);let u=null;this.calculateRelativeScreenBounds&&(u=this.calculateRelativeScreenBounds());for(let e=0;e<3*b;e+=3){for(let t=0;t<3;t++)o[t]=Math.min(o[t],O[e+t]),o[t+3]=Math.max(o[t+3],O[e+t]);u&&s.push({location:O.slice(e,e+3),screenSpaceBoundingRect:u})}if(i?.service&&"absolute-height"!==this.elevationContext.mode){g(o,m);const e="relative-to-scene"===this.elevationContext.mode?"scene":"ground";let t=0;if(i.useViewElevation)t=i.service.getElevation(m[0],m[1],e)??0;else try{const s=h(o,i.service.spatialReference,i);t=await i.service.queryElevation(m[0],m[1],a,s,e)??0}catch(v){}c(o,0,0,-this.alignedSampledElevation+t)}return o}addObjectState(e){0===e.stateType&&e.addObject(this.stageObject,this.stageObject.highlight(e.highlightName)),1===e.stateType&&e.addObject(this.stageObject,this.stageObject.maskOccludee())}removeObjectState(e){e.removeByObject(this.stageObject)}resetEdgeObject(e){const{_edgeState:t,stageObject:i,_stageLayer:s,visible:a}=this;null!=t&&s.stage.renderer.withEdgeView(s=>{a?this._addOrUpdateEdgeObject(t,s,e):s.removeObject(i)})}_addOrUpdateEdgeObject(e,t,i){const s=u(e.baseMaterial);e.edgeMaterial.objectTransparency=s,t.addOrUpdateObject3D(this.stageObject,e.edgeMaterial,e.hasSlicePlane,!i).then(()=>this._stageLayer?.sync())}}function u(e){return e.transparent?0:1}const O=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],j=i(),m=i(),p=[[0,1,2],[3,1,2],[0,4,2],[3,4,2],[0,1,5],[3,1,5],[0,4,5],[3,4,5]];export{b as Graphics3DObject3DGraphicLayer,d as Object3DEdgeState};