/*
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/maybe","../../../../core/reactiveUtils","../../../../chunks/mat4","../../../../chunks/mat4f64","../../../../chunks/vec3","../../../../chunks/vec3f64","../../../../chunks/vec4","../../../../chunks/vec4f32","../../../../geometry/support/vectorStacks","./Object3DVisualElement","../../webgl-engine/lib/Geometry","../../webgl-engine/lib/GeometryUtil","../../webgl-engine/lib/Material","../../webgl-engine/lib/VertexAttribute","../../webgl-engine/materials/ColorMaterial","../../webgl-engine/materials/RibbonLineMaterial"],(function(e,t,i,r,a,n,s,l,o,u,c,d,h,_,m,f,p,g,M){"use strict";let y=function(e){function s(t){var r;return(r=e.call(this,t)||this)._handles=new i,r._quadMaterial=null,r._outlineMaterial=null,r._maxSize=0,r._position=o.create(),r._up=o.create(),r._right=o.create(),r._renderOccluded=f.RenderOccludedFlag.OccludeAndTransparent,r._color=c.fromValues(1,0,0,1),r._outlineColor=c.fromValues(0,0,0,1),r._outlineSize=0,r._size=32,r._outlineRenderOccluded=f.RenderOccludedFlag.Opaque,r.applyProps(t),r}t._inheritsLoose(s,e);var h=s.prototype;return h.createExternalResources=function(){this._quadMaterial=new g.ColorMaterial(this.quadMaterialParameters),this._outlineMaterial=new M.RibbonLineMaterial(this.outlineMaterialParameters),this._handles.add(a.watch((()=>this.view.state.camera),(()=>this._updateTransform())))},h.destroyExternalResources=function(){this._quadMaterial=null,this._outlineMaterial=null,this._handles.removeAll()},h.forEachExternalMaterial=function(e){e(this._quadMaterial),e(this._outlineMaterial)},h.createGeometries=function(e){this._createQuadGeometry(e),this._createOutlineGeometry(e),this._updateTransform(e)},h._createQuadGeometry=function(e){const t=this._quadGeometryData(this._up,this._right);e.addGeometry(t,this._quadMaterial)},h._createOutlineGeometry=function(e){if(0===this._outlineSize)return;const t=l.add(d.sv3d.get(),this._up,this._right),i=m.createPolylineGeometry([this._up,t,this._right]);e.addGeometry(i,this._outlineMaterial)},h._updateTransform=function(e=this.object){const t=this.view.state.camera,i=this._size*t.computeScreenPixelSizeAt(this._position),a=Math.min(this._maxSize,i);n.fromTranslation(O,this._position),n.scale(O,O,[a,a,a]),r.isSome(e)&&(e.transformation=O)},h._quadGeometryData=function(e,t){const i=l.add(d.sv3d.get(),e,t);return new _.Geometry([[p.VertexAttribute.POSITION,{size:3,data:[0,0,0,...t,...e,...i],exclusive:!0}]],[[p.VertexAttribute.POSITION,new Uint16Array([0,1,2,1,2,3])]])},h._updateQuadMaterial=function(){this._quadMaterial&&this._quadMaterial.setParameters(this.quadMaterialParameters)},h._updateOutlineMaterial=function(){this._outlineMaterial&&this._outlineMaterial.setParameters(this.outlineMaterialParameters)},t._createClass(s,[{key:"renderOccluded",get:function(){return this._renderOccluded},set:function(e){e!==this._renderOccluded&&(this._renderOccluded=e,this._updateQuadMaterial())}},{key:"color",get:function(){return this._color},set:function(e){u.copy(this._color,e),this._updateQuadMaterial()}},{key:"outlineColor",get:function(){return this._outlineColor},set:function(e){u.copy(this._outlineColor,e),this._updateOutlineMaterial()}},{key:"outlineSize",get:function(){return this._outlineSize},set:function(e){const t=0===this._outlineSize!=(0===e);this._outlineSize=e,t?this.recreateGeometry():this._updateOutlineMaterial()}},{key:"size",get:function(){return this._size},set:function(e){e!==this._size&&(this._size=e,this._updateTransform())}},{key:"outlineRenderOccluded",get:function(){return this._outlineRenderOccluded},set:function(e){this._outlineRenderOccluded=e,this._updateOutlineMaterial()}},{key:"geometry",set:function({previous:e,center:t,next:i}){this._maxSize=Math.min(l.distance(t,e),l.distance(t,i))/3,l.normalize(this._up,l.subtract(this._up,e,t)),l.normalize(this._right,l.subtract(this._right,i,t)),l.copy(this._position,t),this.recreateGeometry()}},{key:"quadMaterialParameters",get:function(){return{color:this._color,transparent:!0,writeDepth:!1,polygonOffset:!0,renderOccluded:this._renderOccluded}}},{key:"outlineMaterialParameters",get:function(){return{color:this._outlineColor,width:this._outlineSize,renderOccluded:this._outlineRenderOccluded}}}]),s}(h.Object3DVisualElement);const O=s.create();e.RightAngleQuadVisualElement=y,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
