UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 14.6 kB
import"../../../../geometry.js";import e from"../../../../analysis/SlicePlane.js";import"../../../../core/has.js";import t from"../../../../core/Logger.js";import{rad2deg as n,deg2rad as i}from"../../../../core/mathUtils.js";import{isNone as o,isSome as r}from"../../../../core/maybe.js";import{castRenderScreenPointArray3 as s}from"../../../../core/screenUtils.js";import{o as a,b as c,k as l,m as u,r as d,i as m,w as p,F as g}from"../../../../chunks/mat4.js";import{c as f}from"../../../../chunks/mat4f64.js";import{r as b}from"../../../../chunks/quat.js";import{g as h,c as T,e as w,f as O,n as E,a as I,l as R,b as j,s as A,p as L,w as _}from"../../../../chunks/vec3.js";import{a as C,c as N,f as P}from"../../../../chunks/vec3f64.js";import{tryProjectWithZConversion as M}from"../../../../geometry/projection.js";import{Axis as v}from"../../../../geometry/support/Axis.js";import{r as y,f as U,i as V,a as S,n as k,u as H}from"../../../../chunks/boundedPlane.js";import{fromVectorsAndPoint as x,fromPositionAndNormal as F}from"../../../../geometry/support/plane.js";import{create as G}from"../../../../geometry/support/ray.js";import{angleAroundAxis as D}from"../../../../geometry/support/vector.js";import{sv3d as X,sm4d as Y,sq4d as Z}from"../../../../geometry/support/vectorStacks.js";import{VERTICAL_DOT_THRESHOLD as W,SMALL_ANGLE_DOT_THRESHOLD as B,PLANE_MIN_BASIS_SCREEN_LEN2 as q,INITIAL_PLANE_HALF_SIZE_VIEW_PROPORTION as z,SHIFT_RESTART_OFFSET_DISTANCE as $,RESIZE_HANDLE_EDGE_PADDING_FRAC as J,SHIFT_RESTART_CALLOUT_COLOR as K,SHIFT_RESTART_TIP_RADIUS as Q,PLANE_OUTLINE_COLOR as ee,PLANE_OUTLINE_WIDTH as te,PLANE_BACKGROUND_COLOR as ne,GRID_COLOR as ie,RESIZE_HANDLE_CORNER_INPUT_RADIUS as oe,RESIZE_HANDLE_EDGE_INPUT_RADIUS as re,SHIFT_RESTART_ARROW_TIP_COLOR as se,SHIFT_RESTART_ARROW_CAP_COLOR as ae,SHIFT_RESTART_TUBE_COLOR as ce,SHIFT_RESTART_OUTLINE_COLOR as le,SHIFT_RESTART_TIP_LENGTH as ue,SHIFT_RESTART_ARROW_LENGTH as de,SHIFT_RESTART_ARROW_OUTLINE_WIDTH as me,RESIZE_HANDLE_CORNER_WIDTH as pe,RESIZE_HANDLE_EDGE_WIDTH as ge,DISPLAY_FOCUS_MULTIPLIER as fe,SHIFT_RESTART_TUBE_RADIUS as be,SHIFT_RESTART_TUBE_FOCUS_MULTIPLIER as he,RESIZE_HANDLE_COLOR as Te,SHIFT_RESTART_TIP_FOCUS_MULTIPLIER as we}from"./sliceToolConfig.js";import{applyProjectionAndElevationAlignment as Oe}from"../support/projectionUtils.js";import{Manipulator3D as Ee}from"../../interactive/Manipulator3D.js";import{calculateTranslateRotateFromBases as Ie,createRotateManipulator as Re,worldScaledManipulatorSettings as je}from"../../interactive/manipulatorUtils.js";import{RenderObject as Ae}from"../../interactive/RenderObject.js";import{LineVisualElement as Le}from"../../interactive/visualElements/LineVisualElement.js";import{SlicePlaneVisualElement as _e}from"../../interactive/visualElements/SlicePlaneVisualElement.js";import{RenderCoordsHelper as Ce}from"../../support/RenderCoordsHelper.js";import{fromRender as Ne}from"../../support/geometryUtils/ray.js";import{CullFaceOptions as Pe}from"../../webgl-engine/lib/basicInterfaces.js";import{createPolylineGeometry as Me,createConeGeometry as ve,createPathExtrusionGeometry as ye}from"../../webgl-engine/lib/GeometryUtil.js";import{RenderOccludedFlag as Ue}from"../../webgl-engine/lib/Material.js";import{ColorMaterial as Ve}from"../../webgl-engine/materials/ColorMaterial.js";import{NativeLineMaterial as Se}from"../../webgl-engine/materials/NativeLineMaterial.js";import{RibbonLineMaterial as ke}from"../../webgl-engine/materials/RibbonLineMaterial.js";import{ManipulatorStateCustomFlags as He,ManipulatorStateFlags as xe}from"../../../interactive/interfaces.js";import Fe from"../../../../geometry/Extent.js";function Ge(e,t,n,i,o,r,s,a){return De(t,s.worldUpAtPosition(e,X.get()),o,r,a.basis1,a.basis2),h(a.basis1,a.basis1,n),h(a.basis2,a.basis2,i),T(a.origin,e),x(a.basis2,a.basis1,a.origin,a.plane),a}function De(e,t,n,i,o,r){const s=w(e,t),a=X.get(),c=X.get();switch(i===Rt.HORIZONTAL_OR_VERTICAL?Math.abs(s)>W?Rt.HORIZONTAL:Rt.VERTICAL:i){case Rt.VERTICAL:{const i=Math.abs(s)<=B?e:n.viewUp;O(a,i,t),T(c,t);break}case Rt.HORIZONTAL:O(a,n.viewUp,t),O(c,t,a);break;case Rt.TILTED:{const i=Math.abs(s)<=B?t:n.viewUp;O(a,i,e),O(c,e,a);break}}const l=O(X.get(),a,c);w(l,n.viewForward)>0&&h(c,c,-1),E(o,a),E(r,c)}function Xe(e,t,n){const i=t.worldUpAtPosition(e.origin,X.get()),o=e.basis1,r=bt(e,i),s=Math.round(r/Lt)*Lt;return y(e,s-r,o,n)}function Ye(e,t,n,i,o,r){const s=T(X.get(),o.origin);I(s,s,h(X.get(),o.basis1,e.direction[0]<0?1:-1)),I(s,s,h(X.get(),o.basis2,e.direction[1]<0?1:-1));const a=R(o.basis1),c=R(o.basis2),l=j(X.get(),n,s),u=j(X.get(),t,s);let d=0,m=0;if(rt(e)){const t=ot(o),n=ot(r);d=a-.5*e.direction[0]*w(o.basis1,u)/a,m=c-.5*e.direction[1]*w(o.basis2,u)/c;const i=n/t;d*=i,m*=i}const p=d+.5*e.direction[0]*w(o.basis1,l)/a,g=m+.5*e.direction[1]*w(o.basis2,l)/c,f=h(X.get(),o.basis1,p/a),b=h(X.get(),o.basis2,g/c);(p<=0||nt(r.origin,f,i)<=q)&&T(f,r.basis1),(g<=0||nt(r.origin,b,i)<=q)&&T(b,r.basis2);const O=T(X.get(),s);return I(O,O,h(X.get(),f,e.direction[0]<0?-1:1)),I(O,O,h(X.get(),b,e.direction[1]<0?-1:1)),U(O,f,b,r)}function Ze(e,t){return z*Math.min(t.width,t.height)*t.computeRenderPixelSizeAt(e)}function We(e,t,n,i){const o=O(X.get(),t,n);return O(o,o,t),F(e,o,i)}function Be(e,t){return Ie(e.basis1,e.basis2,e.origin,t)}function qe(e,t,n,i){const o=t.worldUpAtPosition(e.origin,X.get()),r=X.get();switch(n){case It.HEADING:T(r,o);break;case It.TILT:T(r,e.basis1)}return F(e.origin,r,i)}function ze(e,t,n,i){const o=tt(n,et.NEGATIVE_X),r=Y.get();a(r,t,o.edge*Math.PI/2);const c=E(X.get(),o.basis);let l=h(X.get(),c,o.direction*i.computeScreenPixelSizeAt(o.position)*$);I(l,l,o.position);const u=i.projectToRenderScreen(l,s(X.get())),d=$e(i,u);Ne(i,u,At),E(At.direction,At.direction);const m=X.get();!d&&V(n,At,m)&&(l=m),r[12]=0,r[13]=0,r[14]=0,e.modelTransform=r,e.renderLocation=C(l),d?e.state|=jt:e.state&=~jt}function $e(e,t){const[n,i,o,r]=e.viewport,s=Math.min(o,r)/16;let a=!0;return t[0]<n+s?(t[0]=n+s,a=!1):t[0]>n+o-s&&(t[0]=n+o-s,a=!1),t[1]<i+s?(t[1]=i+s,a=!1):t[1]>i+r-s&&(t[1]=i+r-s,a=!1),a}function Je(e,t,n,i){const o=R(i.basis1),r=R(i.basis2),s=it(i),a=ot(i),d=A(X.get(),0,0,0);I(d,h(X.get(),i.basis1,t.direction[0]),h(X.get(),i.basis2,t.direction[1])),I(d,i.origin,d);let m=0,p=1;if(rt(t))1===t.direction[0]&&-1===t.direction[1]?m=Lt:1===t.direction[0]&&1===t.direction[1]?m=Math.PI:-1===t.direction[0]&&1===t.direction[1]&&(m=3*Math.PI/2),p=a;else{const e=0!==t.direction[0]?1:2;m=1===e?Lt:0,p=(1===e?r:o)-s}const g=c(Y.get(),m);l(g,g,A(X.get(),p,p,p)),u(g,n,g),g[12]=0,g[13]=0,g[14]=0,e.modelTransform=g,e.renderLocation=d}function Ke(e,t,n,i){const o=i.worldUpAtPosition(n.origin,X.get()),r=tt(n,et.POSITIVE_X),s=c(Y.get(),r.edge*Math.PI/2);d(s,s,-bt(n,o)),u(s,t,s),s[12]=0,s[13]=0,s[14]=0,e.modelTransform=s,e.renderLocation=r.position}function Qe(e,t,n){const i=tt(n,et.POSITIVE_Y),o=c(Y.get(),i.edge*Math.PI/2);d(o,o,Lt),u(o,t,o),o[12]=0,o[13]=0,o[14]=0,e.modelTransform=o,e.renderLocation=i.position}var et;function tt(e,t){switch(t){case et.POSITIVE_X:return{basis:e.basis1,direction:1,position:I(X.get(),e.origin,e.basis1),edge:t};case et.POSITIVE_Y:return{basis:e.basis2,direction:1,position:I(X.get(),e.origin,e.basis2),edge:t};case et.NEGATIVE_X:return{basis:e.basis1,direction:-1,position:j(X.get(),e.origin,e.basis1),edge:t};case et.NEGATIVE_Y:return{basis:e.basis2,direction:-1,position:j(X.get(),e.origin,e.basis2),edge:t}}}function nt(e,t,n){const i=n.projectToRenderScreen(I(X.get(),e,t),s(X.get())),o=n.projectToRenderScreen(j(X.get(),e,t),s(X.get()));return L(j(i,i,o))}function it(e){const t=R(e.basis1),n=R(e.basis2);return J*Math.min(t,n)}function ot(e){return it(e)}function rt(e){return 0!==e.direction[0]&&0!==e.direction[1]}function st(e,t=Nt.CENTER_ON_ARROW){const n=t===Nt.CENTER_ON_CALLOUT?$:0,i=[P(n,0,-de/2),P(n,0,de/2)],o=pt(i,!0),r=(e,t)=>dt(i,e,t),s=r(0,!1),a=r(me,!0),c=new Se({color:K,renderOccluded:Ue.OccludeAndTransparent}),l=Me(c,[[n,0,0],[n-$,0,0]]),u=Me(c,[[n,0,0],[n-$,0,0]]);return new Ee({view:e,renderObjects:[...s.normal.map((e=>new Ae(e,xe.Unfocused|Et))),...a.normal.map((e=>new Ae(e,xe.Unfocused|Et))),new Ae(l,xe.Unfocused|Et|jt),...s.focused.map((e=>new Ae(e,xe.Focused|Et))),...a.focused.map((e=>new Ae(e,xe.Focused|Et))),new Ae(u,xe.Focused|Et|jt)],autoScaleRenderObjects:!1,collisionType:{type:"line",paths:[o]},collisionPriority:1,radius:Q,state:Et})}function at(e,t){const n=Re(e,{customStateMask:Et,texture:t});return n.state=Et,n}function ct(e){const t=[[-1,-1,0],[1,-1,0],[1,1,0],[-1,1,0],[-1,-1,0]];return new Le({view:e,attached:!1,color:ee,width:te,writeDepthEnabled:!1,renderOccluded:Ue.OccludeAndTransparent,geometry:[t]})}function lt(e){return new _e({view:e,attached:!1,backgroundColor:[...ne],gridColor:ie,gridWidth:4,renderOccluded:Ue.OccludeAndTransparent})}function ut(e,t){const n=rt(t),i=n?[P(1,0,0),P(0,0,0),P(0,1,0)]:[P(1,0,0),P(-1,0,0)],o=Te,r=e=>new ke({color:o,width:e,renderOccluded:Ue.OccludeAndTransparent}),s=()=>new Se({color:o,renderOccluded:Ue.OccludeAndTransparent}),a=n?pe:ge,c=a*fe,l=ge,u=e=>e>1?r(e):s(),d=[new Ae(Me(u(a),i),xe.Unfocused|_t),new Ae(Me(u(c),i),xe.Focused|_t),new Ae(Me(u(l),i),Ct)],m=new Ee({view:e,renderObjects:d,collisionType:{type:"line",paths:[i]},radius:n?oe:re,...je});return m.state=_t,m}function dt(e,t,n){const i=new Ve({color:se,cullFace:Pe.Back,renderOccluded:Ue.Opaque}),o=new Ve({color:ae,cullFace:Pe.Back,renderOccluded:Ue.Opaque}),r=new Ve({color:ce,cullFace:Pe.Back,renderOccluded:Ue.Opaque}),s=new Ve({color:le,transparent:!0,writeDepth:!1,cullFace:Pe.Front,renderOccluded:Ue.Transparent}),a=a=>{e=e.slice(0);const c=j(X.get(),e[0],e[1]);E(c,c);const d=j(X.get(),e[e.length-1],e[e.length-2]);if(E(d,d),t>0){const n=h(N(),d,-t);e[e.length-1]=I(n,n,e[e.length-1]);const i=h(N(),c,-t);e[0]=I(i,i,e[0])}const T=a?we:1,w=ue*T,O=Q*T,R=m(Y.get());if(t>0){const e=w/4,n=A(X.get(),0,e,0),i=1+t/e;p(R,R,n),l(R,R,A(X.get(),i,i,i)),p(R,R,h(n,n,-1/i))}const L=m(f()),_=P(0,1,0),C=g(f(),b(Z.get(),_,d));C[12]=e[e.length-1][0],C[13]=e[e.length-1][1],C[14]=e[e.length-1][2],u(C,C,R);const M=mt(be*(a?he:1)+t,e,n?s:r);M.transformation=L;const v=[M],y=ve(n?s:i,w,O,24,!1,!1,!0);y.transformation=C,v.push(y);const U=ve(n?s:o,w,O,24,!1,!0,!1);U.transformation=C,v.push(U);const V=g(f(),b(Z.get(),_,c));return V[12]=e[0][0],V[13]=e[0][1],V[14]=e[0][2],u(V,V,R),v.push(y.instantiate({transformation:V})),v.push(U.instantiate({transformation:V})),v};return{normal:a(!1),focused:a(!0)}}function mt(e,t,n){const i=[],o=12;for(let r=0;r<o;r++){const t=r/o*2*Math.PI;i.push([Math.cos(t)*e,Math.sin(t)*e])}return ye(n,i,t,[],[],!1)}function pt(e,t){const n=j(N(),e[e.length-1],e[e.length-2]);if(E(n,n),h(n,n,ue),I(n,n,e[e.length-1]),t){const t=j(N(),e[0],e[1]);return E(t,t),h(t,t,ue),I(t,t,e[0]),[t,...e,n]}return[...e,n]}function gt(t,i,r,s=new e){if(o(t))return null;const{renderCoordsHelper:a}=i,c=a.fromRenderCoords(t.origin,i.spatialReference);if(o(c))return null;const l=M(c,r);if(o(l))return null;s.position=l;const u=2*R(t.basis1),d=2*R(t.basis2),m=Ce.renderUnitScaleFactor(i.spatialReference,r);s.width=u*m,s.height=d*m;const p=a.worldUpAtPosition(t.origin,X.get());return s.tilt=n(bt(t,p)),s.heading=a.headingAtPosition(t.origin,t.basis1)-90,s}function ft(e,t,n){if(o(e))return null;const i=e.origin,r=X.get(),s=X.get(),a=X.get(),c=X.get();let l,u,d,m,p,g;I(r,i,e.basis1),I(r,r,e.basis2),I(s,i,e.basis1),_(s,s,e.basis2),_(a,i,e.basis1),_(a,a,e.basis2),_(c,i,e.basis1),I(c,c,e.basis2);for(const f of[r,s,a,c]){const e=t.fromRenderCoords(f,f,n);if(o(e))return null;l=null==l?e[0]:Math.min(l,e[0]),u=null==u?e[0]:Math.max(u,e[0]),d=null==d?e[1]:Math.min(d,e[1]),m=null==m?e[1]:Math.max(m,e[1]),p=null==p?e[2]:Math.min(p,e[2]),g=null==g?e[2]:Math.max(g,e[2])}return new Fe({xmin:l,xmax:u,ymin:d,ymax:m,zmin:p,zmax:g,spatialReference:n})}function bt(e,t){return D(t,e.basis2,e.basis1)+Lt}function ht(e,n,o,r,s,a,c=S()){return a.toRenderCoords(e,c.origin)?(a.worldBasisAtPosition(c.origin,v.X,c.basis1),a.worldBasisAtPosition(c.origin,v.Y,c.basis2),x(c.basis2,c.basis1,c.origin,c.plane),y(c,-i(n),k(c),c),y(c,i(o),c.basis1,c),h(c.basis1,c.basis1,r/2),h(c.basis2,c.basis2,s/2),H(c),c):(t.getLogger("esri.views.3d.analysis.Slice.sliceToolUtils").error(`Failed to project slice plane position, projection from ${e.spatialReference.wkid} is not supported`),null)}function Tt(e,t){if(o(e)||o(e.position))return null;const n=Oe(e.position,t.spatialReference,t.elevationProvider);if(o(n))return null;const i=Ce.renderUnitScaleFactor(e.position.spatialReference,t.spatialReference),r=e.width*i,s=e.height*i;return{position:n,heading:e.heading,tilt:e.tilt,renderWidth:r,renderHeight:s}}function wt(e,t,n,i=S()){const r=Tt(e,t);return o(r)?null:Ot(r,t,n,i)}function Ot(e,t,n,i=S()){if(o(e))return null;const s=ht(e.position,e.heading,e.tilt,e.renderWidth,e.renderHeight,t.renderCoordsHelper,i);return!n.tiltEnabled&&r(s)&&Xe(s,t.renderCoordsHelper,s),s}!function(e){e[e.POSITIVE_X=0]="POSITIVE_X",e[e.POSITIVE_Y=1]="POSITIVE_Y",e[e.NEGATIVE_X=2]="NEGATIVE_X",e[e.NEGATIVE_Y=3]="NEGATIVE_Y"}(et||(et={}));const Et=He.Custom1;var It,Rt;!function(e){e[e.HEADING=1]="HEADING",e[e.TILT=2]="TILT"}(It||(It={})),function(e){e[e.HORIZONTAL_OR_VERTICAL=0]="HORIZONTAL_OR_VERTICAL",e[e.HORIZONTAL=1]="HORIZONTAL",e[e.VERTICAL=2]="VERTICAL",e[e.TILTED=3]="TILTED"}(Rt||(Rt={}));const jt=He.Custom2,At=G(),Lt=Math.PI/2,_t=He.Custom1,Ct=He.Custom2;var Nt;function Pt(e){const t="building-scene-3d"===e.type?e:null;return r(t)}!function(e){e[e.CENTER_ON_CALLOUT=0]="CENTER_ON_CALLOUT",e[e.CENTER_ON_ARROW=1]="CENTER_ON_ARROW"}(Nt||(Nt={}));export{Et as DidPointerMoveRecentlyFlag,jt as IsShiftEdgeOnScreenFlag,Nt as OffsetMode,It as RotationAxis,Rt as SliceOrientation,pt as addArrowTips,Be as calculateBoundedPlaneTranslateRotate,ot as calculateDiagonalResizeHandleScale,Ze as calculatePlaneHalfSize,it as calculateResizeHandlePadding,nt as calculateScreenSpaceBasisLength2,dt as createArrowGeometry,lt as createGridVisualElement,ct as createOutlineVisualElement,Ge as createPlane,ut as createResizeManipulator,at as createRotateManipulator,qe as createRotatePlane,st as createShiftManipulator,We as createShiftPlane,Xe as forceHorizontalOrVertical,rt as isDiagonalResizeHandle,Pt as isIBuildingSceneLayerView3D,De as normalToBases,ft as planeToExtent,gt as planeToShape,Tt as projectAndElevationAlignShape,Ot as projectedShapeToPlane,_t as resizeNormal,Ct as resizeOutlineOnly,Ye as resizePlane,wt as shapeToPlane,Je as updateResizeHandle,Ke as updateRotateHeadingHandle,Qe as updateRotateTiltHandle,ze as updateShiftRestartHandle};