/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../../../../chunks/_rollupPluginBabelHelpers","../../../../../core/maybe","../../../../../chunks/vec3","../../../../../chunks/vec3f64","../../../../../geometry/support/aaBoundingBox","../../../../../geometry/support/buffer/BufferView","./ComponentIntersectionData","../../lib/ComponentUtils","../../lib/geometryDataUtils","../../materials/internal/MaterialUtil"],(function(t,e,n,i,o,s,r,a,p,c){"use strict";let m=function(){function i(t,n){this._indices=e.isSome(t.indices)?t.indices:p.generateDefaultIndexArray(t.positions.length/3),this._positions=new s.BufferViewVec3f(t.positions),this._components=n,this._componentIntersectionData=new Array(n.count)}var o=i.prototype;return o.getComponentAabb=function(t,n){if(e.isSome(this._perComponentAabbs)){for(let e=0;e<6;e++)n[e]=this._perComponentAabbs[6*t+e];return n}return this._computePerComponentAabbs(),this.getComponentAabb(t,n)},o.getComponentPositions=function(t,e){e.indices=this._indices,e.data=this._positions.typedBuffer,e.stride=this._positions.typedBufferStride,e.startIndex=this._components.offsets[t],e.endIndex=this._components.offsets[t+1]},o.intersect=function(t,i,o,s,p,m,u){const b={data:this._positions.typedBuffer,stride:this._positions.typedBufferStride,size:3},_=this._indices,l=this._components.offsets,d=c.computeInvDir(t,i,f),y=t[2],C=i[2];this._components.visibility.forEachComponent((f=>{if(!a.getVisibility(this._components.pickability,f))return!0;const A=this.getComponentAabb(f,h);if(e.isSome(m)){const n=m[f];e.isSome(p)?p.componentOffset=n:(t[2]=y-n,i[2]=C-n)}if(e.isSome(p)&&p.applyToAabb(A),!c.intersectAabbInvDir(A,t,d,o))return!0;const g=l[f]/3,I=l[f+1]/3,B=(t,e,i)=>{u(f,t,n.transformMat3(e,e,s),i)},D=I-g;return e.isNone(p)&&D>r.componentMinimalSizeForIntersectionData?(null==this._componentIntersectionData[f]&&(this._componentIntersectionData[f]=new r.ComponentIntersectionData(this._indices,g,I,b)),this._componentIntersectionData[f].intersectRay({r0:t,r1:i},B)):c.intersectTriangles(t,i,g,I,_,b,void 0,p,B),!0}))},o._computePerComponentAabbs=function(){const t=this._components.count;this._perComponentAabbs=new Float32Array(6*t);const e=this._indices,n=this._positions.typedBuffer,i=this._positions.typedBufferStride,o=this._components.offsets;let s=0;for(let r=0;r<t;r++){const t=o[r],a=o[r+1];let p=1/0,c=1/0,m=1/0,f=-1/0,h=-1/0,u=-1/0;for(let o=t;o<a;o++){const t=e[o]*i,s=n[t],r=n[t+1],a=n[t+2];p=Math.min(p,s),c=Math.min(c,r),m=Math.min(m,a),f=Math.max(f,s),h=Math.max(h,r),u=Math.max(u,a)}this._perComponentAabbs[s++]=p,this._perComponentAabbs[s++]=c,this._perComponentAabbs[s++]=m,this._perComponentAabbs[s++]=f,this._perComponentAabbs[s++]=h,this._perComponentAabbs[s++]=u}},t._createClass(i,[{key:"positions",get:function(){return this._positions}},{key:"indices",get:function(){return this._indices}}]),i}();const f=i.create(),h=o.create();return m}));
