UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 2.22 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{clamp as t}from"../../../../core/mathUtils.js";import{i as n,c as o,u as r}from"../../../../chunks/vec32.js";import{create as e}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{add as i,elementwiseProduct as s,scalarProduct as c}from"../lib/LongVectorMath.js";import{MainLight as f,FillLight as h,AmbientLight as a,SphericalHarmonicsAmbientLight as g}from"./Lightsources.js";function u(t){return(t+1)*(t+1)}function l(n){return t(Math.floor(Math.sqrt(n)-1),0,2)}function m(t,n,o){const r=t[0],e=t[1],i=t[2],s=o||[];return s.length=u(n),n>=0&&(s[0]=.28209479177),n>=1&&(s[1]=.4886025119*r,s[2]=.4886025119*i,s[3]=.4886025119*e),n>=2&&(s[4]=1.09254843059*r*e,s[5]=1.09254843059*e*i,s[6]=.31539156525*(3*i*i-1),s[7]=1.09254843059*r*i,s[8]=.54627421529*(r*r-e*e)),s}function p(t,n){const o=u(t),r=n||{r:[],g:[],b:[]};r.r.length=r.g.length=r.b.length=o;for(let e=0;e<o;e++)r.r[e]=r.g[e]=r.b[e]=0;return r}function b(t,n){const o=l(n.r.length);for(const e of t)r(P,e.direction),m(P,o,v),s(v,w),c(v,e.intensity[0],I),i(n.r,I),c(v,e.intensity[1],I),i(n.g,I),c(v,e.intensity[2],I),i(n.b,I);return n}function y(t,n){m(P,0,v);for(const o of t)n.r[0]+=v[0]*w[0]*o.intensity[0]*4*Math.PI,n.g[0]+=v[0]*w[0]*o.intensity[1]*4*Math.PI,n.b[0]+=v[0]*w[0]*o.intensity[2]*4*Math.PI;return n}function M(t,r,e,s){p(r,s),n(e.intensity,0,0,0);let c=!1;const u=S,l=d,m=j;u.length=0,l.length=0,m.length=0;for(const n of t)n instanceof f&&!c?(o(e.direction,n.direction),o(e.intensity,n.intensity),e.specularStrength=n.specularStrength,e.environmentStrength=n.environmentStrength,e.castShadows=n.castShadows,c=!0):n instanceof f||n instanceof h?u.push(n):n instanceof a?l.push(n):n instanceof g&&m.push(n);b(u,s),y(l,s);for(const n of m)i(s.r,n.r),i(s.g,n.g),i(s.b,n.b)}const S=[],d=[],j=[],v=[0],I=[0],P=e(),w=[3.141593,2.094395,2.094395,2.094395,.785398,.785398,.785398,.785398,.785398];export{M as combineLights,m as computeCoefficients,p as initSHCoefficients,u as numberOfCoefficients,l as orderFromNumberOfCoefficients,y as projectAmbientLights,b as projectFillLights};