@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 6 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{identity as e,scale as t}from"../../../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as r}from"../../../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{ONES as i,fromArray as a,create as n}from"../../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{ONES as o}from"../../../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{computeTranslationToOriginAndRotation as s}from"../../../../../../geometry/projection/computeTranslationToOriginAndRotation.js";import{create as l,size as m}from"../../../../../../geometry/support/aaBoundingBox.js";import{defaultPrimitive as d}from"../../../../../../symbols/support/ObjectSymbol3DLayerResource.js";import{objectSymbolLayerPrimitiveBoundingBox as c,objectSymbolLayerSizeWithResourceSize as p}from"../../../../../../symbols/support/symbolLayerUtils3D.js";import{computeObjectScale as u}from"../../graphicUtils.js";import{isValidPrimitive as h}from"../../primitiveObjectSymbolUtils.js";import{PipelineCommand as y}from"../PipelineCommand.js";import{readMapCoordinates as f,readObjectIds as _}from"../featureData/processingUtils.js";import{createPrimitiveGeometry as b}from"./primitiveObjectUtils.js";import{CullFaceOptions as C}from"../../../../webgl-engine/lib/basicInterfaces.js";import{DefaultMaterialParameters as g,isTransparent as x}from"../../../../webgl-engine/materials/DefaultMaterial.js";import{schematicMRRFactors as v}from"../../../../webgl-engine/materials/pbrUtils.js";class w{constructor(e,t){this._loaded=!1,this._loadingPromise=null,this._primitiveMaterialId=null,this._lodRendererId=null,this._context=null,this._symbolLayer=null,this._primitive=null,this._context=t,this._symbolLayer=e}_destroy(){this._lodRendererId=null,this._primitiveMaterialId=null}get loaded(){return this._loaded}get _isPrimitive(){return null!=this._primitive}load(){return null==this._loadingPromise&&(this._loadingPromise=this._load()),this._loadingPromise}async _load(){const e=this._context.renderCommandContext,t={physicalBasedRenderingEnabled:!0,slicePlaneEnabled:!1,castShadows:!0},r=this._getLayerOpacity();let a={usePBR:t.physicalBasedRenderingEnabled,isSchematic:!0,mrrFactors:v,ambient:i,diffuse:i,hasSlicePlane:t.slicePlaneEnabled,castShadows:t.castShadows,layerOpacity:r,offsetTransparentBackfaces:!1,screenSizePerspective:{}};if(a.externalColor=o,a.isInstanced=!0,this._isPrimitive){const e=new g;e.layerOpacity=r,a={...a,cullFace:P(x(e))}}const n=await e.createMaterial({type:"default",parameters:a}),s=this._symbolLayer.resource;this._primitive=s&&h(s?.primitive)?s.primitive:d;const l=b(this._primitive,n);this._lodRendererId=await e.createLodRenderer(l),this._primitiveMaterialId=n,this._loaded=!0}async createDestroyCommand(){const{_lodRendererId:e,_primitiveMaterialId:t,_context:r}=this,i=r.renderCommandContext,a=[];return null!=e&&a.push(i.destroyLodRenderer(e)),null!=t&&a.push(i.destroyMaterial(t)),new y(i,i.mergeRenderCommandBuffers(a),[()=>this._destroy()])}async createAddCommand(e){const t=this._context,{renderCommandContext:r,mainThreadDelegate:i}=t;if(null==this._lodRendererId)throw new Error("expected lod renderer id to not be null");const{featureCount:n}=e;if(0===n)return t.createPipelineCommand();const o=this._isPrimitive,s=this._primitive||d,u=l(c(s)),h=a(m(u)),y=a(p(h,{isPrimitive:o,width:100,depth:null,height:null})),b=new Float64Array(16*n),C=new Float64Array(16*n),g=f(e),x=await i.applyElevationAlignmentTo(g);for(let a=0;a<n;++a){const e=a,t=x[3*a+0],r=x[3*a+1],i=x[3*a+2],n=this._computeGlobalTransform(t,r,i,this._context.viewSpatialReference,T),o=this._computeLocalTransform(y,h,j);this._writeMatrixToTypedBuffer(b,e,o),this._writeMatrixToTypedBuffer(C,e,n)}const v=_(e),w=new Uint8Array(n);e.getVisibilityArray(w);const P={featureIds:new Uint32Array(v),visibility:w,localTransforms:b,globalTransforms:C};return t.createPipelineCommand(r.addLodInstances(this._lodRendererId,e.id,P))}async createRemoveCommand(e){const{_context:t,_lodRendererId:r}=this,i=t.renderCommandContext;return null==r?t.createPipelineCommand():t.createPipelineCommand(i.removeLodInstances(r,e))}async createUpdateVisibilityCommand(e){const{_lodRendererId:t,_context:r}=this,i=r.renderCommandContext;if(null==t)return r.createPipelineCommand();const a=new Uint8Array(e.featureCount);return e.getVisibilityArray(a),r.createPipelineCommand(i.updateVisibility(t,e.id,a))}async createUpdateLayerViewOpacityCommand(e){const{_context:t}=this,r=t.renderCommandContext,i=this._primitiveMaterialId;if(null==i)return t.createPipelineCommand();const a=this._getLayerOpacity();let n={layerOpacity:a};if(this._isPrimitive){const e=new g;e.layerOpacity=a,n={...n,cullFace:P(x(e))}}return t.createPipelineCommand(r.updateMaterial({type:"default",materialId:i,parameters:n}))}async createUpdateElevationCommand(e){const{_context:t,_lodRendererId:r}=this,{renderCommandContext:i,mainThreadDelegate:a}=t,{featureCount:n,id:o}=e;if(null==r||0===n)return t.createPipelineCommand();const s=new Float64Array(16*n),l=f(e),m=await a.applyElevationAlignmentTo(l);for(let d=0;d<n;++d){const e=d,t=m[3*d+0],r=m[3*d+1],i=m[3*d+2],a=this._computeGlobalTransform(t,r,i,this._context.viewSpatialReference,T);this._writeMatrixToTypedBuffer(s,e,a)}return t.createPipelineCommand(i.updateLodInstancesData(r,o,s))}_writeMatrixToTypedBuffer(e,t,r){let i=16*t;for(let a=0;a<16;a++)e[i++]=r[a]}_computeGlobalTransform(e,t,r,i,a){return I[0]=e,I[1]=t,I[2]=r,s(i,I,a,this._context.renderSpatialReference),a}_computeLocalTransform(t,r,i){return e(i),this._applyObjectScale(t,r,i),i}_applyObjectScale(e,r,i){const a=u(e,e,r,this._context.renderCoordsHelper.unitInMeters);1===a[0]&&1===a[1]&&1===a[2]||t(i,i,a)}_getLayerOpacity(){return this._context.layerViewInfo.fullOpacity}}function P(e){return e?C.None:C.Back}const I=n(),j=r(),T=r();export{w as ObjectSymbolLayerRenderer};