/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import t from"../../../../../core/Handles.js";import{makeHandle as e}from"../../../../../core/handleUtils.js";import"../../../../../core/has.js";import{destroyMaybe as i}from"../../../../../core/maybe.js";import{watch as a,initial as r}from"../../../../../core/reactiveUtils.js";import{fromScaling as s}from"../../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as o}from"../../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{set as n}from"../../../../../core/libs/gl-matrix-2/math/vec3.js";import{fromValues as l}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{sv3d as p,sm4d as c}from"../../../../../geometry/support/vectorStacks.js";import{Manipulator3D as m}from"../../Manipulator3D.js";import{RenderObject as h}from"../../RenderObject.js";import{screenToMapXYAtLocation as u}from"../dragEventPipeline3D.js";import{discRadius as d,discCollisionRadius as _,geometrySegments as f,discHeight as g}from"./config.js";import{Manipulation as j}from"./Manipulation.js";import{createManipulatedMoveDragPipeline as M}from"./moveUtils.js";import{SnapToScene as v}from"../snapping/SnapToScene.js";import{createCylinderGeometry as S}from"../../../webgl-engine/lib/GeometryUtil.js";import{ColorMaterial as T}from"../../../webgl-engine/materials/ColorMaterial.js";import{createManipulatorDragEventPipeline as w,dragAtLocation as b,addScreenDelta as y}from"../../../../interactive/dragEventPipeline.js";class x extends j{constructor(e){super(),this._handles=new t,this._snapToScene=new v,this._scale=1,this._radius=d,this._view=e.view,this._tool=e.tool,this._discMaterial=this._createMaterial(),this._discMaterialTransparent=this._createMaterial(.5),null!=e.snapToScene&&(this.snapToScene=e.snapToScene),null!=e.radius&&(this._radius=e.radius),this._createManipulator(),this.forEachManipulator(t=>this._tool.manipulators.add(t))}destroy(){this._handles=i(this._handles),this.forEachManipulator(t=>{this._tool.manipulators.remove(t),t.destroy()}),this._tool=null,this._view=null,this._manipulator=null}forEachManipulator(t){t(this._manipulator,1)}get displayScale(){return this._scale}set displayScale(t){this._scale=t,this._updateManipulatorTransform()}get snapToScene(){return this._snapToScene.enabled}set snapToScene(t){this._snapToScene.enabled=t}get radius(){return this._radius}set radius(t){t!==this._radius&&(this._radius=t,this._updateManipulator())}get discManipulator(){return this._manipulator}createManipulatedObjectDragPipeline(t,i,a){if(!i.operations)return e();const r=i.graphic,s=i.elevationInfo,o=i.operations.data.spatialReference;return M(i,a,e=>this.createDragPipeline((i,a,r,s,o)=>(({steps:a,cancel:r}=t(i,a,r,s,o)),e(i,a,r)),s,o,r))}createDragPipeline(t,e,i,a){const r=this._view;return w(this._manipulator,(s,o,n,l,p)=>{const c=o.next(b(r,s.elevationAlignedLocation)).next(u(r,s.elevationAlignedLocation,e,i,a)).next(...this._snapToScene.createDragEventPipelineStep(r,e)).next(t=>({...t,manipulatorType:1})).next(y());t(s,c,n,l,p)})}_updateManipulatorTransform(){const t=s(c.get(),n(p.get(),this.displayScale,this.displayScale,this.displayScale));this._manipulator.modelTransform=t}_createManipulator(){const t=this._view;this._manipulator=new m({view:t,worldSized:!1,autoScaleRenderObjects:!1,focusMultiplier:1,touchMultiplier:1,collisionType:{type:"disc",direction:l(0,0,1)},worldOriented:!0}),this._updateManipulator()}_updateManipulator(){const t=S(this._discMaterial,g,1,f,l(0,0,1),l(0,0,0));t.transformation=s(o(),l(this._radius,this._radius,this._radius)),this._manipulator.renderObjects=[new h(t,2),new h(t.instantiate({material:this._discMaterialTransparent}),1)],this._manipulator.radius=_*(this._radius/d)}_createMaterial(t=1){const e=new T({cullFace:2,renderOccluded:2,isDecoration:!0});return this._handles.add(a(()=>this._view.effectiveTheme.accentColor.toUnitRGBA(),i=>{i[3]*=t,e.setParameters({color:i})},r)),e}get test(){}}export{x as MoveXYDiscManipulation};
