@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 4.57 kB
JavaScript
import{clamp as e}from"../../../../core/mathUtils.js";import{isNone as t}from"../../../../core/maybe.js";import{fromValues as r}from"../../../../geometry/support/aaBoundingBox.js";import{newLayout as i}from"../../support/buffer/InterleavedLayout.js";import{ShaderOutput as a}from"../core/shaderLibrary/ShaderOutput.js";import{NormalsDoubleSidedMode as s}from"../core/shaderLibrary/shading/Normals.glsl.js";import o from"../lib/GLMaterial.js";import{Material as n}from"../lib/Material.js";import{isPathGeometry as h}from"../lib/PathGeometry.js";import{RenderSlot as c}from"../lib/RenderSlot.js";import{VertexAttribute as u}from"../lib/VertexAttribute.js";import{DefaultBufferWriter as l}from"./DefaultBufferWriter.js";import{vertexAttributeLocations as d,PathTechniqueConfiguration as p,PathTechnique as m,PathPassParameters as f}from"./PathTechnique.js";import{intersectAabbInvDir as b}from"./internal/MaterialUtil.js";class S extends n{constructor(e){super(e,new g),this.supportsEdges=!0,this._vertexAttributeLocations=d,this._configuration=new p,this._vertexBufferLayout=S.getVertexBufferLayout()}getConfiguration(e,t){return this._configuration.output=e,this._configuration.vvSize=this.parameters.vvSizeEnabled,this._configuration.vvColor=this.parameters.vvColorEnabled,this._configuration.vvOpacity=this.parameters.vvOpacityEnabled,this._configuration.hasSlicePlane=this.parameters.hasSlicePlane,this._configuration.transparent=this.parameters.transparent,this._configuration.hasOccludees=this.parameters.hasOccludees,e!==a.Color&&e!==a.Alpha||(this._configuration.doubleSidedMode=this.parameters.doubleSided&&"normal"===this.parameters.doubleSidedType?s.View:this.parameters.doubleSided&&"winding-order"===this.parameters.doubleSidedType?s.WindingOrder:s.None,this._configuration.receiveShadows=this.parameters.receiveShadows,this._configuration.receiveAmbientOcclusion=!!t.ssaoHelper.active&&this.parameters.receiveSSAO),this._configuration.transparencyPassType=t.transparencyPassType,this._configuration.hasMultipassTerrain=t.multipassTerrain.enabled,this._configuration.cullAboveGround=t.multipassTerrain.cullAboveGround,this._configuration}isVisibleForOutput(e){return e!==a.Shadow&&e!==a.ShadowExcludeHighlight&&e!==a.ShadowHighlight||this.parameters.castShadows}isVisible(){return super.isVisible()&&this.parameters.opacity>0}intersect(i,a,s,o,n,c){const u=i;if(!h(u))return;const l=u.path,d=[this.parameters.size[0],this.parameters.size[1]];if(this.parameters.vvSizeEnabled){const t=this.parameters.vvSizeOffset,r=this.parameters.vvSizeFactor,i=this.parameters.vvSizeMinSize,a=this.parameters.vvSizeMaxSize,s=l.sizeAttributeValue;d[0]*=e(t[0]+s*r[0],i[0],a[0]),d[1]*=e(t[2]+s*r[2],i[2],a[2])}const p=Math.max(d[0],d[1]),m=i.boundingInfo;if(t(m))return void this._intersectTriangles(l,d,o,n,c);const f=r(m.bbMin[0]-p,m.bbMin[1]-p,m.bbMin[2]-p,m.bbMax[0]+p,m.bbMax[1]+p,m.bbMax[2]+p),S=[n[0]-o[0],n[1]-o[1],n[2]-o[2]],v=Math.sqrt(S[0]*S[0]+S[1]*S[1]+S[2]*S[2]),g=[v/S[0],v/S[1],v/S[2]];b(f,o,g,s.tolerance)&&this._intersectTriangles(l,d,o,n,c)}_intersectTriangles(e,t,r,i,a){e.baked.size&&e.baked.size[0]===t[0]&&e.baked.size[1]===t[1]||e.baked.bake(t),e.baked.intersect(r,i,a)}createBufferWriter(){return new l(this._vertexBufferLayout)}requiresSlot(e,t){switch(t){case a.Shadow:case a.ShadowHighlight:case a.ShadowExcludeHighlight:if(!this.parameters.castShadows)return!1;case a.Color:case a.Alpha:case a.Depth:case a.Normal:case a.Highlight:case a.ObjectAndLayerIdColor:return e===(this.parameters.transparent?c.TRANSPARENT_MATERIAL:c.OPAQUE_MATERIAL)||e===c.DRAPED_MATERIAL;default:return!1}}createGLMaterial(e){return new v(e)}static getVertexBufferLayout(){return i().vec3f(u.POSITION).vec4f(u.PROFILERIGHT).vec4f(u.PROFILEUP).vec4f(u.PROFILEVERTEXANDNORMAL).vec4f(u.FEATUREVALUE)}}class v extends o{_updateOccludeeState(e){e.hasOccludees!==this._material.parameters.hasOccludees&&this._material.setParameters({hasOccludees:e.hasOccludees})}_updateShadowState(e){(t(this.technique)||e.shadowMap.enabled!==this.technique.configuration.receiveShadows)&&this._material.setParameters({receiveShadows:e.shadowMap.enabled})}beginSlot(e){return this._output!==a.Color&&this._output!==a.Alpha||(this._updateShadowState(e),this._updateOccludeeState(e)),this.ensureTechnique(m,e)}}class g extends f{constructor(){super(...arguments),this.doubleSided=!1,this.doubleSidedType="normal",this.receiveSSAO=!0,this.receiveShadows=!1,this.castShadows=!0,this.hasSlicePlane=!1,this.transparent=!1,this.hasOccludees=!1}}export{S as PathMaterial,g as PathMaterialParameters};