/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../chunks/_rollupPluginBabelHelpers","../../../../core/Handles","../../../../core/mathUtils","../../../../core/maybe","../../../../core/reactiveUtils","../../../../chunks/mat4f64","../../../../chunks/vec3","../../../../chunks/vec3f64","../../../../chunks/vec4f64","../../../../geometry/support/vectorStacks","./Object3DVisualElement","../../webgl-engine/lib/GeometryUtil","../../webgl-engine/lib/Material","../../webgl-engine/materials/MeasurementArrowMaterial"],(function(e,t,r,i,a,s,o,n,l,c,h,d,p,u,_){"use strict";let w=function(e){function c(t){var r;return(r=e.call(this,t)||this)._parameters=y,r._handles=null,r._origin=l.create(),r._originTransform=o.create(),r._arrowCenter=l.create(),r._renderOccluded=u.RenderOccludedFlag.OccludeAndTransparent,r._geometry=null,r._stripeLength=1,r._stripesEnabled=!0,r._opacity=1,r.applyProps(t),r}t._inheritsLoose(c,e);var d=c.prototype;return d.createExternalResources=function(){const{arrowStripeEvenColor:e,arrowStripeOddColor:t,arrowOutlineColor:i}=this._parameters,a=this._stripesEnabled?e:t;this._arrowMaterial=new _.MeasurementArrowMaterial({outlineColor:i,stripeEvenColor:a,stripeOddColor:t,renderOccluded:this.renderOccluded,polygonOffset:!0}),this._handles=new r,this._handles.add(s.watch((()=>this.view.state.camera),(()=>{this._viewChanged()})))},d.destroyExternalResources=function(){this._arrowMaterial=null,this._handles.destroy(),this._handles=null},d.forEachExternalMaterial=function(e){e(this._arrowMaterial)},d.createGeometries=function(e){if(a.isNone(this._geometry)||a.isNone(this._geometry.startRenderSpace)||a.isNone(this._geometry.endRenderSpace))return;const t=this._createArrowGeometry(this._geometry.startRenderSpace,this._geometry.endRenderSpace,this._origin,this._geometry);e.addGeometry(t,this._arrowMaterial,this._originTransform),this._viewChanged()},d._createArrowGeometry=function(e,t,r,i){const a=this.view.renderCoordsHelper,s=[],o=[],l=(e,t)=>{const i=h.sv3d.get();n.subtract(i,e,r),s.push(i),o.push(t)};if("euclidean"===i.type){i.eval(.5,this._arrowCenter);const r=h.sv3d.get();a.worldUpAtPosition(this._arrowCenter,r),l(e,r),l(t,r)}else{i.eval(.5,this._arrowCenter);const e=this._parameters.arrowSubdivisions+1&-2;for(let t=0;t<e;++t){const r=t/(e-1),s=h.sv3d.get(),o=h.sv3d.get();i.eval(r,s),a.worldUpAtPosition(s,o),l(s,o)}}return p.createPolylineGeometry(s,o)},d._geometryChanged=function(){this.recreateGeometry()},d._viewChanged=function(){if(this.view.ready&&this.attached&&a.isSome(this._geometry)){const e=this.view.state.camera.computeScreenPixelSizeAt(this._arrowCenter);this._arrowMaterial.setParameters({width:this._parameters.arrowWidth*e})}},d._updateArrowOpacity=function(){const e=this.opacity,{arrowStripeEvenColor:t,arrowStripeOddColor:r,arrowOutlineColor:a}=this._parameters,s=i.applyOpacity(g,this._stripesEnabled?t:r,e),o=i.applyOpacity(m,a,e),n=i.applyOpacity(f,r,e);this._arrowMaterial.setParameters({stripeEvenColor:s,outlineColor:o,stripeOddColor:n})},t._createClass(c,[{key:"renderOccluded",get:function(){return this._renderOccluded},set:function(e){e!==this._renderOccluded&&(this._renderOccluded=e,this._arrowMaterial&&this._arrowMaterial.setParameters({renderOccluded:e}))}},{key:"geometry",get:function(){return this._geometry},set:function(e){this._geometry=e,this._geometryChanged()}},{key:"stripeLength",get:function(){return this._stripeLength},set:function(e){this._stripeLength=e,this.attached&&this._arrowMaterial.setParameters({stripeLength:this._stripeLength})}},{key:"stripesEnabled",get:function(){return this._stripesEnabled},set:function(e){if(this._stripesEnabled=e,this.attached){const e=this.opacity,{arrowStripeEvenColor:t,arrowStripeOddColor:r}=this._parameters,a=i.applyOpacity(g,this._stripesEnabled?t:r,e);this._arrowMaterial.setParameters({stripeEvenColor:a})}}},{key:"opacity",get:function(){return this._opacity},set:function(e){e!==this._opacity&&(this._opacity=e,this._updateArrowOpacity())}}]),c}(d.Object3DVisualElement);const y={arrowWidth:16,arrowOutlineColor:[1,.5,0,1],arrowOutlineWidth:.2,arrowStripeEvenColor:[1,1,1,1],arrowStripeOddColor:[1,.5,0,1],arrowStripeLength:16,arrowSubdivisions:128},g=c.create(),m=c.create(),f=c.create();e.MeasurementArrowVisualElement=w,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
