@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 6.06 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import"../../../../core/has.js";import{generateUID as t}from"../../../../core/uid.js";import{multiply as i,copy as e,hasIdentityRotation as s}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as o,IDENTITY as r}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{m as a,t as n,j as h,i as m,f as l,q as c,c as d}from"../../../../chunks/vec32.js";import{create as g,fromValues as u}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{a as f,c as _}from"../../../../chunks/sphere.js";import{maxScale as b}from"../../support/mathUtils.js";import{Object3DState as v}from"./basicInterfaces.js";import{Object3DOccludeeStateID as p,Object3DHighlightStateID as S}from"./Object3DStateID.js";import{assert as j}from"./Util.js";import{affectsGeometry as y}from"./VertexAttribute.js";import{addObject3DStateID as x,removeObject3DStateID as V}from"../materials/renderers/utils.js";class A{constructor(i={}){this.id=t(),this._highlightIds=new Set,this._shaderTransformation=null,this._visible=!0,this.castShadow=i.castShadow??!0,this.usesVerticalDistanceToGround=i.usesVerticalDistanceToGround??!1,this.graphicUid=i.graphicUid,this.layerViewUid=i.layerViewUid,i.isElevationSource&&(this.lastValidElevationBB=new M),this._geometries=i.geometries?Array.from(i.geometries):new Array}dispose(){this._geometries.length=0}get layer(){return this._layer}set layer(t){j(null==this._layer||null==t,"Object3D can only be added to a single Layer"),this._layer=t}addGeometry(t){t.visible=this._visible,this._geometries.push(t);for(const i of this._highlightIds)t.addHighlight(i);this._emit("geometryAdded",{object:this,geometry:t}),this._highlightIds.size&&this._emit("highlightChanged",this),this._invalidateBoundingVolume()}removeGeometry(t){const i=this._geometries.splice(t,1)[0];if(i){for(const t of this._highlightIds)i.removeHighlight(t);this._emit("geometryRemoved",{object:this,geometry:i}),this._highlightIds.size&&this._emit("highlightChanged",this),this._invalidateBoundingVolume()}}removeAllGeometries(){for(;this._geometries.length>0;)this.removeGeometry(0)}geometryVertexAttributeUpdated(t,i,e=!1){this._emit("attributesChanged",{object:this,geometry:t,attribute:i,sync:e}),y(i)&&this._invalidateBoundingVolume()}get visible(){return this._visible}set visible(t){if(this._visible!==t){this._visible=t;for(const t of this._geometries)t.visible=this._visible;this._emit("visibilityChanged",this)}}maskOccludee(){const t=new p;for(const i of this._geometries)i.occludees=x(i.occludees,t);return this._emit("occlusionChanged",this),t}removeOcclude(t){for(const i of this._geometries)i.occludees=V(i.occludees,t);this._emit("occlusionChanged",this)}highlight(t){const i=new S(t);for(const e of this._geometries)e.addHighlight(i);return this._emit("highlightChanged",this),this._highlightIds.add(i),i}removeHighlight(t){this._highlightIds.delete(t);for(const i of this._geometries)i.removeHighlight(t);this._emit("highlightChanged",this)}removeStateID(t){t.channel===v.Highlight?this.removeHighlight(t):this.removeOcclude(t)}getCombinedStaticTransformation(t,e){return i(e,this.transformation,t.transformation)}getCombinedShaderTransformation(t,e=o()){return i(e,this.effectiveTransformation,t.transformation)}get boundingVolumeWorldSpace(){return this._bvWorldSpace||(this._bvWorldSpace=this._bvWorldSpace||new O,this._validateBoundingVolume(this._bvWorldSpace,w.WorldSpace)),this._bvWorldSpace}get boundingVolumeObjectSpace(){return this._bvObjectSpace||(this._bvObjectSpace=this._bvObjectSpace||new O,this._validateBoundingVolume(this._bvObjectSpace,w.ObjectSpace)),this._bvObjectSpace}_validateBoundingVolume(t,i){const e=i===w.ObjectSpace;for(const s of this._geometries){const i=s.boundingInfo;i&&T(i,t,e?s.transformation:this.getCombinedShaderTransformation(s))}a(f(t.bounds),t.min,t.max,.5);for(const s of this._geometries){const i=s.boundingInfo;if(null==i)continue;const o=e?s.transformation:this.getCombinedShaderTransformation(s),r=b(o);n(I,i.center,o);const a=h(I,f(t.bounds)),m=i.radius*r;t.bounds[3]=Math.max(t.bounds[3],a+m)}}_invalidateBoundingVolume(){const t=this._bvWorldSpace?.bounds;this._bvObjectSpace=this._bvWorldSpace=void 0,this.layer&&t&&this.layer.notifyObjectBBChanged(this,t)}_emit(t,i){this.layer?.events.emit(t,i)}get geometries(){return this._geometries}get transformation(){return this._transformation??r}set transformation(t){this._transformation=e(this._transformation??o(),t),this._invalidateBoundingVolume(),this._emit("transformationChanged",this)}get shaderTransformation(){return this._shaderTransformation}set shaderTransformation(t){this._shaderTransformation=t?e(this._shaderTransformation??o(),t):null,this._invalidateBoundingVolume(),this._emit("shaderTransformationChanged",this)}get effectiveTransformation(){return this.shaderTransformation??this.transformation}get test(){}}class M{constructor(){this.min=u(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this.max=u(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE)}isEmpty(){return this.max[0]<this.min[0]&&this.max[1]<this.min[1]&&this.max[2]<this.min[2]}}class O extends M{constructor(){super(...arguments),this.bounds=_()}}function T(t,i,e){const o=t.bbMin,r=t.bbMax;if(s(e)){const t=m(C,e[12],e[13],e[14]);l(B,o,t),l(U,r,t);for(let e=0;e<3;++e)i.min[e]=Math.min(i.min[e],B[e]),i.max[e]=Math.max(i.max[e],U[e])}else if(n(B,o,e),c(o,r))for(let s=0;s<3;++s)i.min[s]=Math.min(i.min[s],B[s]),i.max[s]=Math.max(i.max[s],B[s]);else{n(U,r,e);for(let t=0;t<3;++t)i.min[t]=Math.min(i.min[t],B[t],U[t]),i.max[t]=Math.max(i.max[t],B[t],U[t]);for(let t=0;t<3;++t){d(B,o),d(U,r),B[t]=r[t],U[t]=o[t],n(B,B,e),n(U,U,e);for(let t=0;t<3;++t)i.min[t]=Math.min(i.min[t],B[t],U[t]),i.max[t]=Math.max(i.max[t],B[t],U[t])}}}const C=g(),B=g(),U=g(),I=g();var w;!function(t){t[t.WorldSpace=0]="WorldSpace",t[t.ObjectSpace=1]="ObjectSpace"}(w||(w={}));export{O as BoundingVolume,A as Object3D};