/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{GeometryCursor as e}from"../../../../../../../geometry/GeometryCursor.js";import{loadGeometryOperatorsForEffect as t}from"../../../../../../../symbols/cim/CIMEffects.js";import{CIMEffectHelper as r}from"../../../../../../../symbols/cim/effects/CIMEffectHelper.js";import{MeshWriterVertexPack as s}from"./MeshWriterVertexPack.js";class a{constructor(e,t,r,s){this._instanceId=e,this._evaluator=t,this._enabledOptionalAttributes=r,this._viewParams=s,this._evaluator.evaluator=e=>this.vertexSpec.createComputedParams(e)}get _vertexPack(){if(!this._cachedVertexPack){const e=s.fromVertexSpec(this.vertexSpec,this._enabledOptionalAttributes);this._evaluator.hasDynamicProperties||e.pack(this._evaluator.evaluatedMeshParams,this._viewParams),this._cachedVertexPack=e}return this._cachedVertexPack}get evaluatedMeshParams(){return this._evaluator.evaluatedMeshParams}get hasEffects(){return!!this.evaluatedMeshParams.effects}get effectInfos(){return this._evaluator.inputMeshParams.effects?.effectInfos}get instanceId(){return this._instanceId}get attributeLayout(){return this._vertexPack.attributeLayout}get _preventEffectClipping(){return!1}setReferences(e){this._references=e}getBoundsInfo(){return null}getTileInfo(){return this._viewParams.tileInfo}async loadDependencies(){for(const{effect:e}of this.effectInfos||[])await t(e)}enqueueRequest(e,t,r){this._evaluator.hasDynamicProperties&&this._evaluator.enqueueRequest(e,t,r)}write(e,t,r,s,a){this.ensurePacked(t,r,s);const i=this.evaluatedMeshParams.effects;if(!i||0===i.length)return void this._write(e,r,void 0,a);const n=this.getEffectCursor(e,r,i);if(!n)return;let c;for(;c=n.next();)c.invertY(),this._write(e,r,c,a)}ensurePacked(e,t,r){if(!this._evaluator.hasDynamicProperties)return;const s=this._evaluator.evaluateMeshParams(e,t,r);this._vertexPack.pack(s,this._viewParams)}hasArcadeDependency(e){return this._evaluator.hasArcadeDependency(e)}_writeVertex(e,t,r,s,a){const i=this.evaluatedMeshParams;this._vertexPack.writeVertex(e,t,r,s,i,a)}getEffectCursor(t,s,a){const i=s.readGeometryForDisplay()?.clone();if(!i)return;const n=e.fromOptimizedCIM(i,s.geometryType);n.invertY();const c=t.id||"";return r.executeEffects(a,n,c,this._preventEffectClipping)}}export{a as MeshWriter};
