@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 8.16 kB
JavaScript
import has from"../../../../core/has.js";import{isSome as e}from"../../../../core/maybe.js";import{s as t,c as r,n as a,b as s,l as i,g as o,e as n,t as h}from"../../../../chunks/vec3.js";import{c,f as l}from"../../../../chunks/vec3f64.js";import{ViewingMode as u}from"../../../ViewingMode.js";import{newLayout as m}from"../../support/buffer/InterleavedLayout.js";import{ShaderOutput as p}from"../core/shaderLibrary/ShaderOutput.js";import{NormalsDoubleSidedMode as d}from"../core/shaderLibrary/shading/Normals.glsl.js";import{PBRMode as f}from"../core/shaderLibrary/shading/PhysicallyBasedRenderingParameters.glsl.js";import{CullFaceOptions as g}from"../lib/basicInterfaces.js";import{GLTextureMaterial as T}from"../lib/GLTextureMaterial.js";import{Material as _}from"../lib/Material.js";import{OITPolygonOffsetLimit as x}from"../lib/OrderIndependentTransparency.js";import{RenderSlot as b}from"../lib/RenderSlot.js";import{VertexAttribute as S}from"../lib/VertexAttribute.js";import{getVerticalOffsetObject3D as v}from"../lib/verticalOffsetUtils.js";import{DefaultBufferWriter as w}from"./DefaultBufferWriter.js";import{verticalOffsetAtDistance as O,intersectTriangleGeometry as M}from"./internal/MaterialUtil.js";import{DefaultMaterialTechnique as A,DefaultMaterialPassParameters as y}from"../shaders/DefaultMaterialTechnique.js";import{DefaultMaterialTechniqueConfiguration as C}from"../shaders/DefaultMaterialTechniqueConfiguration.js";import{RealisticTreeTechnique as R}from"../shaders/RealisticTreeTechnique.js";class E extends _{constructor(e){super(e,j),this.supportsEdges=!0,this._configuration=new C,this._vertexBufferLayout=L(this.parameters)}isVisibleForOutput(e){return e!==p.Shadow&&e!==p.ShadowExcludeHighlight&&e!==p.ShadowHighlight||this.parameters.castShadows}isVisible(){const t=this.parameters;if(!super.isVisible()||0===t.layerOpacity)return!1;const{instanced:r,hasVertexColors:a,hasSymbolColors:s,vvColorEnabled:i}=t,o=e(r)&&r.includes("color"),n="replace"===t.colorMixMode,h=t.opacity>0,c=t.externalColor&&t.externalColor[3]>0;return a&&(o||i||s)?!!n||h:a?n?c:h:o||i||s?!!n||h:n?c:h}getConfiguration(t,r){return this._configuration.output=t,this._configuration.hasNormalTexture=!!this.parameters.normalTextureId,this._configuration.hasColorTexture=!!this.parameters.textureId,this._configuration.hasVertexTangents=this.parameters.hasVertexTangents,this._configuration.instanced=!!this.parameters.instanced,this._configuration.instancedDoublePrecision=this.parameters.instancedDoublePrecision,this._configuration.vvSize=this.parameters.vvSizeEnabled,this._configuration.hasVerticalOffset=e(this.parameters.verticalOffset),this._configuration.hasScreenSizePerspective=e(this.parameters.screenSizePerspective),this._configuration.hasSlicePlane=this.parameters.hasSlicePlane,this._configuration.hasSliceHighlight=this.parameters.hasSliceHighlight,this._configuration.alphaDiscardMode=this.parameters.textureAlphaMode,this._configuration.normalType=this.parameters.normalType,this._configuration.transparent=this.parameters.transparent,this._configuration.writeDepth=this.parameters.writeDepth,e(this.parameters.customDepthTest)&&(this._configuration.customDepthTest=this.parameters.customDepthTest),this._configuration.hasOccludees=this.parameters.hasOccludees,this._configuration.cullFace=this.parameters.hasSlicePlane?g.None:this.parameters.cullFace,this._configuration.hasMultipassTerrain=r.multipassTerrain.enabled,this._configuration.cullAboveGround=r.multipassTerrain.cullAboveGround,this._configuration.hasModelTransformation=e(this.parameters.modelTransformation),t!==p.Color&&t!==p.Alpha||(this._configuration.hasVertexColors=this.parameters.hasVertexColors,this._configuration.hasSymbolColors=this.parameters.hasSymbolColors,this.parameters.treeRendering?this._configuration.doubleSidedMode=d.WindingOrder:this._configuration.doubleSidedMode=this.parameters.doubleSided&&"normal"===this.parameters.doubleSidedType?d.View:this.parameters.doubleSided&&"winding-order"===this.parameters.doubleSidedType?d.WindingOrder:d.None,this._configuration.instancedColor=e(this.parameters.instanced)&&this.parameters.instanced.includes("color"),this._configuration.receiveShadows=this.parameters.receiveShadows&&this.parameters.shadowMappingEnabled,this._configuration.receiveAmbientOcclusion=!!r.ssaoHelper.active&&this.parameters.receiveSSAO,this._configuration.vvColor=this.parameters.vvColorEnabled,this._configuration.textureAlphaPremultiplied=!!this.parameters.textureAlphaPremultiplied,this._configuration.pbrMode=this.parameters.usePBR?this.parameters.isSchematic?f.Schematic:f.Normal:f.Disabled,this._configuration.hasMetallicRoughnessTexture=!!this.parameters.metallicRoughnessTextureId,this._configuration.hasEmissionTexture=!!this.parameters.emissiveTextureId,this._configuration.hasOcclusionTexture=!!this.parameters.occlusionTextureId,this._configuration.offsetBackfaces=!(!this.parameters.transparent||!this.parameters.offsetTransparentBackfaces),this._configuration.transparencyPassType=r.transparencyPassType,this._configuration.enableOffset=r.camera.relativeElevation<x,this._configuration.snowCover=this.hasSnowCover(r),this._configuration.hasColorTextureTransform=!!this.parameters.colorTextureTransformMatrix,this._configuration.hasNormalTextureTransform=!!this.parameters.normalTextureTransformMatrix,this._configuration.hasEmissionTextureTransform=!!this.parameters.emissiveTextureTransformMatrix,this._configuration.hasOcclusionTextureTransform=!!this.parameters.occlusionTextureTransformMatrix,this._configuration.hasMetallicRoughnessTextureTransform=!!this.parameters.metallicRoughnessTextureTransformMatrix),this._configuration}hasSnowCover(t){return e(t.weather)&&t.weatherVisible&&"snowy"===t.weather.type&&"enabled"===t.weather.snowCover}intersect(c,l,m,p,d,f){if(e(this.parameters.verticalOffset)){const e=m.camera;t(z,l[12],l[13],l[14]);let c=null;switch(m.viewingMode){case u.Global:c=a(B,z);break;case u.Local:c=r(B,N)}let f=0;const g=s(G,z,e.eye),T=i(g),_=o(g,g,1/T);let x=null;this.parameters.screenSizePerspective&&(x=n(c,_)),f+=O(e,T,this.parameters.verticalOffset,x??0,this.parameters.screenSizePerspective),o(c,c,f),h(H,c,m.transform.inverseRotation),p=s(D,p,H),d=s(V,d,H)}M(c,m,p,d,v(m.verticalOffset),f)}requiresSlot(e,t){if(t===p.Color||t===p.Alpha||t===p.Depth||t===p.Normal||t===p.Shadow||t===p.ShadowHighlight||t===p.ShadowExcludeHighlight||t===p.Highlight||t===p.ObjectAndLayerIdColor){return e===(this.parameters.transparent?this.parameters.writeDepth?b.TRANSPARENT_MATERIAL:b.TRANSPARENT_DEPTH_WRITE_DISABLED_MATERIAL:b.OPAQUE_MATERIAL)||e===b.DRAPED_MATERIAL}return!1}createGLMaterial(e){return new I(e)}createBufferWriter(){return new w(this._vertexBufferLayout)}}class I extends T{constructor(e){super({...e,...e.material.parameters})}_updateShadowState(e){e.shadowMap.enabled!==this._material.parameters.shadowMappingEnabled&&this._material.setParameters({shadowMappingEnabled:e.shadowMap.enabled})}_updateOccludeeState(e){e.hasOccludees!==this._material.parameters.hasOccludees&&this._material.setParameters({hasOccludees:e.hasOccludees})}beginSlot(e){this._output!==p.Color&&this._output!==p.Alpha||(this._updateShadowState(e),this._updateOccludeeState(e));const r=this._material.parameters;this.updateTexture(r.textureId);const a=e.camera.viewInverseTransposeMatrix;return t(r.origin,a[3],a[7],a[11]),this._material.setParameters(this.textureBindParameters),this.ensureTechnique(r.treeRendering?R:A,e)}}class P extends y{constructor(){super(...arguments),this.initTextureTransparent=!1,this.treeRendering=!1,this.hasVertexTangents=!1}}const j=new P;function L(e){const t=m().vec3f(S.POSITION).vec3f(S.NORMAL),r=e.textureId||e.normalTextureId||e.metallicRoughnessTextureId||e.emissiveTextureId||e.occlusionTextureId;return e.hasVertexTangents&&t.vec4f(S.TANGENT),r&&t.vec2f(S.UV0),e.hasVertexColors&&t.vec4u8(S.COLOR),e.hasSymbolColors&&t.vec4u8(S.SYMBOLCOLOR),has("enable-feature:objectAndLayerId-rendering")&&t.vec4u8(S.OBJECTANDLAYERIDCOLOR),t}const D=c(),V=c(),N=l(0,0,1),B=c(),H=c(),z=c(),G=c();export{I as DefaultGLMaterial,E as DefaultMaterial,P as DefaultMaterialParameters};