UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 5.98 kB
import{isSome as e,isNone as t,unwrap as s,unwrapOr as i}from"../../../../core/maybe.js";import{c as a,m as n,a as r}from"../../../../chunks/vec3.js";import{c as o}from"../../../../chunks/vec3f64.js";import{setMin as c,setMax as h,create as l,isPoint as g,empty as d,center as b,offset as u}from"../../../../geometry/support/aaBoundingBox.js";import{g as j}from"../../../../chunks/sphere.js";import{evaluateElevationInfoAtPoint as O}from"./elevationAlignmentUtils.js";import{setContextFeature as m}from"./featureExpressionInfoUtils.js";import{demResolutionForBoundingBox as p}from"./graphicUtils.js";import{Object3DState as _}from"../../webgl-engine/lib/basicInterfaces.js";import{Transparency as v}from"../../webgl-engine/lib/edgeRendering/interfaces.js";class f{constructor(e,t,s){this.baseMaterial=e,this.edgeMaterials=t,this.properties=s}}class S{get isElevationSource(){return!(!this.stageObject.metadata||!this.stageObject.metadata.isElevationSource)}constructor(e,t,s,i,a,n,r,o=null){this.graphics3DSymbolLayer=e,this.stageObject=t,this._uniqueGeometries=s,this._uniqueMaterials=i,this._sharedResource=a,this.elevationAligner=n,this.elevationContext=r,this._edgeState=o,this.type="object3d",this._stageLayer=null,this._stage=null,this._visible=!1,this._addedToStage=!1,this.alignedSampledElevation=0,this.needsElevationUpdates=!1,this.useObjectOriginAsAttachmentOrigin=!1}initialize(e,t){this._stageLayer=t,this._stage=e,e.addMany(this._uniqueMaterials),e.addMany(this._uniqueGeometries),e.add(this.stageObject)}destroy(){const t=this._stage;this._stageLayer&&(t.removeMany(this._uniqueMaterials),t.removeMany(this._uniqueGeometries)),t.remove(this.stageObject),this._addedToStage&&(this._stageLayer.remove(this.stageObject),this._addedToStage=!1);const s=this._stage.renderer.ensureEdgeView();s.hasObject(this.stageObject)&&s.removeObject(this.stageObject),this.stageObject.dispose(),e(this._sharedResource)&&this._sharedResource.release(),this._visible=!1,this._stageLayer=null,this._stage=null}layerOpacityChanged(e,s){if(t(this._edgeState))return;const i=E(this._edgeState.baseMaterial);let a=!1;for(const t of this._edgeState.edgeMaterials)t.objectTransparency!==i&&(t.objectTransparency=i,a=!0);a&&this._resetEdgeObject(s);this._stage.renderer.ensureEdgeView().updateAllComponentOpacities(this.stageObject,[e])}slicePlaneEnabledChanged(e,s){if(t(this._edgeState))return;this._stage.renderer.ensureEdgeView().updateAllComponentMaterials(this.stageObject,this._edgeState.edgeMaterials,{hasSlicePlane:e},!s),this._edgeState.properties.hasSlicePlane=e}setVisibility(t){if(null!=this._stage&&this._visible!==t&&(this._visible=t,this.stageObject.visible=t,this._visible&&!this._addedToStage&&(this._stageLayer.add(this.stageObject),this._addedToStage=!0),e(this._edgeState))){const e=this._stage.renderer.ensureEdgeView();e.hasObject(this.stageObject)?e.updateObjectVisibility(this.stageObject,t):t&&this._addOrUpdateEdgeObject(e,!1)}}get visible(){return this._visible}alignWithElevation(t,i,a,n){if(null==this.elevationAligner)return;e(a)&&m(this.elevationContext.featureExpressionInfoContext,a);const r=(e,s)=>O(e,t,this.elevationContext,i,s);this.alignedSampledElevation=this.elevationAligner(this,this.elevationContext,s(t.spatialReference),r,i),this._resetEdgeObject(n)}alignWithAbsoluteElevation(e,t,s){const i=(t,s)=>{s.sampledElevation=e,s.verticalDistanceToGround=0,s.z=e};this.alignedSampledElevation=this.elevationAligner(this,this.elevationContext,null,i,t),this._resetEdgeObject(s)}getCenterObjectSpace(e=o()){return a(e,j(this.stageObject.boundingVolumeObjectSpace.bounds))}getBoundingBoxObjectSpace(e=l()){const t=this.stageObject.boundingVolumeObjectSpace;return c(e,t.min),h(e,t.max),e}computeAttachmentOrigin(e){if(this.useObjectOriginAsAttachmentOrigin){const t=this.stageObject.transformation;e.render.origin[0]+=t[12],e.render.origin[1]+=t[13],e.render.origin[2]+=t[14],e.render.num++}else for(const t of this.stageObject.geometries)t.computeAttachmentOrigin(x)&&(n(x,x,this.stageObject.transformation),r(e.render.origin,e.render.origin,x),e.render.num++)}async getProjectedBoundingBox(e,t,s,a,r){const o=this.getBoundingBoxObjectSpace(r),c=A,h=g(o)?1:c.length;for(let i=0;i<h;i++){const e=c[i];M[0]=o[e[0]],M[1]=o[e[1]],M[2]=o[e[2]],n(M,M,this.stageObject.transformation),y[3*i+0]=M[0],y[3*i+1]=M[1],y[3*i+2]=M[2]}if(!e(y,0,h))return null;d(o);let l=null;this.calculateRelativeScreenBounds&&(l=this.calculateRelativeScreenBounds());for(let i=0;i<3*h;i+=3){for(let e=0;e<3;e++)o[e]=Math.min(o[e],y[i+e]),o[e+3]=Math.max(o[e+3],y[i+e]);l&&s.push({location:y.slice(i,i+3),screenSpaceBoundingRect:l})}if(t&&t.service&&"absolute-height"!==this.elevationContext.mode){b(o,x);const e="relative-to-scene"===this.elevationContext.mode?"scene":"ground";let s=0;if(t.useViewElevation)s=i(t.service.getElevation(x[0],x[1],e),0);else try{const n=p(o,t.service.spatialReference,t);s=i(await t.service.queryElevation(x[0],x[1],a,n,e),0)}catch(j){}u(o,0,0,-this.alignedSampledElevation+s)}return o}addObjectState(e,t){e===_.Highlight&&t.addObject(this.stageObject,this.stageObject.highlight()),e===_.MaskOccludee&&t.addObject(this.stageObject,this.stageObject.maskOccludee())}removeObjectState(e){e.removeObject(this.stageObject)}_resetEdgeObject(e){if(t(this._edgeState))return;const s=this._stage.renderer.ensureEdgeView();this._visible?this._addOrUpdateEdgeObject(s,e):s.removeObject(this.stageObject)}_addOrUpdateEdgeObject(e,s){const i=this._edgeState;if(t(i))return;const a=E(i.baseMaterial);for(const t of i.edgeMaterials)t.objectTransparency=a;e.addOrUpdateObject3D(this.stageObject,i.edgeMaterials,i.properties,!s).then((()=>this._stageLayer?.sync()))}}function E(e){return e.isVisible()?e.parameters.transparent?v.TRANSPARENT:v.OPAQUE:v.INVISIBLE}const y=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],M=o(),x=o(),A=[[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{S as Graphics3DObject3DGraphicLayer,f as Object3DEdgeState};