/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../core/mathUtils","../../../../chunks/vec3","../../../../chunks/vec3f64","../lib/LongVectorMath","./Lightsources"],(function(t,n,e,i,o,r){"use strict";function c(t){return(t+1)*(t+1)}function s(t){return n.clamp(Math.floor(Math.sqrt(t)-1),0,2)}function a(t,n,e){const i=t[0],o=t[1],r=t[2],s=e||[];return s.length=c(n),n>=0&&(s[0]=.28209479177),n>=1&&(s[1]=.4886025119*i,s[2]=.4886025119*r,s[3]=.4886025119*o),n>=2&&(s[4]=1.09254843059*i*o,s[5]=1.09254843059*o*r,s[6]=.31539156525*(3*r*r-1),s[7]=1.09254843059*i*r,s[8]=.54627421529*(i*i-o*o)),s}function f(t,n){const e=c(t),i=n||{r:[],g:[],b:[]};i.r.length=i.g.length=i.b.length=e;for(let o=0;o<e;o++)i.r[o]=i.g[o]=i.b[o]=0;return i}function h(t,n){const i=s(n.r.length);for(const r of t)e.negate(y,r.direction),a(y,i,m),o.elementwiseProduct(m,L),o.scalarProduct(m,r.intensity[0],p),o.add(n.r,p),o.scalarProduct(m,r.intensity[1],p),o.add(n.g,p),o.scalarProduct(m,r.intensity[2],p),o.add(n.b,p);return n}function u(t,n){a(y,0,m);for(const e of t)n.r[0]+=m[0]*L[0]*e.intensity[0]*4*Math.PI,n.g[0]+=m[0]*L[0]*e.intensity[1]*4*Math.PI,n.b[0]+=m[0]*L[0]*e.intensity[2]*4*Math.PI;return n}function g(t,n,i,c){f(n,c),e.set(i.intensity,0,0,0);let s=!1;const a=l,g=d,m=b;a.length=0,g.length=0,m.length=0;for(const o of t)o instanceof r.MainLight&&!s?(e.copy(i.direction,o.direction),e.copy(i.intensity,o.intensity),i.specularStrength=o.specularStrength,i.environmentStrength=o.environmentStrength,i.castShadows=o.castShadows,s=!0):o instanceof r.MainLight||o instanceof r.FillLight?a.push(o):o instanceof r.AmbientLight?g.push(o):o instanceof r.SphericalHarmonicsAmbientLight&&m.push(o);h(a,c),u(g,c);for(const e of m)o.add(c.r,e.r),o.add(c.g,e.g),o.add(c.b,e.b)}const l=[],d=[],b=[],m=[0],p=[0],y=i.create(),L=[3.141593,2.094395,2.094395,2.094395,.785398,.785398,.785398,.785398,.785398];t.combineLights=g,t.computeCoefficients=a,t.initSHCoefficients=f,t.numberOfCoefficients=c,t.orderFromNumberOfCoefficients=s,t.projectAmbientLights=u,t.projectFillLights=h,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
