/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{normalize as e,set as t,scale as r,add as i}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{fromValues as s,create as a}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{fromValues as n}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{center as o,scale as p}from"../../../../geometry/support/aaBoundingBox.js";import{BufferViewVec3f as c}from"../../../../geometry/support/buffer/BufferView.js";import{isColorOrOLID as h,isColor as l}from"../core/shaderLibrary/ShaderOutput.js";import u from"../lib/GLMaterial.js";import{Material as m,MaterialParameters as f}from"../lib/Material.js";import{intersectTriangleGeometry as g}from"../lib/RayIntersections.js";import{assert as d}from"../lib/Util.js";import{writeAttributes as b,writePosition as _}from"./internal/bufferWriterUtils.js";import{getLayout as S,ShadedColorMaterialTechnique as j}from"../shaders/ShadedColorMaterialTechnique.js";import{ShadedColorMaterialTechniqueConfiguration as w}from"../shaders/ShadedColorMaterialTechniqueConfiguration.js";import{alphaCutoff as T}from"../../../../webscene/support/AlphaCutoff.js";class x extends m{constructor(e){super(e,D),this._configuration=new w,this.supportsEdges=!0,this._pp0=s(0,0,1),this._pp1=s(0,0,0),this.produces=new Map([[2,e=>8===e||h(e)&&!this.parameters.transparent],[4,e=>h(e)&&this.parameters.transparent&&this.parameters.writeDepth],[9,e=>h(e)&&this.parameters.transparent&&!this.parameters.writeDepth]])}getConfiguration(e,t){return super.getConfiguration(e,t,this._configuration),this._configuration.cullFace=this.parameters.cullFace,this._configuration.hasSlicePlane=this.parameters.hasSlicePlane,this._configuration.transparent=this.parameters.transparent,this._configuration.writeDepth=this.parameters.writeDepth,this._configuration.screenSizeEnabled=this.parameters.screenSizeEnabled,this._configuration.shadingEnabled=this.parameters.shadingEnabled,this._configuration.terrainDepthTest=t.terrainDepthTest&&l(e),this._configuration.cullAboveTerrain=t.cullAboveTerrain,this._configuration}get visible(){return this.parameters.color[3]>=T}intersect(e,t,r,i,s,a){this._intersect(e,r,i,s,a)}intersectDraped(e,t,r,i){return this._pp0[0]=this._pp1[0]=r[0],this._pp0[1]=this._pp1[1]=r[1],this._intersect(e,t,this._pp0,this._pp1,i)}_intersect(e,s,a,n,c){if(this.parameters.screenSizeEnabled){const h=e.attributes.get("offset"),l={applyToVertex:(e,a,n,o)=>{const p=t(E,h.data[3*o],h.data[3*o+1],h.data[3*o+2]),c=t(M,e,a,n);return r(p,p,this.parameters.screenSizeScale*(s.camera?.computeScreenPixelSizeAt(p)??1)),i(c,c,p),[c[0],c[1],c[2]]},applyToAabb:e=>{const t=o(e,E);return p(e,this.parameters.screenSizeScale*(s.camera?.computeScreenPixelSizeAt(t)??1))}};g(e,s,a,n,l,c)}else g(e,s,a,n,void 0,c)}createGLMaterial(e){return new z(e)}createBufferWriter(){return new y(S(this.parameters))}}class z extends u{beginSlot(e){return this.getTechnique(j,e)}}class D extends f{constructor(){super(...arguments),this.color=n(1,1,1,1),this.shadingTint=n(0,0,0,.25),this.shadingDirection=e(a(),[.5,-.5,-.5]),this.screenSizeScale=14,this.forceTransparentMode=!1,this.writeDepth=!0,this.hasSlicePlane=!1,this.cullFace=0,this.screenSizeEnabled=!1,this.shadingEnabled=!0}get transparent(){return this.color[3]<1||this.forceTransparentMode}}class y{constructor(e){this.layout=e}elementCount(e){return e.get("position").indices.length}write(e,t,r,i,s,a){const n=b(r,i,this.layout,e,t,s,a),o=s.getField("offset",c);if(o&&r.has("offset")){const e=r.get("offset");d(3===e.size),_(e,t,o,a)}return n}}const E=a(),M=a();export{D as Parameters,x as ShadedColorMaterial};
