UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 14.2 kB
import{_ as t}from"../../../../chunks/tslib.es6.js";import i from"../../../../core/Accessor.js";import e from"../../../../core/Logger.js";import{lerp as r}from"../../../../core/mathUtils.js";import{createScreenPointArray as s,createRenderScreenPointArray3 as h}from"../../../../core/screenUtils.js";import{property as o}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/accessorSupport/ensureType.js";import"../../../../core/arrayUtils.js";import{subclass as n}from"../../../../core/accessorSupport/decorators/subclass.js";import{c as a,m as p,q as _,h as u,a as v,t as l,u as w}from"../../../../chunks/mat4.js";import{c}from"../../../../chunks/mat4f64.js";import{c as d,m as y}from"../../../../chunks/vec2.js";import{f as g}from"../../../../chunks/vec2f64.js";import{b as f,i as m,c as x,k as M,w as T,e as D,D as j,E as R,g as F,l as P,s as O,f as V,n as S,r as C}from"../../../../chunks/vec3.js";import{c as I}from"../../../../chunks/vec3f64.js";import{b,h as E,g as L,c as k,i as H,t as U}from"../../../../chunks/vec4.js";import{f as B,c as G}from"../../../../chunks/vec4f64.js";import{create as A,copy as z,fromMatrix as W}from"../../../../geometry/support/frustum.js";import{create as X}from"../../../../geometry/support/ray.js";import{projectPointSignedLength as Y}from"../../../../geometry/support/vector.js";import{ViewingMode as q}from"../../../ViewingMode.js";import{fovd2fovx as N,fovx2fovd as J,fovd2fovy as K,fovy2fovd as Q}from"./fov.js";var Z;let $=Z=class extends i{constructor(t={}){super(t),this._center=I(),this._up=I(),this._viewUp=I(),this._viewForward=I(),this._viewRight=I(),this._ray=X(),this._viewport=B(0,0,1,1),this._padding=B(0,0,0,0),this._fov=55/180*Math.PI,this._nearFar=g(1,1e3),this._viewDirty=!0,this._viewMatrix=c(),this._viewProjectionDirty=!0,this._viewProjectionMatrix=c(),this._viewInverseTransposeMatrixDirty=!0,this._viewInverseTransposeMatrix=c(),this._frustumDirty=!0,this._frustum=A(),this._fullViewport=G(),this._pixelRatio=1,this.relativeElevation=0}get pixelRatio(){return this._pixelRatio}set pixelRatio(t){this._pixelRatio=t>0?t:1}get eye(){return this._ray.origin}set eye(t){this._compareAndSetView(t,this._ray.origin)}get center(){return this._center}set center(t){this._compareAndSetView(t,this._center,"_center")}get ray(){return f(this._ray.direction,this.center,this.eye),this._ray}get up(){return this._up}set up(t){this._compareAndSetView(t,this._up,"_up")}get viewMatrix(){return this._ensureViewClean(),this._viewMatrix}set viewMatrix(t){a(this._viewMatrix,t),this._viewDirty=!1,this._viewInverseTransposeMatrixDirty=!0,this._viewProjectionDirty=!0,this._frustumDirty=!0}get viewForward(){return this._ensureViewClean(),this._viewForward}get viewUp(){return this._ensureViewClean(),this._viewUp}get viewRight(){return this._ensureViewClean(),this._viewRight}get nearFar(){return this._nearFar}get near(){return this._nearFar[0]}set near(t){this._nearFar[0]!==t&&(this._nearFar[0]=t,this._viewProjectionDirty=!0,this._frustumDirty=!0,this.notifyChange("_nearFar"))}get far(){return this._nearFar[1]}set far(t){this._nearFar[1]!==t&&(this._nearFar[1]=t,this._viewProjectionDirty=!0,this._frustumDirty=!0,this.notifyChange("_nearFar"))}get viewport(){return this._viewport}set viewport(t){this.x=t[0],this.y=t[1],this.width=t[2],this.height=t[3]}get screenViewport(){if(1===this.pixelRatio)return this._viewport;const t=b(G(),this._viewport,1/this.pixelRatio),i=this._get("screenViewport");return i&&E(t,i)?i:t}get x(){return this._viewport[0]}set x(t){t+=this._padding[ht.LEFT],this._viewport[0]!==t&&(this._viewport[0]=t,this._viewProjectionDirty=!0,this._frustumDirty=!0,this.notifyChange("_viewport"))}get y(){return this._viewport[1]}set y(t){t+=this._padding[ht.BOTTOM],this._viewport[1]!==t&&(this._viewport[1]=t,this._viewProjectionDirty=!0,this._frustumDirty=!0,this.notifyChange("_viewport"))}get width(){return this._viewport[2]}set width(t){this._viewport[2]!==t&&(this._viewport[2]=t,this._viewProjectionDirty=!0,this._frustumDirty=!0,this.notifyChange("_viewport"))}get height(){return this._viewport[3]}set height(t){this._viewport[3]!==t&&(this._viewport[3]=t,this._viewProjectionDirty=!0,this._frustumDirty=!0,this.notifyChange("_viewport"))}get fullWidth(){return this._viewport[2]+this._padding[ht.RIGHT]+this._padding[ht.LEFT]}set fullWidth(t){this.width=t-(this._padding[ht.RIGHT]+this._padding[ht.LEFT])}get fullHeight(){return this._viewport[3]+this._padding[ht.TOP]+this._padding[ht.BOTTOM]}set fullHeight(t){this.height=t-(this._padding[ht.TOP]+this._padding[ht.BOTTOM])}get fullViewport(){return this._fullViewport[0]=this._viewport[0]-this._padding[ht.LEFT],this._fullViewport[1]=this._viewport[1]-this._padding[ht.BOTTOM],this._fullViewport[2]=this.fullWidth,this._fullViewport[3]=this.fullHeight,this._fullViewport}get _aspect(){return this.width/this.height}get padding(){return this._padding}set padding(t){L(this._padding,t)||(this._viewport[0]+=t[ht.LEFT]-this._padding[ht.LEFT],this._viewport[1]+=t[ht.BOTTOM]-this._padding[ht.BOTTOM],this._viewport[2]-=t[ht.RIGHT]+t[ht.LEFT]-(this._padding[ht.RIGHT]+this._padding[ht.LEFT]),this._viewport[3]-=t[ht.TOP]+t[ht.BOTTOM]-(this._padding[ht.TOP]+this._padding[ht.BOTTOM]),k(this._padding,t),this._viewProjectionDirty=!0,this._frustumDirty=!0,this.notifyChange("_padding"),this.notifyChange("_viewport"))}get viewProjectionMatrix(){return this._viewProjectionDirty&&(p(this._viewProjectionMatrix,this.projectionMatrix,this.viewMatrix),this._viewProjectionDirty=!1),this._viewProjectionMatrix}get projectionMatrix(){const t=this.width,i=this.height,e=this.near*Math.tan(this.fovY/2),r=e*this._aspect,s=_(c(),-r*(1+2*this._padding[ht.LEFT]/t),r*(1+2*this._padding[ht.RIGHT]/t),-e*(1+2*this._padding[ht.BOTTOM]/i),e*(1+2*this._padding[ht.TOP]/i),this.near,this.far),h=this._get("projectionMatrix");return h&&u(h,s)?h:s}get inverseProjectionMatrix(){return v(c(),this.projectionMatrix)||this._get("inverseProjectionMatrix")||c()}get fov(){return this._fov}set fov(t){this._fov=t,this._viewProjectionDirty=!0,this._frustumDirty=!0}get fovX(){return N(this._fov,this.width,this.height)}set fovX(t){this._fov=J(t,this.width,this.height),this._viewProjectionDirty=!0,this._frustumDirty=!0}get fovY(){return K(this._fov,this.width,this.height)}set fovY(t){this._fov=Q(t,this.width,this.height),this._viewProjectionDirty=!0,this._frustumDirty=!0}get distance(){return m(this.center,this.eye)}get frustum(){return this._recomputeFrustum(),this._frustum}get viewInverseTransposeMatrix(){return(this._viewInverseTransposeMatrixDirty||this._viewDirty)&&(v(this._viewInverseTransposeMatrix,this.viewMatrix),l(this._viewInverseTransposeMatrix,this._viewInverseTransposeMatrix),this._viewInverseTransposeMatrixDirty=!1),this._viewInverseTransposeMatrix}depthNDCToWorld(t){const i=2*t-1;return 2*this.near*this.far/(this.far+this.near-i*(this.far-this.near))}get perRenderPixelRatio(){return Math.tan(this.fovX/2)/(this.width/2)}get perScreenPixelRatio(){return this.perRenderPixelRatio*this.pixelRatio}get aboveGround(){return null!=this.relativeElevation&&this.relativeElevation>=0}copyFrom(t){x(this._ray.origin,t.eye),this.center=t.center,this.up=t.up,k(this._viewport,t.viewport),this.notifyChange("_viewport"),k(this._padding,t.padding),this.notifyChange("_padding"),d(this._nearFar,t.nearFar),this.notifyChange("_nearFar"),this._fov=t.fov,this.relativeElevation=t.relativeElevation;const i=t;return this._viewDirty=i._viewDirty,this._viewDirty||(a(this._viewMatrix,t.viewMatrix),x(this._viewRight,t.viewRight),x(this._viewUp,t.viewUp),x(this._viewForward,t.viewForward)),this._viewProjectionDirty=!0,this._frustumDirty=i._frustumDirty,this._frustumDirty||(z(this._frustum,t.frustum),this._frustumDirty=!1),i._viewInverseTransposeMatrixDirty?this._viewInverseTransposeMatrixDirty=!0:(a(this._viewInverseTransposeMatrix,t.viewInverseTransposeMatrix),this._viewInverseTransposeMatrixDirty=!1),k(this._fullViewport,t.fullViewport),this.pixelRatio=t.pixelRatio,this}copyViewFrom(t){this.eye=t.eye,this.center=t.center,this.up=t.up}clone(){return(new Z).copyFrom(this)}equals(t){return M(this.eye,t.eye)&&M(this.center,t.center)&&M(this.up,t.up)&&L(this._viewport,t.viewport)&&L(this._padding,t.padding)&&y(this.nearFar,t.nearFar)&&this._fov===t.fov&&this.pixelRatio===t.pixelRatio&&this.relativeElevation===t.relativeElevation}almostEquals(t){if(Math.abs(t.fov-this._fov)>=.001||H(t.padding,this._padding)>=.5||H(this.screenViewport,t.screenViewport)>=.5)return!1;T(et,t.eye,t.center),T(rt,this.eye,this.center);const i=D(et,rt),e=j(et),r=j(rt),s=5e-4;return i*i>=(1-1e-10)*e*r&&R(t.eye,this.eye)<Math.max(e,r)*s*s}computeRenderPixelSizeAt(t){return this.computeRenderPixelSizeAtDist(this._viewDirectionDistance(t))}computeRenderPixelSizeAtDist(t){return t*this.perRenderPixelRatio}computeScreenPixelSizeAt(t){return this.computeScreenPixelSizeAtDist(this._viewDirectionDistance(t))}_viewDirectionDistance(t){return Math.abs(Y(this.viewForward,f(et,t,this.eye)))}computeScreenPixelSizeAtDist(t){return t*this.perScreenPixelRatio}computeDistanceFromRadius(t,i){return t/Math.tan(Math.min(this.fovX,this.fovY)/(2*(i||1)))}getScreenCenter(t=s()){return t[0]=(this.padding[ht.LEFT]+this.width/2)/this.pixelRatio,t[1]=(this.padding[ht.TOP]+this.height/2)/this.pixelRatio,t}getRenderCenter(t,i=.5,e=.5){return t[0]=this.padding[ht.LEFT]+this.width*i,t[1]=this.padding[ht.BOTTOM]+this.height*e,t[2]=.5,t}setGLViewport(t){const i=this.viewport,e=this.padding;t.setViewport(i[0]-e[3],i[1]-e[2],i[2]+e[1]+e[3],i[3]+e[0]+e[2])}applyProjection(t,i){t!==tt&&x(tt,t),tt[3]=1,U(tt,tt,this.projectionMatrix);const e=Math.abs(tt[3]);F(tt,tt,1/e);const s=this.fullViewport;i[0]=r(0,s[0]+s[2],.5+.5*tt[0]),i[1]=r(0,s[1]+s[3],.5+.5*tt[1]),i[2]=.5*(tt[2]+1),i[3]=e}unapplyProjection(t,i){const e=this.fullViewport;tt[0]=(t[0]/(e[0]+e[2])*2-1)*t[3],tt[1]=(t[1]/(e[1]+e[3])*2-1)*t[3],tt[2]=(2*t[2]-1)*t[3],tt[3]=t[3],null!=this.inverseProjectionMatrix&&(U(tt,tt,this.inverseProjectionMatrix),i[0]=tt[0],i[1]=tt[1],i[2]=tt[2])}projectToScreen(t,i){return this.projectToRenderScreen(t,st),this.renderToScreen(st,i),i}projectToRenderScreen(t,i){if(tt[0]=t[0],tt[1]=t[1],tt[2]=t[2],tt[3]=1,U(tt,tt,this.viewProjectionMatrix),0===tt[3])return null;F(tt,tt,1/Math.abs(tt[3]));const e=this.fullViewport;return"x"in i?(i.x=r(0,e[0]+e[2],.5+.5*tt[0]),i.y=r(0,e[1]+e[3],.5+.5*tt[1])):(i[0]=r(0,e[0]+e[2],.5+.5*tt[0]),i[1]=r(0,e[1]+e[3],.5+.5*tt[1]),i.length>2&&(i[2]=.5*(tt[2]+1))),i}unprojectFromScreen(t,i){return this.unprojectFromRenderScreen(this.screenToRender(t,st),i)}unprojectFromRenderScreen(t,i){if(p(it,this.projectionMatrix,this.viewMatrix),!v(it,it))return null;const e=this.fullViewport;return tt[0]=2*(t[0]-e[0])/e[2]-1,tt[1]=2*(t[1]-e[1])/e[3]-1,tt[2]=2*t[2]-1,tt[3]=1,U(tt,tt,it),0===tt[3]?null:(i[0]=tt[0]/tt[3],i[1]=tt[1]/tt[3],i[2]=tt[2]/tt[3],i)}constrainWindowSize(t,i,e,r){const s=t*this.pixelRatio,h=i*this.pixelRatio,o=Math.max(s-e/2,0),n=Math.max(this.fullHeight-h-r/2,0),a=-Math.min(s-e/2,0),p=-Math.min(this.fullHeight-h-r/2,0);return[o,n,e-a- -Math.min(this.fullWidth-s-e/2,0),r-p- -Math.min(h-r/2,0)]}computeUp(t){t===q.Global?this._computeUpGlobal():this._computeUpLocal()}screenToRender(t,i){const e=t[0]*this.pixelRatio,r=this.fullHeight-t[1]*this.pixelRatio;return i[0]=e,i[1]=r,i}renderToScreen(t,i){const e=t[0]/this.pixelRatio,r=(this.fullHeight-t[1])/this.pixelRatio;i[0]=e,i[1]=r}_computeUpGlobal(){f(et,this.center,this.eye);const t=P(this.center);t<1?(O(this._up,0,0,1),this._markViewDirty(),this.notifyChange("_up")):Math.abs(D(et,this.center))>.9999*P(et)*t||(V(this._up,et,this.center),V(this._up,this._up,et),S(this._up,this._up),this.notifyChange("_up"),this._markViewDirty())}_computeUpLocal(){C(et,this.eye,this.center),Math.abs(et[2])<=.9999&&(F(et,et,et[2]),O(this._up,-et[0],-et[1],1-et[2]),S(this._up,this._up),this.notifyChange("_up"),this._markViewDirty())}_compareAndSetView(t,i,r=""){"number"==typeof t[0]&&isFinite(t[0])&&"number"==typeof t[1]&&isFinite(t[1])&&"number"==typeof t[2]&&isFinite(t[2])?M(t,i)||(x(i,t),this._markViewDirty(),r.length&&this.notifyChange(r)):e.getLogger("esri.views.3d.webgl-engine.lib.Camera").warn("Camera vector contains invalid number, ignoring value")}_markViewDirty(){this._viewDirty=!0,this._frustumDirty=!0,this._viewProjectionDirty=!0}_recomputeFrustum(){this._frustumDirty&&(W(this.viewMatrix,this.projectionMatrix,this._frustum),this._frustumDirty=!1)}_ensureViewClean(){this._viewDirty&&(w(this._viewMatrix,this.eye,this.center,this.up),O(this._viewForward,-this._viewMatrix[2],-this._viewMatrix[6],-this._viewMatrix[10]),O(this._viewUp,this._viewMatrix[1],this._viewMatrix[5],this._viewMatrix[9]),O(this._viewRight,this._viewMatrix[0],this._viewMatrix[4],this._viewMatrix[8]),this._viewDirty=!1,this._viewInverseTransposeMatrixDirty=!0)}};t([o()],$.prototype,"_center",void 0),t([o()],$.prototype,"_up",void 0),t([o()],$.prototype,"_viewport",void 0),t([o()],$.prototype,"_padding",void 0),t([o()],$.prototype,"_fov",void 0),t([o()],$.prototype,"_nearFar",void 0),t([o()],$.prototype,"_pixelRatio",void 0),t([o()],$.prototype,"pixelRatio",null),t([o()],$.prototype,"eye",null),t([o()],$.prototype,"center",null),t([o()],$.prototype,"up",null),t([o({readOnly:!0})],$.prototype,"nearFar",null),t([o()],$.prototype,"near",null),t([o()],$.prototype,"far",null),t([o()],$.prototype,"viewport",null),t([o({readOnly:!0})],$.prototype,"screenViewport",null),t([o()],$.prototype,"x",null),t([o()],$.prototype,"y",null),t([o()],$.prototype,"width",null),t([o()],$.prototype,"height",null),t([o()],$.prototype,"fullWidth",null),t([o()],$.prototype,"fullHeight",null),t([o({readOnly:!0})],$.prototype,"_aspect",null),t([o()],$.prototype,"padding",null),t([o({readOnly:!0})],$.prototype,"projectionMatrix",null),t([o({readOnly:!0})],$.prototype,"inverseProjectionMatrix",null),t([o()],$.prototype,"fov",null),t([o()],$.prototype,"fovX",null),t([o()],$.prototype,"fovY",null),$=Z=t([n("esri.views.3d.webgl-engine.lib.Camera")],$);const tt=G(),it=c(),et=I(),rt=I(),st=h();var ht;!function(t){t[t.TOP=0]="TOP",t[t.RIGHT=1]="RIGHT",t[t.BOTTOM=2]="BOTTOM",t[t.LEFT=3]="LEFT"}(ht||(ht={}));export{$ as Camera,ht as PaddingSide};