/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{__decorate as e}from"tslib";import{JSONSupport as t}from"../../core/JSONSupport.js";import{clone as r}from"../../core/lang.js";import o from"../../core/Warning.js";import{property as s,subclass as i}from"../../core/accessorSupport/decorators.js";import{persistable as a}from"../../core/accessorSupport/decorators/persistable.js";import n from"../../geometry/Polygon.js";import{canProjectWithoutEngine as p,projectPolygon as c}from"../../geometry/projectionUtils.js";import l from"../../geometry/SpatialReference.js";import{equals as m}from"../../geometry/support/spatialReferenceUtils.js";import{default3DTilesSpatialReference as f}from"./tiles3DUtils.js";import{isInitialized as y,switchMeshModificationPolygonVCSSync as d}from"../../views/3d/layers/Lyr3DWorker.js";import{toWasmModification as u,fromWasmModification as g}from"../../views/3d/layers/SceneLayerWorkerHandle.js";import{writer as S}from"../../core/accessorSupport/decorators/writer.js";var h;let R=h=class extends t{constructor(e){super(e),this.geometry=null,this.type="clip"}writeGeometry(e,t,r,s){if(this._needWGS84Conversion(s))this._doWGS84Conversion(t,r,s);else if(s.layer?.spatialReference&&!s.layer.spatialReference.equals(this.geometry.spatialReference)){if(!p(e.spatialReference,s.layer.spatialReference))return void(s?.messages&&s.messages.push(new o("scenemodification:unsupported","Scene modifications with incompatible spatial references are not supported",{modification:this,spatialReference:s.layer.spatialReference,context:s})));const i=new n;c(e,i,s.layer.spatialReference),t[r]=i.toJSON(s)}else t[r]=e.toJSON(s)}_needWGS84Conversion(e){if("integrated-mesh-3dtiles"===e.layer?.type){const t=e.layer;return!t.esriCrsSpatialReference||!m(t.esriCrsSpatialReference,this.geometry.spatialReference)}return!1}_doWGS84Conversion(e,t,r){let s=!0;if(y()){const o=u(null,[this],l.WGS84);if(o.length>1){const i=d({modifications:o,inVCS:5773});if(i.success&&i.modifications){const o=[this.clone()];g(i.modifications,o),1===o.length&&o[0].geometry&&(o[0].geometry.spatialReference=f,e[t]=o[0].geometry.toJSON(r),s=!1)}}}s&&r?.messages&&r.messages.push(new o("scenemodification:unsupported","Scene modifications with incompatible spatial references are not supported",{modification:this,spatialReference:this.geometry.spatialReference,context:r}))}clone(){return new h({geometry:r(this.geometry),type:this.type})}};e([s({type:n}),a()],R.prototype,"geometry",void 0),e([S(["web-scene","portal-item"],"geometry")],R.prototype,"writeGeometry",null),e([s({type:["clip","mask","replace"],nonNullable:!0}),a()],R.prototype,"type",void 0),R=h=e([i("esri.layers.support.SceneModification")],R);export{R as default};
