text: // All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  // See https://js.arcgis.com/4.8/esri/copyright.txt for details.
  //>>built
  define("require exports ../../../../core/tsSupport/extendsHelper ../../../../Color ../../../../geometry/support/aaBoundingBox ../../../../geometry/support/MeshComponent ../../../../geometry/support/webMercatorUtils ../../../../geometry/support/meshUtils/projection ./ElevationAligners ./Graphics3DObject3DGraphicLayer ./Graphics3DSymbolCommonCode ./Graphics3DSymbolLayer ../support/edgeUtils ../support/symbolColorUtils ../../lib/glMatrix ../../support/debugFlags ../../support/projectionUtils ../../webgl-engine/Stage ../../webgl-engine/lib/Geometry ../../webgl-engine/lib/GeometryData ../../webgl-engine/lib/Object3D ../../webgl-engine/lib/Texture ../../webgl-engine/lib/Util ../../webgl-engine/materials/DefaultMaterial ../../webgl-engine/materials/NativeLineMaterial".split(" "),
  function(K,ja,S,L,T,U,V,W,X,Y,r,Z,aa,ba,h,M,ca,t,G,H,da,ea,fa,ga,N){var m=fa.VertexAttrConstants;K=function(u){function e(){var a=null!==u&&u.apply(this,arguments)||this;a._edgeStageObjects=new Set;a._materials={};a._textures={};return a}S(e,u);e.prototype._prepareResources=function(){M.DRAW_MESH_GEOMETRY_NORMALS&&(this._debugVertexNormalMaterial=new N({color:[1,0,1,1]},"debugVertexNormal"),this._debugFaceNormalMaterial=new N({color:[0,1,1,1]},"debugFAceNormal"));this.resolve()};e.prototype.destroy=
  function(){u.prototype.destroy.call(this);this.isFulfilled()||this.reject();for(var a in this._materials)this._context.stage.remove(t.ModelContentType.MATERIAL,this._materials[a].material.id);for(a in this._textures)this._context.stage.remove(t.ModelContentType.TEXTURE,this._textures[a].id);this._materials={};this._textures={}};e.prototype.createGraphics3DGraphic=function(a){var b=a.graphic;if("mesh"!==b.geometry.type)return this._logWarning("unsupported geometry type for fill on mesh-3d symbol: "+
  b.geometry.type),null;if(!this._validateGeometry(b.geometry))return null;var c="graphic"+b.uid,d=this.getGraphicElevationContext(b);return this._createAs3DShape(b,a.renderingInfo,d,c,b.uid)};e.prototype.layerPropertyChanged=function(a,b,c){if("opacity"===a){b=this._getLayerOpacity();for(var d in this._materials){c=this._materials[d];c.material.setParameterValues({layerOpacity:b});var g=c.material.getParameterValues();this._setMaterialTransparentParameter(g);c.material.setParameterValues({transparent:g.transparent})}if(0<
  this._edgeStageObjects.size){var v=this._context.stage.view.getEdgeView(),k=this._getLayerOpacity();this._edgeStageObjects.forEach(function(a){v.updateAllComponentOpacities(a,[k])})}return!0}if("elevationInfo"===a){this._updateElevationContext();for(g in b)if(a=b[g],d=c(a))a=this.getGraphicElevationContext(a.graphic),d.needsElevationUpdates=r.needsElevationUpdates3D(a.mode),d.elevationContext.set(a);return!0}return!1};e.prototype._requiresVertexColors=function(){return this._isPropertyDriven("color")||
  this._isPropertyDriven("opacity")};e.prototype._colorUid=function(a){a=a.material&&a.material.color;if(!a)return"-";if(a)switch(a.type){case "value":return a.value.toHex();case "image":return a.uid}};e.prototype._materialProperties=function(a,b){a=this._requiresVertexColors();var c=b.material&&b.material.color;b=this._colorUid(b);return{hasVertexColors:a,color:c,uid:"vc:"+a+",cmuid:"+b}};e.prototype._setInternalColorValueParameters=function(a,b){b.diffuse=L.toUnitRGB(a.value);b.opacity=a.value.a};
  e.prototype._setInternalColorImageParameters=function(a,b,c){var d=a.url;if(d){var g=this._textures[a.uid];g||(g=new ea(d,b+"_"+a.uid+"_tex",{mipmap:!0,wrapClamp:!1,noUnpackFlip:!0}),this._textures[a.uid]=g,this._context.stage.add(t.ModelContentType.TEXTURE,g));c.textureId=g.id}};e.prototype._setInternalMaterialParameters=function(a,b,c){if(a=a.material&&a.material.color)switch(a.type){case "value":this._setInternalColorValueParameters(a,c);break;case "image":this._setInternalColorImageParameters(a,
  b,c)}};e.prototype._setExternalMaterialParameters=function(a){if(this._isPropertyDriven("color"))a.externalColor=O;else{var b=this.symbol.material?L.toUnitRGBA(this.symbol.material.color):O;a.externalColor=b}if(b=this.symbol.material&&this.symbol.material.colorMixMode)a.colorMixMode=b};e.prototype._getOrCreateMaterial=function(a,b){a=this._materialProperties(a,b);var c=this._materials[a.uid];if(c)return c.material;var c=this._getStageIdHint(),d={specular:P,symbolColors:a.hasVertexColors,ambient:P,
  diffuse:ha,opacity:1,doubleSided:!0,doubleSidedType:"winding-order",cullFace:"none",layerOpacity:this._getLayerOpacity()};this._setInternalMaterialParameters(b,c,d);this._setExternalMaterialParameters(d);this._setMaterialTransparentParameter(d);c=new ga(d,c+"_"+a.uid+"_mat");b=b.material&&b.material.color&&"value"===b.material.color.type&&b.material.color.value;this._materials[a.uid]={geometryOpacity:b?b.a:1,material:c};this._context.stage.add(t.ModelContentType.MATERIAL,c);return c};e.prototype._setMaterialTransparentParameter=
  function(a){this._isPropertyDriven("opacity")&&(a.transparent=!0);a.transparent=1>a.layerOpacity||1>a.opacity||a.externalColor&&1>a.externalColor[3]};e.prototype._addDebugNormals=function(a,b,c,d){var g=b.length,v=a.spatialReference.isWGS84?20015077/180:1,k=.1*Math.max(a.extent.width*v,a.extent.height*v,a.extent.zmax-a.extent.zmin),e=[],C=[];a=[];for(var v=[],I=0;I<g;I++)for(var z=b[I],w=z.data.getAttribute(m.POSITION),J=z.data.getAttribute(m.NORMAL),x=z.data.getIndices(m.POSITION),z=z.data.getIndices(m.NORMAL),
  w=w.data,J=J.data,n=0;n<x.length;n++){for(var y=3*x[n],r=3*z[n],l=0;3>l;l++)e.push(w[y+l]);for(l=0;3>l;l++)e.push(w[y+l]+J[r+l]*k);C.push(C.length);C.push(C.length);if(0===n%3){this._calculateFaceNormal(w,x,n,A);this._getFaceVertices(w,x,n,f,B,D);h.vec3d.add(f,B);h.vec3d.add(f,D);h.vec3d.scale(f,1/3);for(l=0;3>l;l++)a.push(f[l]);for(l=0;3>l;l++)a.push(f[l]+A[l]*k);v.push(v.length);v.push(v.length)}}g=(q={},q[m.POSITION]={data:new Float64Array(e),size:3},q);q=(p={},p[m.POSITION]=new Uint32Array(C),
  p);p=new H(g,q,void 0,"line");p=new G(p,"debugVertexNormal");p.singleUse=!0;b.push(p);c.push([this._debugVertexNormalMaterial]);d.push(h.mat4d.create(d[0]));g=(t={},t[m.POSITION]={data:new Float64Array(a),size:3},t);q=(u={},u[m.POSITION]=new Uint32Array(v),u);p=new H(g,q,void 0,"line");p=new G(p,"debugFaceNormal");p.singleUse=!0;b.push(p);c.push([this._debugFaceNormalMaterial]);d.push(h.mat4d.create(d[0]));var q,p,t,u};e.prototype._createAs3DShape=function(a,b,c,d,g){var e=this;a=a.geometry;if("mesh"!==
  a.type)return null;var k=this._createGeometryInfo(a,b,d);if(!k)return null;b=k.geometries;var f=k.materials,h=k.transformations,k=k.objectTransformation;M.DRAW_MESH_GEOMETRY_NORMALS&&this._addDebugNormals(a,b,f,h);d=new da({geometries:b,materials:f,transformations:h,castShadow:!0,metadata:{layerUid:this._context.layer.uid,graphicId:g},idHint:d});d.setObjectTransformation(k);var m=function(a){var b=e._context.stage.view.getEdgeView();if(b){b.removeObject(a);e._edgeStageObjects.delete(a);var c=aa.createMaterial(b,
  e.symbol,e._getLayerOpacity());c&&(e._edgeStageObjects.add(a),b.addObject(a,[c],{mergeGeometries:!0}))}};m(d);g=function(a,b,c,d,g){b=X.perObjectElevationAligner(a,b,c,d,g);m(a);return b};b=new Y(this,d,b,null,null,g,c);b.needsElevationUpdates=r.needsElevationUpdates3D(c.mode);c=a.extent.center.clone();c.z=0;b.elevationContext.centerPointInElevationSR=c;b.alignedTerrainElevation=g(d,b.elevationContext,this._context.elevationProvider,this._context.renderCoordsHelper,this._context.featureExpressionInfoContext);
  return b};e.prototype._createComponentNormals=function(a,b,c,d){switch(c.shading||"flat"){case "source":return this._createComponentNormalsSource(a,b,c,d);case "flat":return this._createComponentNormalsFlat(a,c,d);case "smooth":return this._createComponentNormalsSmooth(a,c,d)}};e.prototype._createComponentNormalsSource=function(a,b,c,d){if(!b)return this._createComponentNormalsFlat(a,c,d);c=!1;for(var g=0;g<d.length;g+=3){this._calculateFaceNormal(a,d,g,A);for(var e=0;3>e;e++){var k=3*d[g+e];f[0]=
  b[k+0];f[1]=b[k+1];f[2]=b[k+2];0>h.vec3d.dot(A,f)&&(b[k+0]=-b[k+0],b[k+1]=-b[k+1],b[k+2]=-b[k+2],c=!0)}}return{normals:b,indices:d,didFlipNormals:c}};e.prototype._createComponentNormalsFlat=function(a,b,c){b=new Float32Array(c.length);for(var d=new Uint32Array(3*c.length),g=0;g<c.length;g+=3)for(var e=this._calculateFaceNormal(a,c,g,A),k=0;3>k;k++)b[g+k]=e[k],d[g+k]=g/3;return{normals:b,indices:d,didFlipNormals:!1}};e.prototype._createComponentNormalsSmooth=function(a,b,c){b={};for(var d=0;d<c.length;d+=
  3)for(var g=this._calculateFaceNormal(a,c,d,A),e=0;3>e;e++){var k=c[d+e],f=b[k];f||(f={normal:h.vec3d.create(),count:0},b[k]=f);h.vec3d.add(f.normal,g);f.count++}a=new Float32Array(3*c.length);g=new Uint32Array(3*c.length);for(d=0;d<c.length;d++){k=c[d];f=b[k];1!==f.count&&(h.vec3d.normalize(h.vec3d.scale(f.normal,1/f.count)),f.count=1);for(e=0;3>e;e++)a[3*d+e]=f.normal[e];g[d]=d}return{normals:a,indices:g,didFlipNormals:!1}};e.prototype._getFaceVertices=function(a,b,c,d,e,f){var g=3*b[c+0],h=3*b[c+
  1];b=3*b[c+2];d[0]=a[g+0];d[1]=a[g+1];d[2]=a[g+2];e[0]=a[h+0];e[1]=a[h+1];e[2]=a[h+2];f[0]=a[b+0];f[1]=a[b+1];f[2]=a[b+2]};e.prototype._calculateFaceNormal=function(a,b,c,d){this._getFaceVertices(a,b,c,f,B,D);h.vec3d.subtract(B,f);h.vec3d.subtract(D,f);h.vec3d.cross(B,D,f);h.vec3d.normalize(f,d);return d};e.prototype._getOrCreateComponents=function(a){return a.components?a.components:ia};e.prototype._createPositionBuffer=function(a){var b=a.vertexAttributes.position,c=new Float64Array(b.length);r.reproject(a.vertexAttributes.position,
  0,a.spatialReference,c,0,this._context.renderSpatialReference,b.length/3);return c};e.prototype._createNormalBuffer=function(a,b){var c=a.vertexAttributes.normal;if(!c)return null;if("local"===this._context.layerView.view.viewingMode)return c;var d=a.vertexAttributes.position,e=new Float32Array(c.length);return W.projectNormalToECEF(c,d,b,a.spatialReference,e)};e.prototype._createColorBuffer=function(a){if(this._requiresVertexColors()){a=this._getVertexOpacityAndColor(a);var b=this.symbol.material&&
  this.symbol.material.colorMixMode||null,c=new Uint8Array(4);ba.encodeSymbolColor(a,b,c);return c}return null};e.prototype._createColorIndices=function(a,b){a=new Uint32Array(b.length);for(b=0;b<a.length;b++)a[b]=0;return a};e.prototype._createBuffers=function(a,b){var c=a.vertexAttributes&&a.vertexAttributes.position;if(!c)return this._logWarning("Mesh geometry must contain position vertex attributes"),null;var d=a.vertexAttributes.normal,e=a.vertexAttributes.uv;if(d&&d.length!==c.length)return this._logWarning("Mesh normal vertex buffer must contain the same number of elements as the position buffer"),
  null;if(e&&e.length/2!==c.length/3)return this._logWarning("Mesh uv vertex buffer must contain the same number of elements as the position buffer"),null;c=this._createPositionBuffer(a);b=this._createColorBuffer(b);d=this._createNormalBuffer(a,c);a=this._transformCenterLocal(a,c,d);return{positionBuffer:c,normalBuffer:d,uvBuffer:e,colorBuffer:b,objectTransformation:a}};e.prototype._transformCenterLocal=function(a,b,c){var d=a.extent.center,e=this._context.renderSpatialReference;E[0]=d.x;E[1]=d.y;E[2]=
  0;d=h.mat4d.create();ca.computeLinearTransformation(a.spatialReference,E,d,e);h.mat4d.inverse(d,Q);for(a=0;a<b.length;a+=3)f[0]=b[a+0],f[1]=b[a+1],f[2]=b[a+2],h.mat4d.multiplyVec3(Q,f),b[a+0]=f[0],b[a+1]=f[1],b[a+2]=f[2];if(c)for(h.mat4d.toMat3(d,F),h.mat3d.transpose(F,F),a=0;a<c.length;a+=3)f[0]=c[a+0],f[1]=c[a+1],f[2]=c[a+2],h.mat3d.multiplyVec3(F,f),c[a+0]=f[0],c[a+1]=f[1],c[a+2]=f[2];return d};e.prototype._validateFaces=function(a,b){a=a.vertexAttributes.position.length/3;if(b=b.faces){for(var c=
  -1,d=0;d<b.length;d++){var e=b[d];e>c&&(c=e)}if(a<=c)return this._logWarning("Vertex index "+c+" is out of bounds of the mesh position buffer"),!1}else if(0!==a%3)return this._logWarning("Mesh position buffer length must be a multiple of 9 if no component faces are defined (3 values per vertex * 3 vertices per triangle)"),!1;return!0};e.prototype._getOrCreateFaces=function(a,b){if(b.faces)return b.faces;a=new Uint32Array(a.vertexAttributes.position.length/3);for(b=0;b<a.length;b++)a[b]=b;return a};
  e.prototype._isOutsideClippingArea=function(a){if(!this._context.clippingExtent)return!1;var b=a.vertexAttributes&&a.vertexAttributes.position;if(!b)return!1;var c=this._context.elevationProvider.spatialReference,d=b.length/3;a.spatialReference.equals(c)||(b=new Float64Array(b.length),r.reproject(a.vertexAttributes.position,0,a.spatialReference,b,0,c,d));r.computeBoundingBox(b,0,d,R);return r.boundingBoxClipped(R,this._context.clippingExtent)};e.prototype._createGeometryInfo=function(a,b,c){if(!V.canProject(a,
  this._context.layerView.view.spatialReference))return this._logWarning("Geometry spatial reference is not compatible with the view"),null;if(this._isOutsideClippingArea(a))return null;var d=this._createBuffers(a,b);if(!d)return null;b=d.positionBuffer;for(var e=d.uvBuffer,f=d.colorBuffer,k=d.normalBuffer,d=d.objectTransformation,r=[],t=[],u=[],z=!1,w=0,A=this._getOrCreateComponents(a);w<A.length;w++){var x=A[w];if(!this._validateFaces(a,x))return null;var n=this._getOrCreateFaces(a,x);if(0!==n.length){var y=
  this._createComponentNormals(b,k,x,n);y.didFlipNormals&&(z=!0);var B=(l={},l[m.POSITION]={size:3,data:b},l[m.NORMAL]={size:3,data:y.normals},l),y=(q={},q[m.POSITION]=n,q[m.NORMAL]=y.indices,q);f&&(B[m.SYMBOLCOLOR]={size:4,data:f},y[m.SYMBOLCOLOR]=this._createColorIndices(x,n));a.vertexAttributes.uv&&(B[m.UV0]={size:2,data:e},y[m.UV0]=n);n=new H(B,y);n=new G(n,c+"_mesh");n.singleUse=!0;r.push(n);t.push(h.mat4d.identity());u.push([this._getOrCreateMaterial(a,x)])}}z&&this._logWarning("Normals have been automatically flipped to be consistent with the counter clock wise face winding order. It is better to generate mesh geometries that have consistent normals.");
  return{geometries:r,transformations:t,materials:u,objectTransformation:d};var l,q};return e}(Z);var ha=[1,1,1],O=[1,1,1,1],P=[0,0,0],E=h.vec3d.create(),f=h.vec3d.create(),B=h.vec3d.create(),D=h.vec3d.create(),A=h.vec3d.create(),Q=h.mat4d.create(),F=h.mat3d.create(),R=T.create(),ia=[new U];return K});