├── .eslintignore ├── src ├── ThirdParty │ └── when.d.ts ├── Material │ ├── materials.ts │ ├── Pass │ │ └── RGBShiftMaterial.ts │ ├── SkyAtmosphereMaterial.ts │ └── GeographicReprojectMaterial.ts ├── assets │ └── logo.png ├── Core │ ├── ProjectorMode.ts │ ├── cores.ts │ ├── defined.ts │ ├── SceneMode.ts │ ├── TileEdge.ts │ ├── defaultValue.ts │ ├── TerrainQuantization.ts │ ├── MapMode2D.ts │ ├── HeightmapEncoding.ts │ ├── isBlobUri.ts │ ├── isDataUri.ts │ ├── DefaultProxy.ts │ ├── resolveIncludes.ts │ ├── HeadingPitchRoll.ts │ ├── Interval.ts │ ├── KeyboardEventModifier.ts │ ├── RequestType.ts │ ├── CameraEventType.ts │ ├── Object3DCollection.ts │ ├── ImagerySplitDirection.ts │ ├── formatError.ts │ ├── getTimestamp.ts │ ├── Visibility.ts │ ├── Credit.ts │ ├── BoundingRectangle.ts │ ├── isCrossOriginUrl.ts │ ├── HeadingPitchRange.ts │ ├── Intersect.ts │ ├── clone.ts │ ├── RequestState.ts │ ├── getExtensionFromUri.ts │ ├── arrayFill.ts │ ├── parseResponseHeaders.ts │ ├── NearFarScalar.ts │ ├── getAbsoluteUri.ts │ ├── TerrainExaggeration.ts │ ├── RuntimeError.ts │ ├── objectToQuery.ts │ ├── destroyObject.ts │ ├── queryToObject.ts │ ├── TimeConstants.ts │ ├── binarySearch.ts │ ├── ComponentDatatype.ts │ ├── RequestErrorEvent.ts │ ├── createVerticesFromHeightmap.ts │ ├── DeveloperError.ts │ ├── Queue.ts │ ├── Ray.ts │ └── combine.ts ├── Shader │ ├── Builtin │ │ ├── Constants │ │ │ ├── epsilon1.glsl │ │ │ ├── epsilon2.glsl │ │ │ ├── epsilon3.glsl │ │ │ ├── epsilon4.glsl │ │ │ ├── epsilon5.glsl │ │ │ ├── epsilon6.glsl │ │ │ ├── epsilon7.glsl │ │ │ ├── passGlobe.glsl │ │ │ ├── passOpaque.glsl │ │ │ ├── passCompute.glsl │ │ │ ├── passOverlay.glsl │ │ │ ├── infinity.glsl │ │ │ ├── passEnvironment.glsl │ │ │ ├── passTranslucent.glsl │ │ │ ├── passCesium3DTile.glsl │ │ │ ├── passClassification.glsl │ │ │ ├── passTerrainClassification.glsl │ │ │ ├── passCesium3DTileClassification.glsl │ │ │ ├── sceneMode2D.glsl │ │ │ ├── sceneMode3D.glsl │ │ │ ├── sceneModeMorphing.glsl │ │ │ ├── passCesium3DTileClassificationIgnoreShow.glsl │ │ │ ├── sceneModeColumbusView.glsl │ │ │ ├── solarRadius.glsl │ │ │ ├── pi.glsl │ │ │ ├── twoPi.glsl │ │ │ ├── oneOverPi.glsl │ │ │ ├── piOverSix.glsl │ │ │ ├── piOverTwo.glsl │ │ │ ├── piOverFour.glsl │ │ │ ├── piOverThree.glsl │ │ │ ├── oneOverTwoPi.glsl │ │ │ ├── threePiOver2.glsl │ │ │ ├── degreesPerRadian.glsl │ │ │ ├── radiansPerDegree.glsl │ │ │ ├── depthRange.glsl │ │ │ └── webMercatorMaxLatitude.glsl │ │ ├── Functions │ │ │ ├── readDepth.glsl │ │ │ ├── cascadeDistance.glsl │ │ │ ├── cascadeColor.glsl │ │ │ ├── columbusViewMorph.glsl │ │ │ ├── ellipsoidWgs84TextureCoordinates.glsl │ │ │ ├── inverseGamma.glsl │ │ │ ├── cascadeWeights.glsl │ │ │ ├── cascadeMatrix.glsl │ │ │ ├── ellipsoidContainsPoint.glsl │ │ │ ├── reverseLogDepth.glsl │ │ │ ├── acesTonemapping.glsl │ │ │ ├── alphaWeight.glsl │ │ │ ├── backFacing.glsl │ │ │ ├── eyeOffset.glsl │ │ │ ├── luminance.glsl │ │ │ ├── gammaCorrect.glsl │ │ │ ├── geodeticSurfaceNormal.glsl │ │ │ ├── transformPlane.glsl │ │ │ ├── unpackDepth.glsl │ │ │ ├── defaultPbrMaterial.glsl │ │ │ ├── multiplyWithColorBalance.glsl │ │ │ ├── decompressTextureCoordinates.glsl │ │ │ ├── lineDistance.glsl │ │ │ ├── isEmpty.glsl │ │ │ ├── packDepth.glsl │ │ │ ├── isFull.glsl │ │ │ ├── pointAlongRay.glsl │ │ │ ├── shadowDepthCompare.glsl │ │ │ ├── saturation.glsl │ │ │ ├── HSBToRGB.glsl │ │ │ ├── writeDepthClamp.glsl │ │ │ ├── computePosition.glsl │ │ │ ├── HSLToRGB.glsl │ │ │ ├── getLambertDiffuse.glsl │ │ │ ├── approximateSphericalCoordinates.glsl │ │ │ ├── RGBToHSB.glsl │ │ │ ├── getDefaultMaterial.glsl │ │ │ ├── RGBToXYZ.glsl │ │ │ ├── unpackFloat.glsl │ │ │ ├── XYZToRGB.glsl │ │ │ ├── signNotZero.glsl │ │ │ ├── translucentPhong.glsl │ │ │ ├── planeDistance.glsl │ │ │ ├── nearFarScalar.glsl │ │ │ ├── RGBToHSL.glsl │ │ │ ├── tangentToEyeSpaceMatrix.glsl │ │ │ ├── hue.glsl │ │ │ ├── pbrSpecularGlossinessMaterial.glsl │ │ │ ├── latitudeToWebMercatorFraction.glsl │ │ │ ├── readNonPerspective.glsl │ │ │ ├── writeNonPerspective.glsl │ │ │ ├── sphericalHarmonics.glsl │ │ │ ├── getSpecular.glsl │ │ │ ├── eyeToWindowCoordinates.glsl │ │ │ ├── fog.glsl │ │ │ ├── transpose.glsl │ │ │ ├── pbrMetallicRoughnessMaterial.glsl │ │ │ ├── getWaterNoise.glsl │ │ │ ├── equalsEpsilon.glsl │ │ │ ├── translateRelativeToEye.glsl │ │ │ ├── modelToWindowCoordinates.glsl │ │ │ ├── antialias.glsl │ │ │ ├── eastNorthUpToEyeCoordinates.glsl │ │ │ ├── depthClamp.glsl │ │ │ ├── metersPerPixel.glsl │ │ │ ├── vertexLogDepth.glsl │ │ │ ├── writeLogDepth.glsl │ │ │ ├── phong.glsl │ │ │ ├── fastApproximateAtan.glsl │ │ │ └── branchFreeTernary.glsl │ │ ├── Structs │ │ │ ├── ray.glsl │ │ │ ├── depthRangeStruct.glsl │ │ │ ├── shadowParameters.glsl │ │ │ ├── pbrParameters.glsl │ │ │ ├── raySegment.glsl │ │ │ ├── material.glsl │ │ │ └── materialInput.glsl │ │ └── Shims-vue.d.ts │ ├── ShaderReplace.ts │ ├── SkyAtmosphereVS.glsl │ ├── SkyAtmosphereFS.glsl │ ├── CubeGlsl3Shader.ts │ ├── RGBShiftShader.ts │ └── envmap_fragment.ts ├── Map.ts ├── Extension │ ├── Extension.ts │ ├── ShaderChunkEx.ts │ ├── ShaderChunk │ │ └── uv_pars_vertex.ts │ └── Vector3Extension.ts ├── Scene │ ├── scenes.ts │ ├── PickDepth.ts │ ├── TerrainState.ts │ ├── ImageryState.ts │ ├── ContextLimits.ts │ ├── QuadtreeTileProvider.ts │ ├── QuadtreeOccluders.ts │ ├── OrthographicFrustumCamera.ts │ ├── QuadtreeTileLoadState.ts │ ├── Picking.ts │ ├── MapRenderer.ts │ ├── RenderCollection.ts │ ├── EffectComposerCollection.ts │ ├── CameraCopy.ts │ ├── PrimitiveCollection.ts │ ├── ShadowMode.ts │ └── Axis.ts ├── Shims-vue.d.ts ├── Renderer │ ├── BufferUsage.ts │ ├── Pass.ts │ ├── WebGL │ │ ├── WebGLProgram.d.ts │ │ ├── WebGLPrograms.d.ts │ │ └── utils.ts │ ├── ShaderPass.ts │ ├── ComputedShaderPass.ts │ ├── ComputedPass.ts │ └── DrawMeshCommand.ts ├── App.vue └── Widgets │ └── getElement.ts ├── .browserslistrc ├── public ├── favicon.ico ├── assets │ ├── logo.png │ └── skyBox │ │ ├── negX.jpg │ │ ├── negY.jpg │ │ ├── negZ.jpg │ │ ├── posX.jpg │ │ ├── posY.jpg │ │ └── posZ.jpg └── index.html ├── babel.config.js ├── .editorconfig ├── .prettierrc ├── .gitignore ├── .eslintrc.js ├── vue.config.js ├── README.md ├── tsconfig.json └── package.json /.eslintignore: -------------------------------------------------------------------------------- 1 | 2 | src/Renderer/WebGL -------------------------------------------------------------------------------- /src/ThirdParty/when.d.ts: -------------------------------------------------------------------------------- 1 | class when { 2 | 3 | } -------------------------------------------------------------------------------- /.browserslistrc: -------------------------------------------------------------------------------- 1 | > 1% 2 | last 2 versions 3 | not dead 4 | -------------------------------------------------------------------------------- /src/Material/materials.ts: -------------------------------------------------------------------------------- 1 | export { TileMaterial } from './TileMaterial'; 2 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pp123pp/threejs-map/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pp123pp/threejs-map/HEAD/src/assets/logo.png -------------------------------------------------------------------------------- /public/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pp123pp/threejs-map/HEAD/public/assets/logo.png -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/cli-plugin-babel/preset' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /public/assets/skyBox/negX.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pp123pp/threejs-map/HEAD/public/assets/skyBox/negX.jpg -------------------------------------------------------------------------------- /public/assets/skyBox/negY.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pp123pp/threejs-map/HEAD/public/assets/skyBox/negY.jpg -------------------------------------------------------------------------------- /public/assets/skyBox/negZ.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pp123pp/threejs-map/HEAD/public/assets/skyBox/negZ.jpg -------------------------------------------------------------------------------- /public/assets/skyBox/posX.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pp123pp/threejs-map/HEAD/public/assets/skyBox/posX.jpg -------------------------------------------------------------------------------- /public/assets/skyBox/posY.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pp123pp/threejs-map/HEAD/public/assets/skyBox/posY.jpg -------------------------------------------------------------------------------- /public/assets/skyBox/posZ.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pp123pp/threejs-map/HEAD/public/assets/skyBox/posZ.jpg -------------------------------------------------------------------------------- /src/Core/ProjectorMode.ts: -------------------------------------------------------------------------------- 1 | const ProjectorMode = { 2 | Perspective: 0, 3 | Orthographic: 1 4 | }; 5 | 6 | export { ProjectorMode }; 7 | -------------------------------------------------------------------------------- /src/Core/cores.ts: -------------------------------------------------------------------------------- 1 | export { ScreenSpaceEventType } from './ScreenSpaceEventType'; 2 | export { IntersectionTests } from './IntersectionTests'; 3 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | [*.{js,jsx,ts,tsx,vue}] 2 | indent_style = space 3 | indent_size = 2 4 | trim_trailing_whitespace = true 5 | insert_final_newline = true 6 | -------------------------------------------------------------------------------- /src/Core/defined.ts: -------------------------------------------------------------------------------- 1 | function defined (value: T): boolean { 2 | return value !== undefined && value !== null; 3 | } 4 | 5 | export { defined }; 6 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/epsilon1.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * 0.1 3 | * 4 | * @name czm_epsilon1 5 | * @glslConstant 6 | */ 7 | const float czm_epsilon1 = 0.1; 8 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/epsilon2.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * 0.01 3 | * 4 | * @name czm_epsilon2 5 | * @glslConstant 6 | */ 7 | const float czm_epsilon2 = 0.01; 8 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/epsilon3.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * 0.001 3 | * 4 | * @name czm_epsilon3 5 | * @glslConstant 6 | */ 7 | const float czm_epsilon3 = 0.001; 8 | -------------------------------------------------------------------------------- /src/Core/SceneMode.ts: -------------------------------------------------------------------------------- 1 | enum SceneMode { 2 | COLUMBUS_VIEW = 1, 3 | MORPHING = 0, 4 | SCENE2D = 2, 5 | SCENE3D = 3 6 | } 7 | export { SceneMode }; 8 | -------------------------------------------------------------------------------- /src/Map.ts: -------------------------------------------------------------------------------- 1 | export * from './Extension/Extension'; 2 | export * from './Scene/scenes'; 3 | export * from './Core/cores'; 4 | export * from './Material/materials'; 5 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/epsilon4.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * 0.0001 3 | * 4 | * @name czm_epsilon4 5 | * @glslConstant 6 | */ 7 | const float czm_epsilon4 = 0.0001; 8 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/epsilon5.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * 0.00001 3 | * 4 | * @name czm_epsilon5 5 | * @glslConstant 6 | */ 7 | const float czm_epsilon5 = 0.00001; 8 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/epsilon6.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * 0.000001 3 | * 4 | * @name czm_epsilon6 5 | * @glslConstant 6 | */ 7 | const float czm_epsilon6 = 0.000001; 8 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/epsilon7.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * 0.0000001 3 | * 4 | * @name czm_epsilon7 5 | * @glslConstant 6 | */ 7 | const float czm_epsilon7 = 0.0000001; 8 | -------------------------------------------------------------------------------- /src/Extension/Extension.ts: -------------------------------------------------------------------------------- 1 | export { Object3D } from './Object3DExtension'; 2 | export { Vector3 } from './Vector3Extension'; 3 | // export { ShaderChunk } from './ShaderChunkEx'; 4 | -------------------------------------------------------------------------------- /src/Shader/ShaderReplace.ts: -------------------------------------------------------------------------------- 1 | 2 | const varyingExp = /varying/g; 3 | const vertexOut = 'out'; 4 | 5 | const fragmentIn = 'in'; 6 | 7 | export { varyingExp, vertexOut, fragmentIn }; 8 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/readDepth.glsl: -------------------------------------------------------------------------------- 1 | float czm_readDepth(sampler2D depthTexture, vec2 texCoords) 2 | { 3 | return czm_reverseLogDepth(texture2D(depthTexture, texCoords).r); 4 | } 5 | -------------------------------------------------------------------------------- /src/Scene/scenes.ts: -------------------------------------------------------------------------------- 1 | export { WebMapTileServiceImageryProvider } from './WebMapTileServiceImageryProvider'; 2 | 3 | export { TileCoordinatesImageryProvider } from './TileCoordinatesImageryProvider'; 4 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Structs/ray.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * DOC_TBA 3 | * 4 | * @name czm_ray 5 | * @glslStruct 6 | */ 7 | struct czm_ray 8 | { 9 | vec3 origin; 10 | vec3 direction; 11 | }; 12 | -------------------------------------------------------------------------------- /src/Shims-vue.d.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/ban-types */ 2 | declare module '*.glsl' { 3 | 4 | const component: DefineComponent<{}, {}, any>; 5 | export default component; 6 | } 7 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "tabWidth": 4, 3 | "useTabs": false, 4 | "printWidth": 120, 5 | "space-before-function-paren": "off", 6 | "trailingComma":"none", 7 | "singleQuotes":true 8 | } 9 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Shims-vue.d.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/ban-types */ 2 | declare module '*.glsl' { 3 | const component: DefineComponent<{}, {}, any>; 4 | export default component; 5 | } 6 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Structs/depthRangeStruct.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * @name czm_depthRangeStruct 3 | * @glslStruct 4 | */ 5 | struct czm_depthRangeStruct 6 | { 7 | float near; 8 | float far; 9 | }; 10 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/cascadeDistance.glsl: -------------------------------------------------------------------------------- 1 | 2 | uniform vec4 shadowMap_cascadeDistances; 3 | 4 | float czm_cascadeDistance(vec4 weights) 5 | { 6 | return dot(shadowMap_cascadeDistances, weights); 7 | } 8 | -------------------------------------------------------------------------------- /src/Scene/PickDepth.ts: -------------------------------------------------------------------------------- 1 | import { Scene } from './Scene'; 2 | 3 | class PickDepth { 4 | scene: Scene; 5 | constructor (scene: Scene) { 6 | this.scene = scene; 7 | } 8 | } 9 | 10 | export { PickDepth }; 11 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/passGlobe.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * The automatic GLSL constant for {@link Pass#GLOBE} 3 | * 4 | * @name czm_passGlobe 5 | * @glslConstant 6 | * 7 | * @see czm_pass 8 | */ 9 | const float czm_passGlobe = 2.0; 10 | -------------------------------------------------------------------------------- /src/Scene/TerrainState.ts: -------------------------------------------------------------------------------- 1 | enum TerrainState { 2 | FAILED = 0, 3 | UNLOADED = 1, 4 | RECEIVING = 2, 5 | RECEIVED = 3, 6 | TRANSFORMING = 4, 7 | TRANSFORMED = 5, 8 | READY = 6, 9 | } 10 | export { TerrainState }; 11 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/passOpaque.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * The automatic GLSL constant for {@link Pass#OPAQUE} 3 | * 4 | * @name czm_passOpaque 5 | * @glslConstant 6 | * 7 | * @see czm_pass 8 | */ 9 | const float czm_passOpaque = 7.0; 10 | -------------------------------------------------------------------------------- /src/Extension/ShaderChunkEx.ts: -------------------------------------------------------------------------------- 1 | import { GLSL3, ShaderChunk, ShaderMaterial } from 'three'; 2 | import uv_pars_vertex from './ShaderChunk/uv_pars_vertex'; 3 | 4 | const ShaderChunkGlsl3 = { 5 | uv_pars_vertex 6 | }; 7 | export { ShaderChunkGlsl3 }; 8 | -------------------------------------------------------------------------------- /src/Scene/ImageryState.ts: -------------------------------------------------------------------------------- 1 | export enum ImageryState { 2 | UNLOADED = 0, 3 | TRANSITIONING = 1, 4 | RECEIVED = 2, 5 | TEXTURE_LOADED = 3, 6 | READY = 4, 7 | FAILED = 5, 8 | INVALID = 6, 9 | PLACEHOLDER = 7, 10 | } 11 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/passCompute.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * The automatic GLSL constant for {@link Pass#COMPUTE} 3 | * 4 | * @name czm_passCompute 5 | * @glslConstant 6 | * 7 | * @see czm_pass 8 | */ 9 | const float czm_passCompute = 1.0; 10 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/passOverlay.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * The automatic GLSL constant for {@link Pass#OVERLAY} 3 | * 4 | * @name czm_passOverlay 5 | * @glslConstant 6 | * 7 | * @see czm_pass 8 | */ 9 | const float czm_passOverlay = 9.0; 10 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/infinity.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * DOC_TBA 3 | * 4 | * @name czm_infinity 5 | * @glslConstant 6 | */ 7 | const float czm_infinity = 5906376272000.0; // Distance from the Sun to Pluto in meters. TODO: What is best given lowp, mediump, and highp? 8 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/passEnvironment.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * The automatic GLSL constant for {@link Pass#ENVIRONMENT} 3 | * 4 | * @name czm_passEnvironment 5 | * @glslConstant 6 | * 7 | * @see czm_pass 8 | */ 9 | const float czm_passEnvironment = 0.0; 10 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/passTranslucent.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * The automatic GLSL constant for {@link Pass#TRANSLUCENT} 3 | * 4 | * @name czm_passTranslucent 5 | * @glslConstant 6 | * 7 | * @see czm_pass 8 | */ 9 | const float czm_passTranslucent = 8.0; 10 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/passCesium3DTile.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * The automatic GLSL constant for {@link Pass#CESIUM_3D_TILE} 3 | * 4 | * @name czm_passCesium3DTile 5 | * @glslConstant 6 | * 7 | * @see czm_pass 8 | */ 9 | const float czm_passCesium3DTile = 4.0; 10 | -------------------------------------------------------------------------------- /src/Core/TileEdge.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @private 3 | */ 4 | enum TileEdge { 5 | WEST= 0, 6 | NORTH= 1, 7 | EAST= 2, 8 | SOUTH= 3, 9 | NORTHWEST= 4, 10 | NORTHEAST= 5, 11 | SOUTHWEST= 6, 12 | SOUTHEAST= 7 13 | } 14 | 15 | export { TileEdge }; 16 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/passClassification.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * The automatic GLSL constant for {@link Pass#CLASSIFICATION} 3 | * 4 | * @name czm_passClassification 5 | * @glslConstant 6 | * 7 | * @see czm_pass 8 | */ 9 | const float czm_passClassification = 7.0; 10 | -------------------------------------------------------------------------------- /src/Extension/ShaderChunk/uv_pars_vertex.ts: -------------------------------------------------------------------------------- 1 | export default /* glsl */` 2 | #ifdef USE_UV 3 | 4 | #ifdef UVS_VERTEX_ONLY 5 | 6 | vec2 vUv; 7 | 8 | #else 9 | 10 | out vec2 vUv; 11 | 12 | #endif 13 | 14 | uniform mat3 uvTransform; 15 | 16 | #endif 17 | `; 18 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/passTerrainClassification.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * The automatic GLSL constant for {@link Pass#TERRAIN_CLASSIFICATION} 3 | * 4 | * @name czm_passTerrainClassification 5 | * @glslConstant 6 | * 7 | * @see czm_pass 8 | */ 9 | const float czm_passTerrainClassification = 3.0; 10 | -------------------------------------------------------------------------------- /src/Core/defaultValue.ts: -------------------------------------------------------------------------------- 1 | function defaultValue (a: T, b: T): T { 2 | if (a !== undefined && a !== null) { 3 | return a; 4 | } 5 | return b; 6 | } 7 | 8 | defaultValue.EMPTY_OBJECT = Object.freeze({}) as { 9 | [name: string]: any 10 | }; 11 | 12 | export { defaultValue }; 13 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/cascadeColor.glsl: -------------------------------------------------------------------------------- 1 | 2 | vec4 czm_cascadeColor(vec4 weights) 3 | { 4 | return vec4(1.0, 0.0, 0.0, 1.0) * weights.x + 5 | vec4(0.0, 1.0, 0.0, 1.0) * weights.y + 6 | vec4(0.0, 0.0, 1.0, 1.0) * weights.z + 7 | vec4(1.0, 0.0, 1.0, 1.0) * weights.w; 8 | } 9 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/passCesium3DTileClassification.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * The automatic GLSL constant for {@link Pass#CESIUM_3D_TILE_CLASSIFICATION} 3 | * 4 | * @name czm_passCesium3DTileClassification 5 | * @glslConstant 6 | * 7 | * @see czm_pass 8 | */ 9 | const float czm_passCesium3DTileClassification = 5.0; 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | 6 | # local env files 7 | .env.local 8 | .env.*.local 9 | 10 | # Log files 11 | npm-debug.log* 12 | yarn-debug.log* 13 | yarn-error.log* 14 | pnpm-debug.log* 15 | 16 | # Editor directories and files 17 | .idea 18 | .vscode 19 | *.suo 20 | *.ntvs* 21 | *.njsproj 22 | *.sln 23 | *.sw? 24 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/sceneMode2D.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * The constant identifier for the 2D {@link SceneMode} 3 | * 4 | * @name czm_sceneMode2D 5 | * @glslConstant 6 | * @see czm_sceneMode 7 | * @see czm_sceneModeColumbusView 8 | * @see czm_sceneMode3D 9 | * @see czm_sceneModeMorphing 10 | */ 11 | const float czm_sceneMode2D = 2.0; 12 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/sceneMode3D.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * The constant identifier for the 3D {@link SceneMode} 3 | * 4 | * @name czm_sceneMode3D 5 | * @glslConstant 6 | * @see czm_sceneMode 7 | * @see czm_sceneMode2D 8 | * @see czm_sceneModeColumbusView 9 | * @see czm_sceneModeMorphing 10 | */ 11 | const float czm_sceneMode3D = 3.0; 12 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/columbusViewMorph.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * DOC_TBA 3 | * 4 | * @name czm_columbusViewMorph 5 | * @glslFunction 6 | */ 7 | vec4 czm_columbusViewMorph(vec4 position2D, vec4 position3D, float time) 8 | { 9 | // Just linear for now. 10 | vec3 p = mix(position2D.xyz, position3D.xyz, time); 11 | return vec4(p, 1.0); 12 | } 13 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/ellipsoidWgs84TextureCoordinates.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * DOC_TBA 3 | * 4 | * @name czm_ellipsoidWgs84TextureCoordinates 5 | * @glslFunction 6 | */ 7 | vec2 czm_ellipsoidWgs84TextureCoordinates(vec3 normal) 8 | { 9 | return vec2(atan(normal.y, normal.x) * czm_oneOverTwoPi + 0.5, asin(normal.z) * czm_oneOverPi + 0.5); 10 | } 11 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Structs/shadowParameters.glsl: -------------------------------------------------------------------------------- 1 | struct czm_shadowParameters 2 | { 3 | #ifdef USE_CUBE_MAP_SHADOW 4 | vec3 texCoords; 5 | #else 6 | vec2 texCoords; 7 | #endif 8 | 9 | float depthBias; 10 | float depth; 11 | float nDotL; 12 | vec2 texelStepSize; 13 | float normalShadingSmooth; 14 | float darkness; 15 | }; 16 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/sceneModeMorphing.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * The constant identifier for the Morphing {@link SceneMode} 3 | * 4 | * @name czm_sceneModeMorphing 5 | * @glslConstant 6 | * @see czm_sceneMode 7 | * @see czm_sceneMode2D 8 | * @see czm_sceneModeColumbusView 9 | * @see czm_sceneMode3D 10 | */ 11 | const float czm_sceneModeMorphing = 0.0; 12 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/passCesium3DTileClassificationIgnoreShow.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * The automatic GLSL constant for {@link Pass#CESIUM_3D_TILE_CLASSIFICATION_IGNORE_SHOW} 3 | * 4 | * @name czm_passCesium3DTileClassificationIgnoreShow 5 | * @glslConstant 6 | * 7 | * @see czm_pass 8 | */ 9 | const float czm_passCesium3DTileClassificationIgnoreShow = 6.0; 10 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/sceneModeColumbusView.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * The constant identifier for the Columbus View {@link SceneMode} 3 | * 4 | * @name czm_sceneModeColumbusView 5 | * @glslConstant 6 | * @see czm_sceneMode 7 | * @see czm_sceneMode2D 8 | * @see czm_sceneMode3D 9 | * @see czm_sceneModeMorphing 10 | */ 11 | const float czm_sceneModeColumbusView = 1.0; 12 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/solarRadius.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * A built-in GLSL floating-point constant for one solar radius. 3 | * 4 | * @alias czm_solarRadius 5 | * @glslConstant 6 | * 7 | * @see CesiumMath.SOLAR_RADIUS 8 | * 9 | * @example 10 | * // GLSL declaration 11 | * const float czm_solarRadius = ...; 12 | */ 13 | const float czm_solarRadius = 695500000.0; 14 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/inverseGamma.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Converts a color in linear space to RGB space. 3 | * 4 | * @name czm_inverseGamma 5 | * @glslFunction 6 | * 7 | * @param {vec3} color The color in linear space. 8 | * @returns {vec3} The color in RGB space. 9 | */ 10 | vec3 czm_inverseGamma(vec3 color) { 11 | return pow(color, vec3(1.0 / czm_gamma)); 12 | } 13 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/cascadeWeights.glsl: -------------------------------------------------------------------------------- 1 | 2 | uniform vec4 shadowMap_cascadeSplits[2]; 3 | 4 | vec4 czm_cascadeWeights(float depthEye) 5 | { 6 | // One component is set to 1.0 and all others set to 0.0. 7 | vec4 near = step(shadowMap_cascadeSplits[0], vec4(depthEye)); 8 | vec4 far = step(depthEye, shadowMap_cascadeSplits[1]); 9 | return near * far; 10 | } 11 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/cascadeMatrix.glsl: -------------------------------------------------------------------------------- 1 | 2 | uniform mat4 shadowMap_cascadeMatrices[4]; 3 | 4 | mat4 czm_cascadeMatrix(vec4 weights) 5 | { 6 | return shadowMap_cascadeMatrices[0] * weights.x + 7 | shadowMap_cascadeMatrices[1] * weights.y + 8 | shadowMap_cascadeMatrices[2] * weights.z + 9 | shadowMap_cascadeMatrices[3] * weights.w; 10 | } 11 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/ellipsoidContainsPoint.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * DOC_TBA 3 | * 4 | * @name czm_ellipsoidContainsPoint 5 | * @glslFunction 6 | * 7 | */ 8 | bool czm_ellipsoidContainsPoint(vec3 ellipsoid_inverseRadii, vec3 point) 9 | { 10 | vec3 scaled = ellipsoid_inverseRadii * (czm_inverseModelView * vec4(point, 1.0)).xyz; 11 | return (dot(scaled, scaled) <= 1.0); 12 | } 13 | -------------------------------------------------------------------------------- /src/Core/TerrainQuantization.ts: -------------------------------------------------------------------------------- 1 | enum TerrainQuantization { 2 | /** 3 | * The vertices are not compressed. 4 | * 5 | * @type {Number} 6 | * @constant 7 | */ 8 | NONE = 0, 9 | 10 | /** 11 | * The vertices are compressed to 12 bits. 12 | * 13 | * @type {Number} 14 | * @constant 15 | */ 16 | BITS12 = 1, 17 | } 18 | 19 | export { TerrainQuantization }; 20 | -------------------------------------------------------------------------------- /src/Scene/ContextLimits.ts: -------------------------------------------------------------------------------- 1 | const ContextLimits = { 2 | _maxAnisotropy: 0, 3 | 4 | _maximumTextureImageUnits: 0, 5 | 6 | get maxAnisotropy (): number { 7 | return ContextLimits._maxAnisotropy; 8 | }, 9 | 10 | get maximumTextureImageUnits (): number { 11 | return ContextLimits._maximumTextureImageUnits; 12 | } 13 | }; 14 | 15 | export { ContextLimits }; 16 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/pi.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * A built-in GLSL floating-point constant for Math.PI. 3 | * 4 | * @alias czm_pi 5 | * @glslConstant 6 | * 7 | * @see CesiumMath.PI 8 | * 9 | * @example 10 | * // GLSL declaration 11 | * const float czm_pi = ...; 12 | * 13 | * // Example 14 | * float twoPi = 2.0 * czm_pi; 15 | */ 16 | const float czm_pi = 3.141592653589793; 17 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/twoPi.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * A built-in GLSL floating-point constant for 2pi. 3 | * 4 | * @alias czm_twoPi 5 | * @glslConstant 6 | * 7 | * @see CesiumMath.TWO_PI 8 | * 9 | * @example 10 | * // GLSL declaration 11 | * const float czm_twoPi = ...; 12 | * 13 | * // Example 14 | * float pi = czm_twoPi / 2.0; 15 | */ 16 | const float czm_twoPi = 6.283185307179586; 17 | -------------------------------------------------------------------------------- /src/Core/MapMode2D.ts: -------------------------------------------------------------------------------- 1 | enum MapMode2D { 2 | /** 3 | * The 2D map can be rotated about the z axis. 4 | * 5 | * @type {Number} 6 | * @constant 7 | */ 8 | ROTATE = 0, 9 | 10 | /** 11 | * The 2D map can be scrolled infinitely in the horizontal direction. 12 | * 13 | * @type {Number} 14 | * @constant 15 | */ 16 | INFINITE_SCROLL = 1, 17 | } 18 | 19 | export { MapMode2D }; 20 | -------------------------------------------------------------------------------- /src/Core/HeightmapEncoding.ts: -------------------------------------------------------------------------------- 1 | enum HeightmapEncoding { 2 | /** 3 | * No encoding 4 | * 5 | * @type {Number} 6 | * @constant 7 | */ 8 | NONE = 0, 9 | 10 | /** 11 | * LERC encoding 12 | * 13 | * @type {Number} 14 | * @constant 15 | * 16 | * @see {@link https://github.com/Esri/lerc|The LERC specification} 17 | */ 18 | LERC = 1, 19 | } 20 | 21 | export { HeightmapEncoding }; 22 | -------------------------------------------------------------------------------- /src/Core/isBlobUri.ts: -------------------------------------------------------------------------------- 1 | const blobUriRegex = /^blob:/i; 2 | 3 | /** 4 | * Determines if the specified uri is a blob uri. 5 | * 6 | * @function isBlobUri 7 | * 8 | * @param {String} uri The uri to test. 9 | * @returns {Boolean} true when the uri is a blob uri; otherwise, false. 10 | * 11 | * @private 12 | */ 13 | function isBlobUri (uri: string): boolean { 14 | return blobUriRegex.test(uri); 15 | } 16 | export { isBlobUri }; 17 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/oneOverPi.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * A built-in GLSL floating-point constant for 1/pi. 3 | * 4 | * @alias czm_oneOverPi 5 | * @glslConstant 6 | * 7 | * @see CesiumMath.ONE_OVER_PI 8 | * 9 | * @example 10 | * // GLSL declaration 11 | * const float czm_oneOverPi = ...; 12 | * 13 | * // Example 14 | * float pi = 1.0 / czm_oneOverPi; 15 | */ 16 | const float czm_oneOverPi = 0.3183098861837907; 17 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/piOverSix.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * A built-in GLSL floating-point constant for pi/6. 3 | * 4 | * @alias czm_piOverSix 5 | * @glslConstant 6 | * 7 | * @see CesiumMath.PI_OVER_SIX 8 | * 9 | * @example 10 | * // GLSL declaration 11 | * const float czm_piOverSix = ...; 12 | * 13 | * // Example 14 | * float pi = 6.0 * czm_piOverSix; 15 | */ 16 | const float czm_piOverSix = 0.5235987755982988; 17 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/piOverTwo.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * A built-in GLSL floating-point constant for pi/2. 3 | * 4 | * @alias czm_piOverTwo 5 | * @glslConstant 6 | * 7 | * @see CesiumMath.PI_OVER_TWO 8 | * 9 | * @example 10 | * // GLSL declaration 11 | * const float czm_piOverTwo = ...; 12 | * 13 | * // Example 14 | * float pi = 2.0 * czm_piOverTwo; 15 | */ 16 | const float czm_piOverTwo = 1.5707963267948966; 17 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/reverseLogDepth.glsl: -------------------------------------------------------------------------------- 1 | float czm_reverseLogDepth(float logZ) 2 | { 3 | #ifdef LOG_DEPTH 4 | float near = czm_currentFrustum.x; 5 | float far = czm_currentFrustum.y; 6 | float log2Depth = logZ * czm_log2FarDepthFromNearPlusOne; 7 | float depthFromNear = pow(2.0, log2Depth) - 1.0; 8 | return far * (1.0 - near / (depthFromNear + near)) / (far - near); 9 | #endif 10 | return logZ; 11 | } 12 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/piOverFour.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * A built-in GLSL floating-point constant for pi/4. 3 | * 4 | * @alias czm_piOverFour 5 | * @glslConstant 6 | * 7 | * @see CesiumMath.PI_OVER_FOUR 8 | * 9 | * @example 10 | * // GLSL declaration 11 | * const float czm_piOverFour = ...; 12 | * 13 | * // Example 14 | * float pi = 4.0 * czm_piOverFour; 15 | */ 16 | const float czm_piOverFour = 0.7853981633974483; 17 | -------------------------------------------------------------------------------- /src/Core/isDataUri.ts: -------------------------------------------------------------------------------- 1 | 2 | const dataUriRegex = /^data:/i; 3 | 4 | /** 5 | * Determines if the specified uri is a data uri. 6 | * 7 | * @function isDataUri 8 | * 9 | * @param {String} uri The uri to test. 10 | * @returns {Boolean} true when the uri is a data uri; otherwise, false. 11 | * 12 | * @private 13 | */ 14 | function isDataUri (uri: string): boolean { 15 | return dataUriRegex.test(uri); 16 | } 17 | export { isDataUri }; 18 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/piOverThree.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * A built-in GLSL floating-point constant for pi/3. 3 | * 4 | * @alias czm_piOverThree 5 | * @glslConstant 6 | * 7 | * @see CesiumMath.PI_OVER_THREE 8 | * 9 | * @example 10 | * // GLSL declaration 11 | * const float czm_piOverThree = ...; 12 | * 13 | * // Example 14 | * float pi = 3.0 * czm_piOverThree; 15 | */ 16 | const float czm_piOverThree = 1.0471975511965976; 17 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/oneOverTwoPi.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * A built-in GLSL floating-point constant for 1/2pi. 3 | * 4 | * @alias czm_oneOverTwoPi 5 | * @glslConstant 6 | * 7 | * @see CesiumMath.ONE_OVER_TWO_PI 8 | * 9 | * @example 10 | * // GLSL declaration 11 | * const float czm_oneOverTwoPi = ...; 12 | * 13 | * // Example 14 | * float pi = 2.0 * czm_oneOverTwoPi; 15 | */ 16 | const float czm_oneOverTwoPi = 0.15915494309189535; 17 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/threePiOver2.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * A built-in GLSL floating-point constant for 3pi/2. 3 | * 4 | * @alias czm_threePiOver2 5 | * @glslConstant 6 | * 7 | * @see CesiumMath.THREE_PI_OVER_TWO 8 | * 9 | * @example 10 | * // GLSL declaration 11 | * const float czm_threePiOver2 = ...; 12 | * 13 | * // Example 14 | * float pi = (2.0 / 3.0) * czm_threePiOver2; 15 | */ 16 | const float czm_threePiOver2 = 4.71238898038469; 17 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/acesTonemapping.glsl: -------------------------------------------------------------------------------- 1 | // See: 2 | // https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/ 3 | 4 | vec3 czm_acesTonemapping(vec3 color) { 5 | float g = 0.985; 6 | float a = 0.065; 7 | float b = 0.0001; 8 | float c = 0.433; 9 | float d = 0.238; 10 | 11 | color = (color * (color + a) - b) / (color * (g * color + c) + d); 12 | 13 | color = clamp(color, 0.0, 1.0); 14 | 15 | return color; 16 | } 17 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/degreesPerRadian.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * A built-in GLSL floating-point constant for converting radians to degrees. 3 | * 4 | * @alias czm_degreesPerRadian 5 | * @glslConstant 6 | * 7 | * @see CesiumMath.DEGREES_PER_RADIAN 8 | * 9 | * @example 10 | * // GLSL declaration 11 | * const float czm_degreesPerRadian = ...; 12 | * 13 | * // Example 14 | * float deg = czm_degreesPerRadian * rad; 15 | */ 16 | const float czm_degreesPerRadian = 57.29577951308232; 17 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/radiansPerDegree.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * A built-in GLSL floating-point constant for converting degrees to radians. 3 | * 4 | * @alias czm_radiansPerDegree 5 | * @glslConstant 6 | * 7 | * @see CesiumMath.RADIANS_PER_DEGREE 8 | * 9 | * @example 10 | * // GLSL declaration 11 | * const float czm_radiansPerDegree = ...; 12 | * 13 | * // Example 14 | * float rad = czm_radiansPerDegree * deg; 15 | */ 16 | const float czm_radiansPerDegree = 0.017453292519943295; 17 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/alphaWeight.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * @private 3 | */ 4 | float czm_alphaWeight(float a) 5 | { 6 | float z = (gl_FragCoord.z - czm_viewportTransformation[3][2]) / czm_viewportTransformation[2][2]; 7 | 8 | // See Weighted Blended Order-Independent Transparency for examples of different weighting functions: 9 | // http://jcgt.org/published/0002/02/09/ 10 | return pow(a + 0.01, 4.0) + max(1e-2, min(3.0 * 1e3, 0.003 / (1e-5 + pow(abs(z) / 200.0, 4.0)))); 11 | } 12 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/depthRange.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * A built-in GLSL vec2 constant for defining the depth range. 3 | * This is a workaround to a bug where IE11 does not implement gl_DepthRange. 4 | * 5 | * @alias czm_depthRange 6 | * @glslConstant 7 | * 8 | * @example 9 | * // GLSL declaration 10 | * float depthRangeNear = czm_depthRange.near; 11 | * float depthRangeFar = czm_depthRange.far; 12 | * 13 | */ 14 | const czm_depthRangeStruct czm_depthRange = czm_depthRangeStruct(0.0, 1.0); 15 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/backFacing.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Determines if the fragment is back facing 3 | * 4 | * @name czm_backFacing 5 | * @glslFunction 6 | * 7 | * @returns {bool} true if the fragment is back facing; otherwise, false. 8 | */ 9 | bool czm_backFacing() 10 | { 11 | // !gl_FrontFacing doesn't work as expected on Mac/Intel so use the more verbose form instead. See https://github.com/CesiumGS/cesium/pull/8494. 12 | return gl_FrontFacing == false; 13 | } 14 | -------------------------------------------------------------------------------- /src/Material/Pass/RGBShiftMaterial.ts: -------------------------------------------------------------------------------- 1 | import { RGBShiftShader } from '@/Shader/RGBShiftShader'; 2 | import { ShaderMaterial, UniformsUtils } from 'three'; 3 | 4 | class RGBShiftMaterial extends ShaderMaterial { 5 | constructor () { 6 | super(); 7 | this.uniforms = UniformsUtils.clone(RGBShiftShader.uniforms); 8 | this.vertexShader = RGBShiftShader.vertexShader; 9 | this.fragmentShader = RGBShiftShader.fragmentShader; 10 | } 11 | } 12 | 13 | export { RGBShiftMaterial }; 14 | -------------------------------------------------------------------------------- /src/Shader/SkyAtmosphereVS.glsl: -------------------------------------------------------------------------------- 1 | attribute vec4 position; 2 | 3 | varying vec3 v_outerPositionWC; 4 | 5 | #ifndef PER_FRAGMENT_ATMOSPHERE 6 | varying vec3 v_mieColor; 7 | varying vec3 v_rayleighColor; 8 | #endif 9 | 10 | void main(void) 11 | { 12 | vec4 positionWC = czm_model * position; 13 | 14 | #ifndef PER_FRAGMENT_ATMOSPHERE 15 | calculateMieColorAndRayleighColor(positionWC.xyz, v_mieColor, v_rayleighColor); 16 | #endif 17 | v_outerPositionWC = positionWC.xyz; 18 | gl_Position = czm_modelViewProjection * position; 19 | } 20 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/eyeOffset.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * DOC_TBA 3 | * 4 | * @name czm_eyeOffset 5 | * @glslFunction 6 | * 7 | * @param {vec4} positionEC DOC_TBA. 8 | * @param {vec3} eyeOffset DOC_TBA. 9 | * 10 | * @returns {vec4} DOC_TBA. 11 | */ 12 | vec4 czm_eyeOffset(vec4 positionEC, vec3 eyeOffset) 13 | { 14 | // This equation is approximate in x and y. 15 | vec4 p = positionEC; 16 | vec4 zEyeOffset = normalize(p) * eyeOffset.z; 17 | p.xy += eyeOffset.xy + zEyeOffset.xy; 18 | p.z += zEyeOffset.z; 19 | return p; 20 | } 21 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/luminance.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Computes the luminance of a color. 3 | * 4 | * @name czm_luminance 5 | * @glslFunction 6 | * 7 | * @param {vec3} rgb The color. 8 | * 9 | * @returns {float} The luminance. 10 | * 11 | * @example 12 | * float light = czm_luminance(vec3(0.0)); // 0.0 13 | * float dark = czm_luminance(vec3(1.0)); // ~1.0 14 | */ 15 | float czm_luminance(vec3 rgb) 16 | { 17 | // Algorithm from Chapter 10 of Graphics Shaders. 18 | const vec3 W = vec3(0.2125, 0.7154, 0.0721); 19 | return dot(rgb, W); 20 | } 21 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/gammaCorrect.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Converts a color from RGB space to linear space. 3 | * 4 | * @name czm_gammaCorrect 5 | * @glslFunction 6 | * 7 | * @param {vec3} color The color in RGB space. 8 | * @returns {vec3} The color in linear space. 9 | */ 10 | vec3 czm_gammaCorrect(vec3 color) { 11 | #ifdef HDR 12 | color = pow(color, vec3(czm_gamma)); 13 | #endif 14 | return color; 15 | } 16 | 17 | vec4 czm_gammaCorrect(vec4 color) { 18 | #ifdef HDR 19 | color.rgb = pow(color.rgb, vec3(czm_gamma)); 20 | #endif 21 | return color; 22 | } 23 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/geodeticSurfaceNormal.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * DOC_TBA 3 | * 4 | * @name czm_geodeticSurfaceNormal 5 | * @glslFunction 6 | * 7 | * @param {vec3} positionOnEllipsoid DOC_TBA 8 | * @param {vec3} ellipsoidCenter DOC_TBA 9 | * @param {vec3} oneOverEllipsoidRadiiSquared DOC_TBA 10 | * 11 | * @returns {vec3} DOC_TBA. 12 | */ 13 | vec3 czm_geodeticSurfaceNormal(vec3 positionOnEllipsoid, vec3 ellipsoidCenter, vec3 oneOverEllipsoidRadiiSquared) 14 | { 15 | return normalize((positionOnEllipsoid - ellipsoidCenter) * oneOverEllipsoidRadiiSquared); 16 | } 17 | -------------------------------------------------------------------------------- /src/Scene/QuadtreeTileProvider.ts: -------------------------------------------------------------------------------- 1 | import { DeveloperError } from '@/Core/DeveloperError'; 2 | 3 | class QuadtreeTileProvider { 4 | constructor () { 5 | DeveloperError.throwInstantiationError(); 6 | } 7 | 8 | get quadtree ():void { 9 | return DeveloperError.throwInstantiationError(); 10 | } 11 | 12 | set quadtree (value: any) { 13 | DeveloperError.throwInstantiationError(); 14 | } 15 | 16 | get tilingScheme ():void { 17 | return DeveloperError.throwInstantiationError(); 18 | } 19 | } 20 | export { QuadtreeTileProvider }; 21 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Structs/pbrParameters.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Parameters for {@link czm_pbrLighting} 3 | * 4 | * @name czm_material 5 | * @glslStruct 6 | * 7 | * @property {vec3} diffuseColor the diffuse color of the material for the lambert term of the rendering equation 8 | * @property {float} roughness a value from 0.0 to 1.0 that indicates how rough the surface of the material is. 9 | * @property {vec3} f0 The reflectance of the material at normal incidence 10 | */ 11 | struct czm_pbrParameters 12 | { 13 | vec3 diffuseColor; 14 | float roughness; 15 | vec3 f0; 16 | }; 17 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Structs/raySegment.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * DOC_TBA 3 | * 4 | * @name czm_raySegment 5 | * @glslStruct 6 | */ 7 | struct czm_raySegment 8 | { 9 | float start; 10 | float stop; 11 | }; 12 | 13 | /** 14 | * DOC_TBA 15 | * 16 | * @name czm_emptyRaySegment 17 | * @glslConstant 18 | */ 19 | const czm_raySegment czm_emptyRaySegment = czm_raySegment(-czm_infinity, -czm_infinity); 20 | 21 | /** 22 | * DOC_TBA 23 | * 24 | * @name czm_fullRaySegment 25 | * @glslConstant 26 | */ 27 | const czm_raySegment czm_fullRaySegment = czm_raySegment(0.0, czm_infinity); 28 | -------------------------------------------------------------------------------- /src/Material/SkyAtmosphereMaterial.ts: -------------------------------------------------------------------------------- 1 | import { MaterialParameters, Matrix4, RawShaderMaterial, ShaderMaterial, Vector3 } from 'three'; 2 | 3 | class SkyAtmosphereMaterial extends RawShaderMaterial { 4 | constructor (parameters: MaterialParameters) { 5 | super(parameters); 6 | 7 | this.lights = false; 8 | this.fog = false; 9 | 10 | this.uniforms = { 11 | u_radiiAndDynamicAtmosphereColor: { value: new Vector3() }, 12 | u_hsbShift: { value: new Vector3() } 13 | }; 14 | } 15 | } 16 | 17 | export { SkyAtmosphereMaterial }; 18 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/transformPlane.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Transforms a plane. 3 | * 4 | * @name czm_transformPlane 5 | * @glslFunction 6 | * 7 | * @param {vec4} plane The plane in Hessian Normal Form. 8 | * @param {mat4} transform The inverse-transpose of a transformation matrix. 9 | */ 10 | vec4 czm_transformPlane(vec4 plane, mat4 transform) { 11 | vec4 transformedPlane = transform * plane; 12 | // Convert the transformed plane to Hessian Normal Form 13 | float normalMagnitude = length(transformedPlane.xyz); 14 | return transformedPlane / normalMagnitude; 15 | } 16 | -------------------------------------------------------------------------------- /src/Core/DefaultProxy.ts: -------------------------------------------------------------------------------- 1 | class DefaultProxy { 2 | proxy: string 3 | constructor (proxy: string) { 4 | this.proxy = proxy; 5 | } 6 | 7 | /** 8 | * Get the final URL to use to request a given resource. 9 | * 10 | * @param {String} resource The resource to request. 11 | * @returns {String} proxied resource 12 | */ 13 | getURL (resource: string): string { 14 | const prefix = this.proxy.indexOf('?') === -1 ? '?' : ''; 15 | return this.proxy + prefix + encodeURIComponent(resource); 16 | } 17 | } 18 | 19 | export { DefaultProxy }; 20 | -------------------------------------------------------------------------------- /src/Core/resolveIncludes.ts: -------------------------------------------------------------------------------- 1 | import { ShaderChunk } from 'three'; 2 | 3 | const includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm; 4 | 5 | function resolveIncludes (string: string): string { 6 | return string.replace(includePattern, includeReplacer); 7 | } 8 | 9 | function includeReplacer (match: string, include: string) { 10 | const string = ShaderChunk[include]; 11 | 12 | if (string === undefined) { 13 | throw new Error('Can not resolve #include <' + include + '>'); 14 | } 15 | 16 | return resolveIncludes(string); 17 | } 18 | 19 | export { resolveIncludes }; 20 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/unpackDepth.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Unpacks a vec4 depth value to a float in [0, 1) range. 3 | * 4 | * @name czm_unpackDepth 5 | * @glslFunction 6 | * 7 | * @param {vec4} packedDepth The packed depth. 8 | * 9 | * @returns {float} The floating-point depth in [0, 1) range. 10 | */ 11 | float czm_unpackDepth(vec4 packedDepth) 12 | { 13 | // See Aras Pranckevičius' post Encoding Floats to RGBA 14 | // http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/ 15 | return dot(packedDepth, vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)); 16 | } 17 | -------------------------------------------------------------------------------- /src/Scene/QuadtreeOccluders.ts: -------------------------------------------------------------------------------- 1 | import { Cartesian3 } from '@/Core/Cartesian3'; 2 | import { Ellipsoid } from '@/Core/Ellipsoid'; 3 | import { EllipsoidalOccluder } from '@/Core/EllipsoidalOccluder'; 4 | 5 | class QuadtreeOccluders { 6 | _ellipsoid: EllipsoidalOccluder 7 | constructor (options = { 8 | ellipsoid: Ellipsoid.WGS84 9 | }) { 10 | this._ellipsoid = new EllipsoidalOccluder(options.ellipsoid, Cartesian3.ZERO); 11 | } 12 | 13 | get ellipsoid (): EllipsoidalOccluder { 14 | return this._ellipsoid; 15 | } 16 | } 17 | 18 | export { QuadtreeOccluders }; 19 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/defaultPbrMaterial.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Get default parameters for physically based rendering. These defaults 3 | * describe a rough dielectric (non-metal) surface (e.g. rough plastic). 4 | * 5 | * @return {czm_pbrParameters} Default parameters for {@link czm_pbrLighting} 6 | */ 7 | czm_pbrParameters czm_defaultPbrMaterial() 8 | { 9 | czm_pbrParameters results; 10 | results.diffuseColor = vec3(1.0); 11 | results.roughness = 1.0; 12 | 13 | const vec3 REFLECTANCE_DIELECTRIC = vec3(0.04); 14 | results.f0 = REFLECTANCE_DIELECTRIC; 15 | return results; 16 | } 17 | -------------------------------------------------------------------------------- /src/Renderer/BufferUsage.ts: -------------------------------------------------------------------------------- 1 | import { WebGLConstants } from '@/Core/WebGLConstants'; 2 | 3 | /** 4 | * @private 5 | */ 6 | const BufferUsage = { 7 | STREAM_DRAW: WebGLConstants.STREAM_DRAW, 8 | STATIC_DRAW: WebGLConstants.STATIC_DRAW, 9 | DYNAMIC_DRAW: WebGLConstants.DYNAMIC_DRAW, 10 | 11 | validate: function (bufferUsage: number) { 12 | return ( 13 | bufferUsage === BufferUsage.STREAM_DRAW || 14 | bufferUsage === BufferUsage.STATIC_DRAW || 15 | bufferUsage === BufferUsage.DYNAMIC_DRAW 16 | ); 17 | } 18 | }; 19 | 20 | export { BufferUsage }; 21 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/multiplyWithColorBalance.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * DOC_TBA 3 | * 4 | * @name czm_multiplyWithColorBalance 5 | * @glslFunction 6 | */ 7 | vec3 czm_multiplyWithColorBalance(vec3 left, vec3 right) 8 | { 9 | // Algorithm from Chapter 10 of Graphics Shaders. 10 | const vec3 W = vec3(0.2125, 0.7154, 0.0721); 11 | 12 | vec3 target = left * right; 13 | float leftLuminance = dot(left, W); 14 | float rightLuminance = dot(right, W); 15 | float targetLuminance = dot(target, W); 16 | 17 | return ((leftLuminance + rightLuminance) / (2.0 * targetLuminance)) * target; 18 | } 19 | -------------------------------------------------------------------------------- /src/Scene/OrthographicFrustumCamera.ts: -------------------------------------------------------------------------------- 1 | import { OrthographicCamera } from 'three'; 2 | import { Scene } from './Scene'; 3 | 4 | export interface OrthographicFrustumCameraParameters { 5 | left?: number; 6 | right?: number; 7 | top?: number; 8 | bottom?: number; 9 | near?: number; 10 | far?: number; 11 | } 12 | 13 | class OrthographicFrustumCamera extends OrthographicCamera { 14 | constructor (scene: Scene, options: OrthographicFrustumCameraParameters) { 15 | super(options.left, options.right, options.top, options.bottom, options.near, options.far); 16 | } 17 | } 18 | 19 | export { OrthographicFrustumCamera }; 20 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/decompressTextureCoordinates.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Decompresses texture coordinates that were packed into a single float. 3 | * 4 | * @name czm_decompressTextureCoordinates 5 | * @glslFunction 6 | * 7 | * @param {float} encoded The compressed texture coordinates. 8 | * @returns {vec2} The decompressed texture coordinates. 9 | */ 10 | vec2 czm_decompressTextureCoordinates(float encoded) 11 | { 12 | float temp = encoded / 4096.0; 13 | float xZeroTo4095 = floor(temp); 14 | float stx = xZeroTo4095 / 4095.0; 15 | float sty = (encoded - xZeroTo4095 * 4096.0) / 4095.0; 16 | return vec2(stx, sty); 17 | } 18 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/lineDistance.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Computes distance from an point in 2D to a line in 2D. 3 | * 4 | * @name czm_lineDistance 5 | * @glslFunction 6 | * 7 | * param {vec2} point1 A point along the line. 8 | * param {vec2} point2 A point along the line. 9 | * param {vec2} point A point that may or may not be on the line. 10 | * returns {float} The distance from the point to the line. 11 | */ 12 | float czm_lineDistance(vec2 point1, vec2 point2, vec2 point) { 13 | return abs((point2.y - point1.y) * point.x - (point2.x - point1.x) * point.y + point2.x * point1.y - point2.y * point1.x) / distance(point2, point1); 14 | } 15 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/isEmpty.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Determines if a time interval is empty. 3 | * 4 | * @name czm_isEmpty 5 | * @glslFunction 6 | * 7 | * @param {czm_raySegment} interval The interval to test. 8 | * 9 | * @returns {bool} true if the time interval is empty; otherwise, false. 10 | * 11 | * @example 12 | * bool b0 = czm_isEmpty(czm_emptyRaySegment); // true 13 | * bool b1 = czm_isEmpty(czm_raySegment(0.0, 1.0)); // false 14 | * bool b2 = czm_isEmpty(czm_raySegment(1.0, 1.0)); // false, contains 1.0. 15 | */ 16 | bool czm_isEmpty(czm_raySegment interval) 17 | { 18 | return (interval.stop < 0.0); 19 | } 20 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/packDepth.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Packs a depth value into a vec3 that can be represented by unsigned bytes. 3 | * 4 | * @name czm_packDepth 5 | * @glslFunction 6 | * 7 | * @param {float} depth The floating-point depth. 8 | * @returns {vec3} The packed depth. 9 | */ 10 | vec4 czm_packDepth(float depth) 11 | { 12 | // See Aras Pranckevičius' post Encoding Floats to RGBA 13 | // http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/ 14 | vec4 enc = vec4(1.0, 255.0, 65025.0, 16581375.0) * depth; 15 | enc = fract(enc); 16 | enc -= enc.yzww * vec4(1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0, 0.0); 17 | return enc; 18 | } 19 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/isFull.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Determines if a time interval is empty. 3 | * 4 | * @name czm_isFull 5 | * @glslFunction 6 | * 7 | * @param {czm_raySegment} interval The interval to test. 8 | * 9 | * @returns {bool} true if the time interval is empty; otherwise, false. 10 | * 11 | * @example 12 | * bool b0 = czm_isEmpty(czm_emptyRaySegment); // true 13 | * bool b1 = czm_isEmpty(czm_raySegment(0.0, 1.0)); // false 14 | * bool b2 = czm_isEmpty(czm_raySegment(1.0, 1.0)); // false, contains 1.0. 15 | */ 16 | bool czm_isFull(czm_raySegment interval) 17 | { 18 | return (interval.start == 0.0 && interval.stop == czm_infinity); 19 | } 20 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 5 | 6 | 17 | 18 | 28 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/pointAlongRay.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Computes the point along a ray at the given time. time can be positive, negative, or zero. 3 | * 4 | * @name czm_pointAlongRay 5 | * @glslFunction 6 | * 7 | * @param {czm_ray} ray The ray to compute the point along. 8 | * @param {float} time The time along the ray. 9 | * 10 | * @returns {vec3} The point along the ray at the given time. 11 | * 12 | * @example 13 | * czm_ray ray = czm_ray(vec3(0.0), vec3(1.0, 0.0, 0.0)); // origin, direction 14 | * vec3 v = czm_pointAlongRay(ray, 2.0); // (2.0, 0.0, 0.0) 15 | */ 16 | vec3 czm_pointAlongRay(czm_ray ray, float time) 17 | { 18 | return ray.origin + (time * ray.direction); 19 | } 20 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | 4 | env: { 5 | node: true 6 | }, 7 | extends: [ 8 | 'plugin:vue/vue3-essential', 9 | '@vue/standard', 10 | '@vue/typescript/recommended' 11 | ], 12 | parserOptions: { 13 | ecmaVersion: 2020, 14 | ignoreImports: true, 15 | }, 16 | rules: { 17 | 'camelcase': 'off', 18 | 'semi': ["error", "always"], 19 | "indent": ["error", 4], 20 | "@typescript-eslint/no-this-alias": ["off"], 21 | 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', 22 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off' 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Core/HeadingPitchRoll.ts: -------------------------------------------------------------------------------- 1 | 2 | class HeadingPitchRoll { 3 | heading: number; 4 | pitch: number; 5 | roll: number; 6 | constructor (heading = 0.0, pitch = 0.0, roll = 0.0) { 7 | /** 8 | * Gets or sets the heading. 9 | * @type {Number} 10 | * @default 0.0 11 | */ 12 | this.heading = heading; 13 | /** 14 | * Gets or sets the pitch. 15 | * @type {Number} 16 | * @default 0.0 17 | */ 18 | this.pitch = pitch; 19 | /** 20 | * Gets or sets the roll. 21 | * @type {Number} 22 | * @default 0.0 23 | */ 24 | this.roll = roll; 25 | } 26 | } 27 | 28 | export { HeadingPitchRoll }; 29 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/shadowDepthCompare.glsl: -------------------------------------------------------------------------------- 1 | 2 | float czm_sampleShadowMap(highp samplerCube shadowMap, vec3 d) 3 | { 4 | return czm_unpackDepth(textureCube(shadowMap, d)); 5 | } 6 | 7 | float czm_sampleShadowMap(highp sampler2D shadowMap, vec2 uv) 8 | { 9 | #ifdef USE_SHADOW_DEPTH_TEXTURE 10 | return texture2D(shadowMap, uv).r; 11 | #else 12 | return czm_unpackDepth(texture2D(shadowMap, uv)); 13 | #endif 14 | } 15 | 16 | float czm_shadowDepthCompare(samplerCube shadowMap, vec3 uv, float depth) 17 | { 18 | return step(depth, czm_sampleShadowMap(shadowMap, uv)); 19 | } 20 | 21 | float czm_shadowDepthCompare(sampler2D shadowMap, vec2 uv, float depth) 22 | { 23 | return step(depth, czm_sampleShadowMap(shadowMap, uv)); 24 | } 25 | -------------------------------------------------------------------------------- /src/Shader/SkyAtmosphereFS.glsl: -------------------------------------------------------------------------------- 1 | varying vec3 v_outerPositionWC; 2 | 3 | #ifndef PER_FRAGMENT_ATMOSPHERE 4 | varying vec3 v_mieColor; 5 | varying vec3 v_rayleighColor; 6 | #endif 7 | 8 | void main (void) 9 | { 10 | vec3 toCamera = czm_viewerPositionWC - v_outerPositionWC; 11 | vec3 lightDirection = getLightDirection(czm_viewerPositionWC); 12 | vec3 mieColor; 13 | vec3 rayleighColor; 14 | 15 | #ifdef PER_FRAGMENT_ATMOSPHERE 16 | calculateMieColorAndRayleighColor(v_outerPositionWC, mieColor, rayleighColor); 17 | #else 18 | mieColor = v_mieColor; 19 | rayleighColor = v_rayleighColor; 20 | #endif 21 | 22 | gl_FragColor = calculateFinalColor(czm_viewerPositionWC, toCamera, lightDirection, mieColor, rayleighColor); 23 | } 24 | -------------------------------------------------------------------------------- /src/Core/Interval.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Represents the closed interval [start, stop]. 4 | * @alias Interval 5 | * @constructor 6 | * 7 | * @param {Number} [start=0.0] The beginning of the interval. 8 | * @param {Number} [stop=0.0] The end of the interval. 9 | */ 10 | 11 | class Interval { 12 | start: number; 13 | stop: number 14 | constructor (start = 0.0, stop = 0.0) { 15 | /** 16 | * The beginning of the interval. 17 | * @type {Number} 18 | * @default 0.0 19 | */ 20 | this.start = start; 21 | /** 22 | * The end of the interval. 23 | * @type {Number} 24 | * @default 0.0 25 | */ 26 | this.stop = stop; 27 | } 28 | } 29 | export { Interval }; 30 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/saturation.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Adjusts the saturation of a color. 3 | * 4 | * @name czm_saturation 5 | * @glslFunction 6 | * 7 | * @param {vec3} rgb The color. 8 | * @param {float} adjustment The amount to adjust the saturation of the color. 9 | * 10 | * @returns {float} The color with the saturation adjusted. 11 | * 12 | * @example 13 | * vec3 greyScale = czm_saturation(color, 0.0); 14 | * vec3 doubleSaturation = czm_saturation(color, 2.0); 15 | */ 16 | vec3 czm_saturation(vec3 rgb, float adjustment) 17 | { 18 | // Algorithm from Chapter 16 of OpenGL Shading Language 19 | const vec3 W = vec3(0.2125, 0.7154, 0.0721); 20 | vec3 intensity = vec3(dot(rgb, W)); 21 | return mix(intensity, rgb, adjustment); 22 | } 23 | -------------------------------------------------------------------------------- /vue.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | productionSourceMap: false, 3 | publicPath: process.env.NODE_ENV === 'production' ? './' : './', 4 | /* 输出文件目录:在npm run build时,生成文件的目录名称 */ 5 | outputDir: 'dist', 6 | // /* 放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录 */ 7 | // assetsDir: 'assets' 8 | chainWebpack: config => { 9 | config.module 10 | .rule('raw') 11 | .test(/\.glsl$/) 12 | .use('raw-loader') 13 | .loader('raw-loader') 14 | .end(); 15 | }, 16 | pluginOptions: { 17 | 'raw-loader': { 18 | preProcessor: 'glsl', // 声明类型 19 | patterns: [ 20 | ] 21 | // injector: 'append' 22 | } 23 | } 24 | 25 | }; 26 | -------------------------------------------------------------------------------- /src/Core/KeyboardEventModifier.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This enumerated type is for representing keyboard modifiers. These are keys 3 | * that are held down in addition to other event types. 4 | * 5 | * @enum {Number} 6 | */ 7 | enum KeyboardEventModifier { 8 | /** 9 | * Represents the shift key being held down. 10 | * 11 | * @type {Number} 12 | * @constant 13 | */ 14 | SHIFT = 0, 15 | 16 | /** 17 | * Represents the control key being held down. 18 | * 19 | * @type {Number} 20 | * @constant 21 | */ 22 | CTRL = 1, 23 | 24 | /** 25 | * Represents the alt key being held down. 26 | * 27 | * @type {Number} 28 | * @constant 29 | */ 30 | ALT = 2 31 | } 32 | export { KeyboardEventModifier }; 33 | -------------------------------------------------------------------------------- /src/Core/RequestType.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * An enum identifying the type of request. Used for finer grained logging and priority sorting. 3 | * 4 | * @enum {Number} 5 | */ 6 | enum RequestType { 7 | /** 8 | * Terrain request. 9 | * 10 | * @type Number 11 | * @constant 12 | */ 13 | TERRAIN = 0, 14 | 15 | /** 16 | * Imagery request. 17 | * 18 | * @type Number 19 | * @constant 20 | */ 21 | IMAGERY = 1, 22 | 23 | /** 24 | * 3D Tiles request. 25 | * 26 | * @type Number 27 | * @constant 28 | */ 29 | TILES3D = 2, 30 | 31 | /** 32 | * Other request. 33 | * 34 | * @type Number 35 | * @constant 36 | */ 37 | OTHER = 3 38 | } 39 | 40 | export { RequestType }; 41 | -------------------------------------------------------------------------------- /src/Core/CameraEventType.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Enumerates the available input for interacting with the camera. 3 | */ 4 | enum CameraEventType { 5 | /** 6 | * A left mouse button press followed by moving the mouse and releasing the button. 7 | */ 8 | LEFT_DRAG = 0, 9 | /** 10 | * A right mouse button press followed by moving the mouse and releasing the button. 11 | */ 12 | RIGHT_DRAG = 1, 13 | /** 14 | * A middle mouse button press followed by moving the mouse and releasing the button. 15 | */ 16 | MIDDLE_DRAG = 2, 17 | /** 18 | * Scrolling the middle mouse button. 19 | */ 20 | WHEEL = 3, 21 | /** 22 | * A two-finger touch on a touch surface. 23 | */ 24 | PINCH = 4 25 | } 26 | export { CameraEventType }; 27 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/HSBToRGB.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Converts an HSB color (hue, saturation, brightness) to RGB 3 | * HSB <-> RGB conversion with minimal branching: {@link http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl} 4 | * 5 | * @name czm_HSBToRGB 6 | * @glslFunction 7 | * 8 | * @param {vec3} hsb The color in HSB. 9 | * 10 | * @returns {vec3} The color in RGB. 11 | * 12 | * @example 13 | * vec3 hsb = czm_RGBToHSB(rgb); 14 | * hsb.z *= 0.1; 15 | * rgb = czm_HSBToRGB(hsb); 16 | */ 17 | 18 | const vec4 K_HSB2RGB = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); 19 | 20 | vec3 czm_HSBToRGB(vec3 hsb) 21 | { 22 | vec3 p = abs(fract(hsb.xxx + K_HSB2RGB.xyz) * 6.0 - K_HSB2RGB.www); 23 | return hsb.z * mix(K_HSB2RGB.xxx, clamp(p - K_HSB2RGB.xxx, 0.0, 1.0), hsb.y); 24 | } 25 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/writeDepthClamp.glsl: -------------------------------------------------------------------------------- 1 | // emulated noperspective 2 | #if defined(GL_EXT_frag_depth) && !defined(LOG_DEPTH) 3 | varying float v_WindowZ; 4 | #endif 5 | 6 | /** 7 | * Emulates GL_DEPTH_CLAMP. Clamps a fragment to the near and far plane 8 | * by writing the fragment's depth. See czm_depthClamp for more details. 9 | *

10 | * The shader must enable the GL_EXT_frag_depth extension. 11 | *

12 | * 13 | * @name czm_writeDepthClamp 14 | * @glslFunction 15 | * 16 | * @example 17 | * gl_FragColor = color; 18 | * czm_writeDepthClamp(); 19 | * 20 | * @see czm_depthClamp 21 | */ 22 | void czm_writeDepthClamp() 23 | { 24 | #if defined(GL_EXT_frag_depth) && !defined(LOG_DEPTH) 25 | gl_FragDepthEXT = clamp(v_WindowZ * gl_FragCoord.w, 0.0, 1.0); 26 | #endif 27 | } 28 | -------------------------------------------------------------------------------- /src/Core/Object3DCollection.ts: -------------------------------------------------------------------------------- 1 | import { Object3D } from 'three'; 2 | import { defaultValue } from './defaultValue'; 3 | 4 | class Object3DCollection extends Object3D { 5 | public destroyChildren: any; 6 | // boundingBox: Box3; 7 | // boundingSphere: Sphere; 8 | constructor (options?: { destroyChildren: true }) { 9 | super(); 10 | 11 | this.destroyChildren = options?.destroyChildren; 12 | // //这个集合整体的包围盒 13 | // this.boundingBox = new Box3(); 14 | // this.boundingSphere = new Sphere(); 15 | } 16 | 17 | // updateBoundingBox() { 18 | // this.boundingBox.makeEmpty(); 19 | // this.boundingBox.expandByObject(this); 20 | // this.boundingBox.getBoundingSphere(this.boundingSphere); 21 | // } 22 | } 23 | 24 | export { Object3DCollection }; 25 | -------------------------------------------------------------------------------- /src/Shader/CubeGlsl3Shader.ts: -------------------------------------------------------------------------------- 1 | import { ShaderLib } from 'three'; 2 | import { envmap_fragment } from './envmap_fragment'; 3 | import { fragmentIn, varyingExp, vertexOut } from './ShaderReplace'; 4 | 5 | const cube = ShaderLib.cube; 6 | 7 | const fragmentShader = ` 8 | 9 | #include 10 | uniform float opacity; 11 | varying vec3 vWorldDirection; 12 | #include 13 | 14 | void main() { 15 | vec3 vReflect = vWorldDirection; 16 | ${envmap_fragment} 17 | gl_FragColor = envColor; 18 | gl_FragColor.a *= opacity; 19 | #include 20 | #include 21 | 22 | }`; 23 | cube.vertexShader = cube.vertexShader.replace(varyingExp, vertexOut); 24 | cube.fragmentShader = fragmentShader.replace(varyingExp, fragmentIn); 25 | 26 | export { cube }; 27 | -------------------------------------------------------------------------------- /src/Core/ImagerySplitDirection.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The direction to display an ImageryLayer relative to the {@link Scene#imagerySplitPosition}. 3 | * 4 | * @enum {Number} 5 | * 6 | * @see ImageryLayer#splitDirection 7 | */ 8 | enum ImagerySplitDirection { 9 | /** 10 | * Display the ImageryLayer to the left of the {@link Scene#imagerySplitPosition}. 11 | * 12 | * @type {Number} 13 | * @constant 14 | */ 15 | LEFT = -1.0, 16 | 17 | /** 18 | * Always display the ImageryLayer. 19 | * 20 | * @type {Number} 21 | * @constant 22 | */ 23 | NONE = 0.0, 24 | 25 | /** 26 | * Display the ImageryLayer to the right of the {@link Scene#imagerySplitPosition}. 27 | * 28 | * @type {Number} 29 | * @constant 30 | */ 31 | RIGHT = 1.0 32 | } 33 | export { ImagerySplitDirection }; 34 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/computePosition.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Returns a position in model coordinates relative to eye taking into 3 | * account the current scene mode: 3D, 2D, or Columbus view. 4 | *

5 | * This uses standard position attributes, position3DHigh, 6 | * position3DLow, position2DHigh, and position2DLow, 7 | * and should be used when writing a vertex shader for an {@link Appearance}. 8 | *

9 | * 10 | * @name czm_computePosition 11 | * @glslFunction 12 | * 13 | * @returns {vec4} The position relative to eye. 14 | * 15 | * @example 16 | * vec4 p = czm_computePosition(); 17 | * v_positionEC = (czm_modelViewRelativeToEye * p).xyz; 18 | * gl_Position = czm_modelViewProjectionRelativeToEye * p; 19 | * 20 | * @see czm_translateRelativeToEye 21 | */ 22 | vec4 czm_computePosition(); 23 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Constants/webMercatorMaxLatitude.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * The maximum latitude, in radians, both North and South, supported by a Web Mercator 3 | * (EPSG:3857) projection. Technically, the Mercator projection is defined 4 | * for any latitude up to (but not including) 90 degrees, but it makes sense 5 | * to cut it off sooner because it grows exponentially with increasing latitude. 6 | * The logic behind this particular cutoff value, which is the one used by 7 | * Google Maps, Bing Maps, and Esri, is that it makes the projection 8 | * square. That is, the rectangle is equal in the X and Y directions. 9 | * 10 | * The constant value is computed as follows: 11 | * czm_pi * 0.5 - (2.0 * atan(exp(-czm_pi))) 12 | * 13 | * @name czm_webMercatorMaxLatitude 14 | * @glslConstant 15 | */ 16 | const float czm_webMercatorMaxLatitude = 1.4844222297453324; 17 | -------------------------------------------------------------------------------- /src/Core/formatError.ts: -------------------------------------------------------------------------------- 1 | import { defined } from './defined'; 2 | 3 | /** 4 | * Formats an error object into a String. If available, uses name, message, and stack 5 | * properties, otherwise, falls back on toString(). 6 | * 7 | * @function 8 | * 9 | * @param {*} object The item to find in the array. 10 | * @returns {String} A string containing the formatted error. 11 | */ 12 | function formatError (object: any): string { 13 | let result; 14 | 15 | const name = object.name; 16 | const message = object.message; 17 | if (defined(name) && defined(message)) { 18 | result = name + ': ' + message; 19 | } else { 20 | result = object.toString(); 21 | } 22 | 23 | const stack = object.stack; 24 | if (defined(stack)) { 25 | result += '\n' + stack; 26 | } 27 | 28 | return result; 29 | } 30 | export { formatError }; 31 | -------------------------------------------------------------------------------- /src/Renderer/Pass.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The render pass for a command. 3 | * 4 | * @private 5 | */ 6 | const Pass = { 7 | // If you add/modify/remove Pass constants, also change the automatic GLSL constants 8 | // that start with 'czm_pass' 9 | // 10 | // Commands are executed in order by pass up to the translucent pass. 11 | // Translucent geometry needs special handling (sorting/OIT). The compute pass 12 | // is executed first and the overlay pass is executed last. Both are not sorted 13 | // by frustum. 14 | ENVIRONMENT: 0, 15 | COMPUTE: 1, 16 | GLOBE: 2, 17 | TERRAIN_CLASSIFICATION: 3, 18 | CESIUM_3D_TILE: 4, 19 | CESIUM_3D_TILE_CLASSIFICATION: 5, 20 | CESIUM_3D_TILE_CLASSIFICATION_IGNORE_SHOW: 6, 21 | OPAQUE: 7, 22 | TRANSLUCENT: 8, 23 | OVERLAY: 9, 24 | NUMBER_OF_PASSES: 10 25 | }; 26 | export { Pass }; 27 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/HSLToRGB.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Converts an HSL color (hue, saturation, lightness) to RGB 3 | * HSL <-> RGB conversion: {@link http://www.chilliant.com/rgb2hsv.html} 4 | * 5 | * @name czm_HSLToRGB 6 | * @glslFunction 7 | * 8 | * @param {vec3} rgb The color in HSL. 9 | * 10 | * @returns {vec3} The color in RGB. 11 | * 12 | * @example 13 | * vec3 hsl = czm_RGBToHSL(rgb); 14 | * hsl.z *= 0.1; 15 | * rgb = czm_HSLToRGB(hsl); 16 | */ 17 | 18 | vec3 hueToRGB(float hue) 19 | { 20 | float r = abs(hue * 6.0 - 3.0) - 1.0; 21 | float g = 2.0 - abs(hue * 6.0 - 2.0); 22 | float b = 2.0 - abs(hue * 6.0 - 4.0); 23 | return clamp(vec3(r, g, b), 0.0, 1.0); 24 | } 25 | 26 | vec3 czm_HSLToRGB(vec3 hsl) 27 | { 28 | vec3 rgb = hueToRGB(hsl.x); 29 | float c = (1.0 - abs(2.0 * hsl.z - 1.0)) * hsl.y; 30 | return (rgb - 0.5) * c + hsl.z; 31 | } 32 | -------------------------------------------------------------------------------- /src/Core/getTimestamp.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Gets a timestamp that can be used in measuring the time between events. Timestamps 3 | * are expressed in milliseconds, but it is not specified what the milliseconds are 4 | * measured from. This function uses performance.now() if it is available, or Date.now() 5 | * otherwise. 6 | * 7 | * @function getTimestamp 8 | * 9 | * @returns {Number} The timestamp in milliseconds since some unspecified reference time. 10 | */ 11 | let getTimestamp: ()=> number; 12 | 13 | if ( 14 | typeof performance !== 'undefined' && 15 | typeof performance.now === 'function' && 16 | isFinite(performance.now()) 17 | ) { 18 | getTimestamp = function (): number { 19 | return performance.now(); 20 | }; 21 | } else { 22 | getTimestamp = function (): number { 23 | return Date.now(); 24 | }; 25 | } 26 | export { getTimestamp }; 27 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/getLambertDiffuse.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Calculates the intensity of diffusely reflected light. 3 | * 4 | * @name czm_getLambertDiffuse 5 | * @glslFunction 6 | * 7 | * @param {vec3} lightDirectionEC Unit vector pointing to the light source in eye coordinates. 8 | * @param {vec3} normalEC The surface normal in eye coordinates. 9 | * 10 | * @returns {float} The intensity of the diffuse reflection. 11 | * 12 | * @see czm_phong 13 | * 14 | * @example 15 | * float diffuseIntensity = czm_getLambertDiffuse(lightDirectionEC, normalEC); 16 | * float specularIntensity = czm_getSpecular(lightDirectionEC, toEyeEC, normalEC, 200); 17 | * vec3 color = (diffuseColor * diffuseIntensity) + (specularColor * specularIntensity); 18 | */ 19 | float czm_getLambertDiffuse(vec3 lightDirectionEC, vec3 normalEC) 20 | { 21 | return max(dot(lightDirectionEC, normalEC), 0.0); 22 | } 23 | -------------------------------------------------------------------------------- /src/Scene/QuadtreeTileLoadState.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The state of a {@link QuadtreeTile} in the tile load pipeline. 3 | * @enum {Number} 4 | * @private 5 | */ 6 | export enum QuadtreeTileLoadState { 7 | /** 8 | * The tile is new and loading has not yet begun. 9 | * @type QuadtreeTileLoadState 10 | * @constant 11 | * @default 0 12 | */ 13 | START = 0, 14 | 15 | /** 16 | * Loading is in progress. 17 | * @type QuadtreeTileLoadState 18 | * @constant 19 | * @default 1 20 | */ 21 | LOADING = 1, 22 | 23 | /** 24 | * Loading is complete. 25 | * @type QuadtreeTileLoadState 26 | * @constant 27 | * @default 2 28 | */ 29 | DONE = 2, 30 | 31 | /** 32 | * The tile has failed to load. 33 | * @type QuadtreeTileLoadState 34 | * @constant 35 | * @default 3 36 | */ 37 | FAILED = 3 38 | } 39 | -------------------------------------------------------------------------------- /src/Widgets/getElement.ts: -------------------------------------------------------------------------------- 1 | import { DeveloperError } from '@/Core/DeveloperError'; 2 | 3 | /** 4 | * If element is a string, look up the element in the DOM by ID. Otherwise return element. 5 | * 6 | * @private 7 | * 8 | * @exception {DeveloperError} Element with id "id" does not exist in the document. 9 | */ 10 | function getElement (element: Element | string) : Element { 11 | if (typeof element === 'string') { 12 | const foundElement = document.getElementById(element); 13 | 14 | // >>includeStart('debug', pragmas.debug); 15 | if (foundElement === null) { 16 | throw new DeveloperError( 17 | 'Element with id "' + element + '" does not exist in the document.' 18 | ); 19 | } 20 | // >>includeEnd('debug'); 21 | 22 | element = foundElement; 23 | } 24 | return element; 25 | } 26 | export default getElement; 27 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/approximateSphericalCoordinates.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Approximately computes spherical coordinates given a normal. 3 | * Uses approximate inverse trigonometry for speed and consistency, 4 | * since inverse trigonometry can differ from vendor-to-vendor and when compared with the CPU. 5 | * 6 | * @name czm_approximateSphericalCoordinates 7 | * @glslFunction 8 | * 9 | * @param {vec3} normal arbitrary-length normal. 10 | * 11 | * @returns {vec2} Approximate latitude and longitude spherical coordinates. 12 | */ 13 | vec2 czm_approximateSphericalCoordinates(vec3 normal) { 14 | // Project into plane with vertical for latitude 15 | float latitudeApproximation = czm_fastApproximateAtan(sqrt(normal.x * normal.x + normal.y * normal.y), normal.z); 16 | float longitudeApproximation = czm_fastApproximateAtan(normal.x, normal.y); 17 | return vec2(latitudeApproximation, longitudeApproximation); 18 | } 19 | -------------------------------------------------------------------------------- /src/Core/Visibility.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This enumerated type is used in determining to what extent an object, the occludee, 3 | * is visible during horizon culling. An occluder may fully block an occludee, in which case 4 | * it has no visibility, may partially block an occludee from view, or may not block it at all, 5 | * leading to full visibility. 6 | * 7 | * @enum {Number} 8 | */ 9 | export enum Visibility { 10 | /** 11 | * Represents that no part of an object is visible. 12 | * 13 | * @type {Number} 14 | * @constant 15 | */ 16 | NONE = -1, 17 | 18 | /** 19 | * Represents that part, but not all, of an object is visible 20 | * 21 | * @type {Number} 22 | * @constant 23 | */ 24 | PARTIAL = 0, 25 | 26 | /** 27 | * Represents that an object is visible in its entirety. 28 | * 29 | * @type {Number} 30 | * @constant 31 | */ 32 | FULL = 1 33 | } 34 | -------------------------------------------------------------------------------- /src/Core/Credit.ts: -------------------------------------------------------------------------------- 1 | import { defaultValue } from './defaultValue'; 2 | import { defined } from './defined'; 3 | 4 | let nextCreditId = 0; 5 | const creditToId = {}; 6 | 7 | class Credit { 8 | _id: any; 9 | _html: string; 10 | _showOnScreen: boolean; 11 | _element?: any; 12 | constructor (html: string, showOnScreen = false) { 13 | let id; 14 | const key = html; 15 | 16 | if (defined(creditToId[key])) { 17 | id = creditToId[key]; 18 | } else { 19 | id = nextCreditId++; 20 | creditToId[key] = id; 21 | } 22 | 23 | showOnScreen = defaultValue(showOnScreen, false); 24 | 25 | // Credits are immutable so generate an id to use to optimize equal() 26 | this._id = id; 27 | this._html = html; 28 | this._showOnScreen = showOnScreen; 29 | this._element = undefined; 30 | } 31 | } 32 | 33 | export { Credit }; 34 | -------------------------------------------------------------------------------- /src/Core/BoundingRectangle.ts: -------------------------------------------------------------------------------- 1 | 2 | class BoundingRectangle { 3 | x: number; 4 | y: number; 5 | width: number; 6 | height: number; 7 | constructor (x = 0.0, y = 0.0, width = 0.0, height = 0.0) { 8 | /** 9 | * The x coordinate of the rectangle. 10 | * @type {Number} 11 | * @default 0.0 12 | */ 13 | this.x = x; 14 | 15 | /** 16 | * The y coordinate of the rectangle. 17 | * @type {Number} 18 | * @default 0.0 19 | */ 20 | this.y = y; 21 | 22 | /** 23 | * The width of the rectangle. 24 | * @type {Number} 25 | * @default 0.0 26 | */ 27 | this.width = width; 28 | 29 | /** 30 | * The height of the rectangle. 31 | * @type {Number} 32 | * @default 0.0 33 | */ 34 | this.height = height; 35 | } 36 | } 37 | 38 | export { BoundingRectangle }; 39 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/RGBToHSB.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Converts an RGB color to HSB (hue, saturation, brightness) 3 | * HSB <-> RGB conversion with minimal branching: {@link http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl} 4 | * 5 | * @name czm_RGBToHSB 6 | * @glslFunction 7 | * 8 | * @param {vec3} rgb The color in RGB. 9 | * 10 | * @returns {vec3} The color in HSB. 11 | * 12 | * @example 13 | * vec3 hsb = czm_RGBToHSB(rgb); 14 | * hsb.z *= 0.1; 15 | * rgb = czm_HSBToRGB(hsb); 16 | */ 17 | 18 | const vec4 K_RGB2HSB = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); 19 | 20 | vec3 czm_RGBToHSB(vec3 rgb) 21 | { 22 | vec4 p = mix(vec4(rgb.bg, K_RGB2HSB.wz), vec4(rgb.gb, K_RGB2HSB.xy), step(rgb.b, rgb.g)); 23 | vec4 q = mix(vec4(p.xyw, rgb.r), vec4(rgb.r, p.yzx), step(p.x, rgb.r)); 24 | 25 | float d = q.x - min(q.w, q.y); 26 | return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + czm_epsilon7)), d / (q.x + czm_epsilon7), q.x); 27 | } 28 | -------------------------------------------------------------------------------- /src/Core/isCrossOriginUrl.ts: -------------------------------------------------------------------------------- 1 | import { defined } from './defined'; 2 | 3 | let a: any; 4 | 5 | /** 6 | * Given a URL, determine whether that URL is considered cross-origin to the current page. 7 | * 8 | * @private 9 | */ 10 | function isCrossOriginUrl (url: string): boolean { 11 | if (!defined(a)) { 12 | a = document.createElement('a'); 13 | } 14 | 15 | // copy window location into the anchor to get consistent results 16 | // when the port is default for the protocol (e.g. 80 for HTTP) 17 | a.href = window.location.href; 18 | 19 | // host includes both hostname and port if the port is not standard 20 | const host = a.host; 21 | const protocol = a.protocol; 22 | 23 | a.href = url; 24 | // IE only absolutizes href on get, not set 25 | // eslint-disable-next-line no-self-assign 26 | a.href = a.href; 27 | 28 | return protocol !== a.protocol || host !== a.host; 29 | } 30 | export { isCrossOriginUrl }; 31 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/getDefaultMaterial.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * An czm_material with default values. Every material's czm_getMaterial 3 | * should use this default material as a base for the material it returns. 4 | * The default normal value is given by materialInput.normalEC. 5 | * 6 | * @name czm_getDefaultMaterial 7 | * @glslFunction 8 | * 9 | * @param {czm_materialInput} input The input used to construct the default material. 10 | * 11 | * @returns {czm_material} The default material. 12 | * 13 | * @see czm_materialInput 14 | * @see czm_material 15 | * @see czm_getMaterial 16 | */ 17 | czm_material czm_getDefaultMaterial(czm_materialInput materialInput) 18 | { 19 | czm_material material; 20 | material.diffuse = vec3(0.0); 21 | material.specular = 0.0; 22 | material.shininess = 1.0; 23 | material.normal = materialInput.normalEC; 24 | material.emission = vec3(0.0); 25 | material.alpha = 1.0; 26 | return material; 27 | } 28 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/RGBToXYZ.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Converts an RGB color to CIE Yxy. 3 | *

The conversion is described in 4 | * {@link http://content.gpwiki.org/index.php/D3DBook:High-Dynamic_Range_Rendering#Luminance_Transform|Luminance Transform} 5 | *

6 | * 7 | * @name czm_RGBToXYZ 8 | * @glslFunction 9 | * 10 | * @param {vec3} rgb The color in RGB. 11 | * 12 | * @returns {vec3} The color in CIE Yxy. 13 | * 14 | * @example 15 | * vec3 xyz = czm_RGBToXYZ(rgb); 16 | * xyz.x = max(xyz.x - luminanceThreshold, 0.0); 17 | * rgb = czm_XYZToRGB(xyz); 18 | */ 19 | vec3 czm_RGBToXYZ(vec3 rgb) 20 | { 21 | const mat3 RGB2XYZ = mat3(0.4124, 0.2126, 0.0193, 22 | 0.3576, 0.7152, 0.1192, 23 | 0.1805, 0.0722, 0.9505); 24 | vec3 xyz = RGB2XYZ * rgb; 25 | vec3 Yxy; 26 | Yxy.r = xyz.g; 27 | float temp = dot(vec3(1.0), xyz); 28 | Yxy.gb = xyz.rg / temp; 29 | return Yxy; 30 | } 31 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/unpackFloat.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Unpack an IEEE 754 single-precision float that is packed as a little-endian unsigned normalized vec4. 3 | * 4 | * @name czm_unpackFloat 5 | * @glslFunction 6 | * 7 | * @param {vec4} packedFloat The packed float. 8 | * 9 | * @returns {float} The floating-point depth in arbitrary range. 10 | */ 11 | float czm_unpackFloat(vec4 packedFloat) 12 | { 13 | // Convert to [0.0, 255.0] and round to integer 14 | packedFloat = floor(packedFloat * 255.0 + 0.5); 15 | float sign = 1.0 - step(128.0, packedFloat[3]) * 2.0; 16 | float exponent = 2.0 * mod(packedFloat[3], 128.0) + step(128.0, packedFloat[2]) - 127.0; 17 | if (exponent == -127.0) 18 | { 19 | return 0.0; 20 | } 21 | float mantissa = mod(packedFloat[2], 128.0) * 65536.0 + packedFloat[1] * 256.0 + packedFloat[0] + float(0x800000); 22 | float result = sign * exp2(exponent - 23.0) * mantissa; 23 | return result; 24 | } 25 | -------------------------------------------------------------------------------- /src/Core/HeadingPitchRange.ts: -------------------------------------------------------------------------------- 1 | class HeadingPitchRange { 2 | heading: number; 3 | pitch: number; 4 | range: number; 5 | constructor (heading = 0.0, pitch = 0.0, range = 0.0) { 6 | /** 7 | * Heading is the rotation from the local north direction where a positive angle is increasing eastward. 8 | * @type {Number} 9 | * @default 0.0 10 | */ 11 | this.heading = heading; 12 | 13 | /** 14 | * Pitch is the rotation from the local xy-plane. Positive pitch angles 15 | * are above the plane. Negative pitch angles are below the plane. 16 | * @type {Number} 17 | * @default 0.0 18 | */ 19 | this.pitch = pitch; 20 | 21 | /** 22 | * Range is the distance from the center of the local frame. 23 | * @type {Number} 24 | * @default 0.0 25 | */ 26 | this.range = range; 27 | } 28 | } 29 | 30 | export { HeadingPitchRange }; 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # threejs-map 2 | 3 | ## Project setup 4 | ``` 5 | npm install 6 | ``` 7 | 8 | ### Compiles and hot-reloads for development 9 | ``` 10 | npm run serve 11 | ``` 12 | 13 | ### Compiles and minifies for production 14 | ``` 15 | npm run build 16 | ``` 17 | 18 | ### Lints and fixes files 19 | ``` 20 | npm run lint 21 | ``` 22 | 没空维护这个项目了,这个球就先到这里吧,主要是发现使用球之后,需要考虑的情况太过复杂,一个人维护不过来,感觉要跳到GIS坑里面爬不出来了 23 | 24 | 代码也只是个雏形,注释很少(可以说是没有吧),也有很多地方是冗余的,可以说是垃圾代码,主要是想试试看自己能不能写出一个球来 25 | 26 | 不过里面倒是踏平了一些坑,球的主体逻辑是从Cesium移植过来的,踩过了一些移植的坑,比如84投影的瓦片重投影问题,瓦片层级切换时如何不产生黑块或者空白快,attribute压缩,当level>4(也可能是level>8,忘了,哈哈,1.83版本可能是大于4就不需要重投影了,自己慢慢看吧☺)时的性能优化问题,简单提一嘴,当层级比较高时,就不需要进行重投影了,每个瓦片就是一个标准的正方形的形状(其实不是,在Cesium中瓦片的mesh最终形状是一个无底的长方体),因此每一个瓦片的Geometry数据是一样的,不过目前的性能还是比不上Cesium,原因可能在于threejs创建的Program数量要比Cesium的多,暂时还不清楚是我自己的原因还是threejs的原因,哪位大神如果知道的话,还请赐教! 27 | 28 | 另外,鼠标操作也是抄的Cesium,核心的一点就是Control最终计算的矩阵能对的上threejs的Camera的矩阵就ok了 29 | 30 | 要用的话就拿去用吧,不过最后还是厚脸皮求个star!!! 31 | 32 | 引流:有问题可以去QQ群问,群号:173306525 33 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/XYZToRGB.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Converts a CIE Yxy color to RGB. 3 | *

The conversion is described in 4 | * {@link http://content.gpwiki.org/index.php/D3DBook:High-Dynamic_Range_Rendering#Luminance_Transform|Luminance Transform} 5 | *

6 | * 7 | * @name czm_XYZToRGB 8 | * @glslFunction 9 | * 10 | * @param {vec3} Yxy The color in CIE Yxy. 11 | * 12 | * @returns {vec3} The color in RGB. 13 | * 14 | * @example 15 | * vec3 xyz = czm_RGBToXYZ(rgb); 16 | * xyz.x = max(xyz.x - luminanceThreshold, 0.0); 17 | * rgb = czm_XYZToRGB(xyz); 18 | */ 19 | vec3 czm_XYZToRGB(vec3 Yxy) 20 | { 21 | const mat3 XYZ2RGB = mat3( 3.2405, -0.9693, 0.0556, 22 | -1.5371, 1.8760, -0.2040, 23 | -0.4985, 0.0416, 1.0572); 24 | vec3 xyz; 25 | xyz.r = Yxy.r * Yxy.g / Yxy.b; 26 | xyz.g = Yxy.r; 27 | xyz.b = Yxy.r * (1.0 - Yxy.g - Yxy.b) / Yxy.b; 28 | 29 | return XYZ2RGB * xyz; 30 | } 31 | -------------------------------------------------------------------------------- /src/Core/Intersect.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This enumerated type is used in determining where, relative to the frustum, an 3 | * object is located. The object can either be fully contained within the frustum (INSIDE), 4 | * partially inside the frustum and partially outside (INTERSECTING), or somwhere entirely 5 | * outside of the frustum's 6 planes (OUTSIDE). 6 | * 7 | * @exports Intersect 8 | */ 9 | export enum Intersect { 10 | /** 11 | * Represents that an object is not contained within the frustum. 12 | * 13 | * @type {Number} 14 | * @constant 15 | */ 16 | OUTSIDE = -1, 17 | 18 | /** 19 | * Represents that an object intersects one of the frustum's planes. 20 | * 21 | * @type {Number} 22 | * @constant 23 | */ 24 | INTERSECTING = 0, 25 | 26 | /** 27 | * Represents that an object is fully within the frustum. 28 | * 29 | * @type {Number} 30 | * @constant 31 | */ 32 | INSIDE = 1 33 | } 34 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <%= htmlWebpackPlugin.options.title %> 9 | 10 | 22 | 23 | 26 |
27 | 28 |
29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/Renderer/WebGL/WebGLProgram.d.ts: -------------------------------------------------------------------------------- 1 | import { WebGLRenderer, WebGLUniforms, WebGLShader } from "three"; 2 | import { WebGLBindingStates } from "three/src/renderers/webgl/WebGLBindingStates"; 3 | 4 | 5 | export class WebGLProgram { 6 | constructor(renderer: WebGLRenderer, cacheKey: string, parameters: object, bindingStates: WebGLBindingStates); 7 | 8 | name: string; 9 | id: number; 10 | cacheKey: string; // unique identifier for this program, used for looking up compiled programs from cache. 11 | 12 | /** 13 | * @default 1 14 | */ 15 | usedTimes: number; 16 | program: any; 17 | vertexShader: WebGLShader; 18 | fragmentShader: WebGLShader; 19 | /** 20 | * @deprecated Use {@link WebGLProgram#getUniforms getUniforms()} instead. 21 | */ 22 | uniforms: any; 23 | /** 24 | * @deprecated Use {@link WebGLProgram#getAttributes getAttributes()} instead. 25 | */ 26 | attributes: any; 27 | 28 | getUniforms(): WebGLUniforms; 29 | getAttributes(): any; 30 | destroy(): void; 31 | } 32 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/signNotZero.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Returns 1.0 if the given value is positive or zero, and -1.0 if it is negative. This is similar to the GLSL 3 | * built-in function sign except that returns 1.0 instead of 0.0 when the input value is 0.0. 4 | * 5 | * @name czm_signNotZero 6 | * @glslFunction 7 | * 8 | * @param {} value The value for which to determine the sign. 9 | * @returns {} 1.0 if the value is positive or zero, -1.0 if the value is negative. 10 | */ 11 | float czm_signNotZero(float value) 12 | { 13 | return value >= 0.0 ? 1.0 : -1.0; 14 | } 15 | 16 | vec2 czm_signNotZero(vec2 value) 17 | { 18 | return vec2(czm_signNotZero(value.x), czm_signNotZero(value.y)); 19 | } 20 | 21 | vec3 czm_signNotZero(vec3 value) 22 | { 23 | return vec3(czm_signNotZero(value.x), czm_signNotZero(value.y), czm_signNotZero(value.z)); 24 | } 25 | 26 | vec4 czm_signNotZero(vec4 value) 27 | { 28 | return vec4(czm_signNotZero(value.x), czm_signNotZero(value.y), czm_signNotZero(value.z), czm_signNotZero(value.w)); 29 | } 30 | -------------------------------------------------------------------------------- /src/Renderer/WebGL/WebGLPrograms.d.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | import { WebGLCapabilities, WebGLRenderer, WebGLExtensions, WebGLClipping, Material, Scene } from "three"; 4 | import { WebGLBindingStates } from "three/src/renderers/webgl/WebGLBindingStates"; 5 | import { WebGLCubeMaps } from "three/src/renderers/webgl/WebGLCubeMaps"; 6 | import { WebGLProgram } from "./WebGLProgram"; 7 | 8 | 9 | 10 | export class WebGLPrograms { 11 | constructor( 12 | renderer: WebGLRenderer, 13 | cubemaps: WebGLCubeMaps, 14 | extensions: WebGLExtensions, 15 | capabilities: WebGLCapabilities, 16 | bindingStates: WebGLBindingStates, 17 | clipping: WebGLClipping, 18 | ); 19 | 20 | programs: WebGLProgram[]; 21 | 22 | getParameters(material: Material, lights: any, shadows: object[], scene: Scene, object: any): any; 23 | getProgramCacheKey(parameters: any): string; 24 | getUniforms(material: Material): object; 25 | acquireProgram(parameters: any, cacheKey: string): WebGLProgram; 26 | releaseProgram(program: WebGLProgram): void; 27 | } 28 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/translucentPhong.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * @private 3 | */ 4 | vec4 czm_translucentPhong(vec3 toEye, czm_material material, vec3 lightDirectionEC) 5 | { 6 | // Diffuse from directional light sources at eye (for top-down and horizon views) 7 | float diffuse = czm_getLambertDiffuse(vec3(0.0, 0.0, 1.0), material.normal); 8 | 9 | if (czm_sceneMode == czm_sceneMode3D) { 10 | // (and horizon views in 3D) 11 | diffuse += czm_getLambertDiffuse(vec3(0.0, 1.0, 0.0), material.normal); 12 | } 13 | 14 | diffuse = clamp(diffuse, 0.0, 1.0); 15 | 16 | float specular = czm_getSpecular(lightDirectionEC, toEye, material.normal, material.shininess); 17 | 18 | // Temporary workaround for adding ambient. 19 | vec3 materialDiffuse = material.diffuse * 0.5; 20 | 21 | vec3 ambient = materialDiffuse; 22 | vec3 color = ambient + material.emission; 23 | color += materialDiffuse * diffuse * czm_lightColor; 24 | color += material.specular * specular * czm_lightColor; 25 | 26 | return vec4(color, material.alpha); 27 | } 28 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/planeDistance.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Computes distance from a point to a plane. 3 | * 4 | * @name czm_planeDistance 5 | * @glslFunction 6 | * 7 | * param {vec4} plane A Plane in Hessian Normal Form. See Plane.js 8 | * param {vec3} point A point in the same space as the plane. 9 | * returns {float} The distance from the point to the plane. 10 | */ 11 | float czm_planeDistance(vec4 plane, vec3 point) { 12 | return (dot(plane.xyz, point) + plane.w); 13 | } 14 | 15 | /** 16 | * Computes distance from a point to a plane. 17 | * 18 | * @name czm_planeDistance 19 | * @glslFunction 20 | * 21 | * param {vec3} planeNormal Normal for a plane in Hessian Normal Form. See Plane.js 22 | * param {float} planeDistance Distance for a plane in Hessian Normal form. See Plane.js 23 | * param {vec3} point A point in the same space as the plane. 24 | * returns {float} The distance from the point to the plane. 25 | */ 26 | float czm_planeDistance(vec3 planeNormal, float planeDistance, vec3 point) { 27 | return (dot(planeNormal, point) + planeDistance); 28 | } 29 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", 4 | "module": "esnext", 5 | "strict": true, 6 | "jsx": "preserve", 7 | "importHelpers": true, 8 | "moduleResolution": "node", 9 | "experimentalDecorators": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "suppressImplicitAnyIndexErrors":true, 14 | "sourceMap": true, 15 | "noImplicitThis": false, 16 | "baseUrl": ".", 17 | "types": [ 18 | "webpack-env" 19 | ], 20 | "paths": { 21 | "@/*": [ 22 | "src/*" 23 | ] 24 | }, 25 | "lib": [ 26 | "esnext", 27 | "dom", 28 | "dom.iterable", 29 | "scripthost" 30 | ] 31 | }, 32 | "include": [ 33 | "src/**/*.ts", 34 | "src/**/*.glsl", 35 | "src/**/*.tsx", 36 | "src/**/*.vue", 37 | "tests/**/*.ts", 38 | "tests/**/*.tsx" 39 | , "src/ThirdParty/when.ts", "src/Renderer/WebGL/WebGLProgram.js" ], 40 | "exclude": [ 41 | "node_modules", 42 | "src/Renderer/WebGL" 43 | ] 44 | } 45 | -------------------------------------------------------------------------------- /src/Core/clone.ts: -------------------------------------------------------------------------------- 1 | import { defaultValue } from './defaultValue'; 2 | 3 | /** 4 | * Clones an object, returning a new object containing the same properties. 5 | * 6 | * @function 7 | * 8 | * @param {Object} object The object to clone. 9 | * @param {Boolean} [deep=false] If true, all properties will be deep cloned recursively. 10 | * @returns {Object} The cloned object. 11 | */ 12 | function clone (object:any, deep = false) :any { 13 | if (object === null || typeof object !== 'object') { 14 | return object; 15 | } 16 | 17 | deep = defaultValue(deep, false); 18 | 19 | const result = new object.constructor(); 20 | for (const propertyName in object) { 21 | // if (object.hasOwnProperty(propertyName)) { 22 | 23 | if (Object.prototype.hasOwnProperty.call(object, propertyName)) { 24 | let value = object[propertyName]; 25 | if (deep) { 26 | value = clone(value, deep); 27 | } 28 | result[propertyName] = value; 29 | } 30 | } 31 | 32 | return result; 33 | } 34 | export { clone }; 35 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/nearFarScalar.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Computes a value that scales with distance. The scaling is clamped at the near and 3 | * far distances, and does not extrapolate. This function works with the 4 | * {@link NearFarScalar} JavaScript class. 5 | * 6 | * @name czm_nearFarScalar 7 | * @glslFunction 8 | * 9 | * @param {vec4} nearFarScalar A vector with 4 components: Near distance (x), Near value (y), Far distance (z), Far value (w). 10 | * @param {float} cameraDistSq The square of the current distance from the camera. 11 | * 12 | * @returns {float} The value at this distance. 13 | */ 14 | float czm_nearFarScalar(vec4 nearFarScalar, float cameraDistSq) 15 | { 16 | float valueAtMin = nearFarScalar.y; 17 | float valueAtMax = nearFarScalar.w; 18 | float nearDistanceSq = nearFarScalar.x * nearFarScalar.x; 19 | float farDistanceSq = nearFarScalar.z * nearFarScalar.z; 20 | 21 | float t = (cameraDistSq - nearDistanceSq) / (farDistanceSq - nearDistanceSq); 22 | 23 | t = pow(clamp(t, 0.0, 1.0), 0.2); 24 | 25 | return mix(valueAtMin, valueAtMax, t); 26 | } 27 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/RGBToHSL.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Converts an RGB color to HSL (hue, saturation, lightness) 3 | * HSL <-> RGB conversion: {@link http://www.chilliant.com/rgb2hsv.html} 4 | * 5 | * @name czm_RGBToHSL 6 | * @glslFunction 7 | * 8 | * @param {vec3} rgb The color in RGB. 9 | * 10 | * @returns {vec3} The color in HSL. 11 | * 12 | * @example 13 | * vec3 hsl = czm_RGBToHSL(rgb); 14 | * hsl.z *= 0.1; 15 | * rgb = czm_HSLToRGB(hsl); 16 | */ 17 | 18 | vec3 RGBtoHCV(vec3 rgb) 19 | { 20 | // Based on work by Sam Hocevar and Emil Persson 21 | vec4 p = (rgb.g < rgb.b) ? vec4(rgb.bg, -1.0, 2.0 / 3.0) : vec4(rgb.gb, 0.0, -1.0 / 3.0); 22 | vec4 q = (rgb.r < p.x) ? vec4(p.xyw, rgb.r) : vec4(rgb.r, p.yzx); 23 | float c = q.x - min(q.w, q.y); 24 | float h = abs((q.w - q.y) / (6.0 * c + czm_epsilon7) + q.z); 25 | return vec3(h, c, q.x); 26 | } 27 | 28 | vec3 czm_RGBToHSL(vec3 rgb) 29 | { 30 | vec3 hcv = RGBtoHCV(rgb); 31 | float l = hcv.z - hcv.y * 0.5; 32 | float s = hcv.y / (1.0 - abs(l * 2.0 - 1.0) + czm_epsilon7); 33 | return vec3(hcv.x, s, l); 34 | } 35 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/tangentToEyeSpaceMatrix.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a matrix that transforms vectors from tangent space to eye space. 3 | * 4 | * @name czm_tangentToEyeSpaceMatrix 5 | * @glslFunction 6 | * 7 | * @param {vec3} normalEC The normal vector in eye coordinates. 8 | * @param {vec3} tangentEC The tangent vector in eye coordinates. 9 | * @param {vec3} bitangentEC The bitangent vector in eye coordinates. 10 | * 11 | * @returns {mat3} The matrix that transforms from tangent space to eye space. 12 | * 13 | * @example 14 | * mat3 tangentToEye = czm_tangentToEyeSpaceMatrix(normalEC, tangentEC, bitangentEC); 15 | * vec3 normal = tangentToEye * texture2D(normalMap, st).xyz; 16 | */ 17 | mat3 czm_tangentToEyeSpaceMatrix(vec3 normalEC, vec3 tangentEC, vec3 bitangentEC) 18 | { 19 | vec3 normal = normalize(normalEC); 20 | vec3 tangent = normalize(tangentEC); 21 | vec3 bitangent = normalize(bitangentEC); 22 | return mat3(tangent.x , tangent.y , tangent.z, 23 | bitangent.x, bitangent.y, bitangent.z, 24 | normal.x , normal.y , normal.z); 25 | } 26 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/hue.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Adjusts the hue of a color. 3 | * 4 | * @name czm_hue 5 | * @glslFunction 6 | * 7 | * @param {vec3} rgb The color. 8 | * @param {float} adjustment The amount to adjust the hue of the color in radians. 9 | * 10 | * @returns {float} The color with the hue adjusted. 11 | * 12 | * @example 13 | * vec3 adjustHue = czm_hue(color, czm_pi); // The same as czm_hue(color, -czm_pi) 14 | */ 15 | vec3 czm_hue(vec3 rgb, float adjustment) 16 | { 17 | const mat3 toYIQ = mat3(0.299, 0.587, 0.114, 18 | 0.595716, -0.274453, -0.321263, 19 | 0.211456, -0.522591, 0.311135); 20 | const mat3 toRGB = mat3(1.0, 0.9563, 0.6210, 21 | 1.0, -0.2721, -0.6474, 22 | 1.0, -1.107, 1.7046); 23 | 24 | vec3 yiq = toYIQ * rgb; 25 | float hue = atan(yiq.z, yiq.y) + adjustment; 26 | float chroma = sqrt(yiq.z * yiq.z + yiq.y * yiq.y); 27 | 28 | vec3 color = vec3(yiq.x, chroma * cos(hue), chroma * sin(hue)); 29 | return toRGB * color; 30 | } 31 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Structs/material.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Holds material information that can be used for lighting. Returned by all czm_getMaterial functions. 3 | * 4 | * @name czm_material 5 | * @glslStruct 6 | * 7 | * @property {vec3} diffuse Incoming light that scatters evenly in all directions. 8 | * @property {float} specular Intensity of incoming light reflecting in a single direction. 9 | * @property {float} shininess The sharpness of the specular reflection. Higher values create a smaller, more focused specular highlight. 10 | * @property {vec3} normal Surface's normal in eye coordinates. It is used for effects such as normal mapping. The default is the surface's unmodified normal. 11 | * @property {vec3} emission Light emitted by the material equally in all directions. The default is vec3(0.0), which emits no light. 12 | * @property {float} alpha Opacity of this material. 0.0 is completely transparent; 1.0 is completely opaque. 13 | */ 14 | struct czm_material 15 | { 16 | vec3 diffuse; 17 | float specular; 18 | float shininess; 19 | vec3 normal; 20 | vec3 emission; 21 | float alpha; 22 | }; 23 | -------------------------------------------------------------------------------- /src/Extension/Vector3Extension.ts: -------------------------------------------------------------------------------- 1 | import { Vector3 } from 'three'; 2 | 3 | // declare module 'three/src/math/Vector3' { 4 | // export interface Vector3 { 5 | // UNIT_X: Vector3 6 | // } 7 | // } 8 | 9 | /** 10 | * An immutable Cartesian3 instance initialized to (0.0, 0.0, 0.0). 11 | * 12 | * @type {Cartesian3} 13 | * @constant 14 | */ 15 | (Vector3 as any).ZERO = Object.freeze(new Vector3(0.0, 0.0, 0.0)); 16 | 17 | /** 18 | * An immutable Cartesian3 instance initialized to (1.0, 0.0, 0.0). 19 | * 20 | * @type {Cartesian3} 21 | * @constant 22 | */ 23 | (Vector3 as any).UNIT_X = Object.freeze(new Vector3(1.0, 0.0, 0.0)); 24 | 25 | /** 26 | * An immutable Cartesian3 instance initialized to (0.0, 1.0, 0.0). 27 | * 28 | * @type {Cartesian3} 29 | * @constant 30 | */ 31 | (Vector3 as any).UNIT_Y = Object.freeze(new Vector3(0.0, 1.0, 0.0)); 32 | 33 | /** 34 | * An immutable Cartesian3 instance initialized to (0.0, 0.0, 1.0). 35 | * 36 | * @type {Cartesian3} 37 | * @constant 38 | */ 39 | (Vector3 as any).UNIT_Z = Object.freeze(new Vector3(0.0, 0.0, 1.0)); 40 | 41 | export { Vector3 }; 42 | -------------------------------------------------------------------------------- /src/Core/RequestState.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * State of the request. 3 | * 4 | * @enum {Number} 5 | */ 6 | enum RequestState { 7 | /** 8 | * Initial unissued state. 9 | * 10 | * @type Number 11 | * @constant 12 | */ 13 | UNISSUED = 0, 14 | 15 | /** 16 | * Issued but not yet active. Will become active when open slots are available. 17 | * 18 | * @type Number 19 | * @constant 20 | */ 21 | ISSUED = 1, 22 | 23 | /** 24 | * Actual http request has been sent. 25 | * 26 | * @type Number 27 | * @constant 28 | */ 29 | ACTIVE = 2, 30 | 31 | /** 32 | * Request completed successfully. 33 | * 34 | * @type Number 35 | * @constant 36 | */ 37 | RECEIVED = 3, 38 | 39 | /** 40 | * Request was cancelled, either explicitly or automatically because of low priority. 41 | * 42 | * @type Number 43 | * @constant 44 | */ 45 | CANCELLED = 4, 46 | 47 | /** 48 | * Request failed. 49 | * 50 | * @type Number 51 | * @constant 52 | */ 53 | FAILED = 5 54 | } 55 | 56 | export { RequestState }; 57 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/pbrSpecularGlossinessMaterial.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Compute parameters for physically based rendering using the 3 | * specular/glossy workflow. All inputs are linear; sRGB texture values must 4 | * be decoded beforehand 5 | * 6 | * @name czm_pbrSpecularGlossinessMaterial 7 | * @glslFunction 8 | * 9 | * @param {vec3} diffuse The diffuse color for dielectrics (non-metals) 10 | * @param {vec3} specular The reflectance at normal incidence (f0) 11 | * @param {float} glossiness A number from 0.0 to 1.0 indicating how smooth the surface is. 12 | * @return {czm_pbrParameters} parameters to pass into {@link czm_pbrLighting} 13 | */ 14 | czm_pbrParameters czm_pbrSpecularGlossinessMaterial( 15 | vec3 diffuse, 16 | vec3 specular, 17 | float glossiness 18 | ) { 19 | czm_pbrParameters results; 20 | 21 | // glossiness is the opposite of roughness, but easier for artists to use. 22 | float roughness = 1.0 - glossiness; 23 | results.roughness = roughness * roughness; 24 | 25 | results.diffuseColor = diffuse * (1.0 - max(max(specular.r, specular.g), specular.b)); 26 | results.f0 = specular; 27 | 28 | return results; 29 | } 30 | -------------------------------------------------------------------------------- /src/Scene/Picking.ts: -------------------------------------------------------------------------------- 1 | import { Cartesian2 } from '@/Core/Cartesian2'; 2 | import { Vector3 } from 'three'; 3 | import { PickDepth } from './PickDepth'; 4 | import { Scene } from './Scene'; 5 | 6 | class Picking { 7 | scene: Scene; 8 | pickDepth: PickDepth; 9 | constructor (scene: Scene) { 10 | // 保存主场景 11 | this.scene = scene; 12 | 13 | // 用于计算深度 14 | this.pickDepth = new PickDepth(scene); 15 | } 16 | 17 | pickPositionWorldCoordinates (windowPosition: Cartesian2, result: Vector3): Vector3 | undefined { 18 | if (!this.scene.useDepthPicking) { 19 | return undefined; 20 | } 21 | } 22 | 23 | // 根据depthTexture获取深度 24 | // getDepth (x: number, y: number, frustum: Frustum) { 25 | // const pixels = this.pickDepth.getDepth(x, y, frustum); 26 | 27 | // if (this.pickDepth.depthMaterial.depthPacking === RGBADepthPacking) { 28 | // const packedDepth = (Vector4 as any).unpack(pixels, 0, scratchPackedDepth); 29 | // return packedDepth.dot(UnpackFactors) * 2 - 1; 30 | // } 31 | 32 | // return -pixels[0] * 2.0 + 1.0; 33 | // } 34 | } 35 | 36 | export { Picking }; 37 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/latitudeToWebMercatorFraction.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Computes the fraction of a Web Wercator rectangle at which a given geodetic latitude is located. 3 | * 4 | * @name czm_latitudeToWebMercatorFraction 5 | * @glslFunction 6 | * 7 | * @param {float} latitude The geodetic latitude, in radians. 8 | * @param {float} southMercatorY The Web Mercator coordinate of the southern boundary of the rectangle. 9 | * @param {float} oneOverMercatorHeight The total height of the rectangle in Web Mercator coordinates. 10 | * 11 | * @returns {float} The fraction of the rectangle at which the latitude occurs. If the latitude is the southern 12 | * boundary of the rectangle, the return value will be zero. If it is the northern boundary, the return 13 | * value will be 1.0. Latitudes in between are mapped according to the Web Mercator projection. 14 | */ 15 | float czm_latitudeToWebMercatorFraction(float latitude, float southMercatorY, float oneOverMercatorHeight) 16 | { 17 | float sinLatitude = sin(latitude); 18 | float mercatorY = 0.5 * log((1.0 + sinLatitude) / (1.0 - sinLatitude)); 19 | 20 | return (mercatorY - southMercatorY) * oneOverMercatorHeight; 21 | } 22 | -------------------------------------------------------------------------------- /src/Scene/MapRenderer.ts: -------------------------------------------------------------------------------- 1 | import { LinearToneMapping, sRGBEncoding, Vector2, WebGLRenderer, WebGLRendererParameters } from 'three'; 2 | 3 | export interface RenderStateParameters extends WebGLRendererParameters{ 4 | antialias?: true 5 | } 6 | 7 | const drawingBufferSize = new Vector2(); 8 | 9 | class MapRenderer extends WebGLRenderer { 10 | constructor (options?: WebGLRendererParameters) { 11 | super(options); 12 | 13 | // const { clientWidth, clientHeight } = container; 14 | 15 | // this.setSize(clientWidth, clientHeight); 16 | // this.setViewport(0, 0, clientWidth, clientHeight); 17 | this.autoClear = false; 18 | this.toneMapping = LinearToneMapping; 19 | this.toneMappingExposure = 1.0; 20 | this.outputEncoding = sRGBEncoding; 21 | 22 | this.setClearColor(0x128caa); 23 | 24 | // container.appendChild(this.domElement); 25 | } 26 | 27 | /** 28 | * 返回当前绘图缓冲区的尺寸 29 | * 30 | * @readonly 31 | * @type {Vector2} 32 | * @memberof MapRenderer 33 | */ 34 | get drawingBufferSize (): Vector2 { 35 | return this.getDrawingBufferSize(drawingBufferSize); 36 | } 37 | } 38 | 39 | export { MapRenderer }; 40 | -------------------------------------------------------------------------------- /src/Core/getExtensionFromUri.ts: -------------------------------------------------------------------------------- 1 | import { URI as Uri } from '../ThirdParty/Uri'; 2 | import { defined } from './defined'; 3 | import { DeveloperError } from './DeveloperError'; 4 | 5 | /** 6 | * Given a URI, returns the extension of the URI. 7 | * @function getExtensionFromUri 8 | * 9 | * @param {String} uri The Uri. 10 | * @returns {String} The extension of the Uri. 11 | * 12 | * @example 13 | * //extension will be "czml"; 14 | * var extension = Cesium.getExtensionFromUri('/Gallery/simple.czml?value=true&example=false'); 15 | */ 16 | function getExtensionFromUri (uri: string): string { 17 | // >>includeStart('debug', pragmas.debug); 18 | if (!defined(uri)) { 19 | throw new DeveloperError('uri is required.'); 20 | } 21 | // >>includeEnd('debug'); 22 | 23 | const uriObject = new Uri(uri); 24 | uriObject.normalize(); 25 | let path = uriObject.path; 26 | let index = path.lastIndexOf('/'); 27 | if (index !== -1) { 28 | path = path.substr(index + 1); 29 | } 30 | index = path.lastIndexOf('.'); 31 | if (index === -1) { 32 | path = ''; 33 | } else { 34 | path = path.substr(index + 1); 35 | } 36 | return path; 37 | } 38 | export { getExtensionFromUri }; 39 | -------------------------------------------------------------------------------- /src/Scene/RenderCollection.ts: -------------------------------------------------------------------------------- 1 | import { Object3DCollection } from '@/Core/Object3DCollection'; 2 | import { Frustum } from 'three'; 3 | 4 | import { FrameState } from './FrameState.js'; 5 | 6 | class RenderCollection extends Object3DCollection { 7 | frustum?: Frustum = undefined 8 | // 用于做裁剪的视锥体 9 | // constructor () { 10 | // super(); 11 | // } 12 | 13 | addPickCommands (commandList: any): void { 14 | for (let i = 0, len = commandList.length; i < len; i++) { 15 | const command = commandList[i]; 16 | // if (command.allowPicking && this.frustum.intersectsSphere(command.boundingSphere)) { 17 | // // this.addObject(command); 18 | // } 19 | if (command.allowPicking) { 20 | this.addObject(command); 21 | } 22 | } 23 | } 24 | 25 | /** 26 | * 在渲染之前更新将要渲染的command 27 | * 28 | * @memberof RenderCollection 29 | */ 30 | updateCommands (frameState: FrameState) { 31 | const children = this.children; 32 | // for (const command of children) { 33 | // if (command.isCommand) { 34 | // command.update(frameState); 35 | // } 36 | // } 37 | } 38 | } 39 | 40 | export { RenderCollection }; 41 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/readNonPerspective.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Reads a value previously transformed with {@link czm_writeNonPerspective} 3 | * by dividing it by `w`, the value used in the perspective divide. 4 | * This function is intended to be called in a fragment shader to access a 5 | * `varying` that should not be subject to perspective interpolation. 6 | * For example, screen-space texture coordinates. The value should have been 7 | * previously written in the vertex shader with a call to 8 | * {@link czm_writeNonPerspective}. 9 | * 10 | * @name czm_readNonPerspective 11 | * @glslFunction 12 | * 13 | * @param {float|vec2|vec3|vec4} value The non-perspective value to be read. 14 | * @param {float} oneOverW One over the perspective divide value, `w`. Usually this is simply `gl_FragCoord.w`. 15 | * @returns {float|vec2|vec3|vec4} The usable value. 16 | */ 17 | float czm_readNonPerspective(float value, float oneOverW) { 18 | return value * oneOverW; 19 | } 20 | 21 | vec2 czm_readNonPerspective(vec2 value, float oneOverW) { 22 | return value * oneOverW; 23 | } 24 | 25 | vec3 czm_readNonPerspective(vec3 value, float oneOverW) { 26 | return value * oneOverW; 27 | } 28 | 29 | vec4 czm_readNonPerspective(vec4 value, float oneOverW) { 30 | return value * oneOverW; 31 | } 32 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "threejs-map", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint" 9 | }, 10 | "dependencies": { 11 | "@types/tweenjs": "^1.0.4", 12 | "core-js": "^3.6.5", 13 | "three": "^0.135.0", 14 | "vue": "^3.0.0", 15 | "vue-class-component": "^8.0.0-0" 16 | }, 17 | "devDependencies": { 18 | "@tweenjs/tween.js": "^18.6.4", 19 | "@types/three": "^0.135.0", 20 | "@typescript-eslint/eslint-plugin": "^4.18.0", 21 | "@typescript-eslint/parser": "^4.18.0", 22 | "@vue/cli-plugin-babel": "~4.5.0", 23 | "@vue/cli-plugin-eslint": "~4.5.0", 24 | "@vue/cli-plugin-typescript": "~4.5.0", 25 | "@vue/cli-service": "~4.5.0", 26 | "@vue/compiler-sfc": "^3.0.0", 27 | "@vue/eslint-config-standard": "^5.1.2", 28 | "@vue/eslint-config-typescript": "^7.0.0", 29 | "es6-tween": "^5.5.11", 30 | "eslint": "^6.7.2", 31 | "eslint-plugin-import": "^2.20.2", 32 | "eslint-plugin-node": "^11.1.0", 33 | "eslint-plugin-promise": "^4.2.1", 34 | "eslint-plugin-standard": "^4.0.0", 35 | "eslint-plugin-vue": "^7.0.0", 36 | "raw-loader": "^4.0.2", 37 | "typescript": "~4.1.5" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Renderer/WebGL/utils.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * cyrb53 hash for string from: https://stackoverflow.com/a/52171480 4 | * 5 | * Public Domain, @bryc - https://stackoverflow.com/users/815680/bryc 6 | * 7 | * It is roughly similar to the well-known MurmurHash/xxHash algorithms. It uses a combination 8 | * of multiplication and Xorshift to generate the hash, but not as thorough. As a result it's 9 | * faster than either would be in JavaScript and significantly simpler to implement. Keep in 10 | * mind this is not a secure algorithm, if privacy/security is a concern, this is not for you. 11 | * 12 | * @param {string} str 13 | * @param {number} seed, default 0 14 | * @returns number 15 | */ 16 | const hashString = (str: string, seed = 0): number => { 17 | let h1 = 0xdeadbeef ^ seed; let h2 = 0x41c6ce57 ^ seed; 18 | 19 | for (let i = 0, ch; i < str.length; i++) { 20 | ch = str.charCodeAt(i); 21 | 22 | h1 = Math.imul(h1 ^ ch, 2654435761); 23 | 24 | h2 = Math.imul(h2 ^ ch, 1597334677); 25 | } 26 | 27 | h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909); 28 | 29 | h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909); 30 | 31 | return 4294967296 * (2097151 & h2) + (h1 >>> 0); 32 | }; 33 | 34 | export {hashString }; 35 | -------------------------------------------------------------------------------- /src/Scene/EffectComposerCollection.ts: -------------------------------------------------------------------------------- 1 | import { RGBShiftMaterial } from '@/Material/Pass/RGBShiftMaterial'; 2 | import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer'; 3 | import { RenderPass } from 'three/examples/jsm/postprocessing/RenderPass'; 4 | import { ShaderPass } from 'three/examples/jsm/postprocessing/ShaderPass'; 5 | import { Scene } from './Scene'; 6 | 7 | class EffectComposerCollection { 8 | readonly scene: Scene; 9 | mainEffectComposer: EffectComposer; 10 | constructor (scene: Scene) { 11 | this.scene = scene; 12 | const renderer = scene.renderer; 13 | this.mainEffectComposer = new EffectComposer(renderer, scene.context.sceneFrameBuffer as any); 14 | 15 | const renderPass: RenderPass = new RenderPass(scene, scene.activeCamera); 16 | this.mainEffectComposer.addPass(renderPass); 17 | 18 | const effect2 = new ShaderPass(new RGBShiftMaterial()); 19 | effect2.uniforms.amount.value = 0.0015; 20 | // this.mainEffectComposer.addPass(effect2); 21 | } 22 | 23 | setSize (container: Element): void { 24 | this.mainEffectComposer.setSize(container.clientWidth, container.clientHeight); 25 | } 26 | 27 | render (): void { 28 | this.mainEffectComposer.render(); 29 | } 30 | } 31 | 32 | export { EffectComposerCollection }; 33 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/writeNonPerspective.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Transforms a value for non-perspective interpolation by multiplying 3 | * it by w, the value used in the perspective divide. This function is 4 | * intended to be called in a vertex shader to compute the value of a 5 | * `varying` that should not be subject to perspective interpolation. 6 | * For example, screen-space texture coordinates. The fragment shader 7 | * must call {@link czm_readNonPerspective} to retrieve the final 8 | * non-perspective value. 9 | * 10 | * @name czm_writeNonPerspective 11 | * @glslFunction 12 | * 13 | * @param {float|vec2|vec3|vec4} value The value to be interpolated without accounting for perspective. 14 | * @param {float} w The perspective divide value. Usually this is the computed `gl_Position.w`. 15 | * @returns {float|vec2|vec3|vec4} The transformed value, intended to be stored in a `varying` and read in the 16 | * fragment shader with {@link czm_readNonPerspective}. 17 | */ 18 | float czm_writeNonPerspective(float value, float w) { 19 | return value * w; 20 | } 21 | 22 | vec2 czm_writeNonPerspective(vec2 value, float w) { 23 | return value * w; 24 | } 25 | 26 | vec3 czm_writeNonPerspective(vec3 value, float w) { 27 | return value * w; 28 | } 29 | 30 | vec4 czm_writeNonPerspective(vec4 value, float w) { 31 | return value * w; 32 | } 33 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Structs/materialInput.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Used as input to every material's czm_getMaterial function. 3 | * 4 | * @name czm_materialInput 5 | * @glslStruct 6 | * 7 | * @property {float} s 1D texture coordinates. 8 | * @property {vec2} st 2D texture coordinates. 9 | * @property {vec3} str 3D texture coordinates. 10 | * @property {vec3} normalEC Unperturbed surface normal in eye coordinates. 11 | * @property {mat3} tangentToEyeMatrix Matrix for converting a tangent space normal to eye space. 12 | * @property {vec3} positionToEyeEC Vector from the fragment to the eye in eye coordinates. The magnitude is the distance in meters from the fragment to the eye. 13 | * @property {float} height The height of the terrain in meters above or below the WGS84 ellipsoid. Only available for globe materials. 14 | * @property {float} slope The slope of the terrain in radians. 0 is flat; pi/2 is vertical. Only available for globe materials. 15 | * @property {float} aspect The aspect of the terrain in radians. 0 is East, pi/2 is North, pi is West, 3pi/2 is South. Only available for globe materials. 16 | */ 17 | struct czm_materialInput 18 | { 19 | float s; 20 | vec2 st; 21 | vec3 str; 22 | vec3 normalEC; 23 | mat3 tangentToEyeMatrix; 24 | vec3 positionToEyeEC; 25 | float height; 26 | float slope; 27 | float aspect; 28 | }; 29 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/sphericalHarmonics.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Computes a color from the third order spherical harmonic coefficients and a normalized direction vector. 3 | *

4 | * The order of the coefficients is [L00, L1_1, L10, L11, L2_2, L2_1, L20, L21, L22]. 5 | *

6 | * 7 | * @name czm_sphericalHarmonics 8 | * @glslFunction 9 | * 10 | * @param {vec3} normal The normalized direction. 11 | * @param {vec3[9]} coefficients The third order spherical harmonic coefficients. 12 | * @returns {vec3} The color at the direction. 13 | * 14 | * @see https://graphics.stanford.edu/papers/envmap/envmap.pdf 15 | */ 16 | vec3 czm_sphericalHarmonics(vec3 normal, vec3 coefficients[9]) 17 | { 18 | vec3 L00 = coefficients[0]; 19 | vec3 L1_1 = coefficients[1]; 20 | vec3 L10 = coefficients[2]; 21 | vec3 L11 = coefficients[3]; 22 | vec3 L2_2 = coefficients[4]; 23 | vec3 L2_1 = coefficients[5]; 24 | vec3 L20 = coefficients[6]; 25 | vec3 L21 = coefficients[7]; 26 | vec3 L22 = coefficients[8]; 27 | 28 | float x = normal.x; 29 | float y = normal.y; 30 | float z = normal.z; 31 | 32 | return 33 | L00 34 | + L1_1 * y 35 | + L10 * z 36 | + L11 * x 37 | + L2_2 * (y * x) 38 | + L2_1 * (y * z) 39 | + L20 * (3.0 * z * z - 1.0) 40 | + L21 * (z * x) 41 | + L22 * (x * x - y * y); 42 | } 43 | -------------------------------------------------------------------------------- /src/Core/arrayFill.ts: -------------------------------------------------------------------------------- 1 | import { defaultValue } from './defaultValue'; 2 | 3 | /** 4 | * Fill an array or a portion of an array with a given value. 5 | * 6 | * @param {Array} array The array to fill. 7 | * @param {*} value The value to fill the array with. 8 | * @param {Number} [start=0] The index to start filling at. 9 | * @param {Number} [end=array.length] The index to end stop at. 10 | * 11 | * @returns {Array} The resulting array. 12 | * @private 13 | */ 14 | function arrayFill (array: any[], value: any, start = 0, end?: number): any[] { 15 | if (typeof array.fill === 'function') { 16 | return array.fill(value, start, end); 17 | } 18 | 19 | const length = array.length >>> 0; 20 | const relativeStart = defaultValue(start, 0); 21 | // If negative, find wrap around position 22 | let k = 23 | relativeStart < 0 24 | ? Math.max(length + relativeStart, 0) 25 | : Math.min(relativeStart, length); 26 | const relativeEnd = defaultValue(end, length) as number; 27 | // If negative, find wrap around position 28 | const last = 29 | relativeEnd < 0 30 | ? Math.max(length + relativeEnd, 0) 31 | : Math.min(relativeEnd, length); 32 | 33 | // Fill array accordingly 34 | while (k < last) { 35 | array[k] = value; 36 | k++; 37 | } 38 | return array; 39 | } 40 | export default arrayFill; 41 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/getSpecular.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Calculates the specular intensity of reflected light. 3 | * 4 | * @name czm_getSpecular 5 | * @glslFunction 6 | * 7 | * @param {vec3} lightDirectionEC Unit vector pointing to the light source in eye coordinates. 8 | * @param {vec3} toEyeEC Unit vector pointing to the eye position in eye coordinates. 9 | * @param {vec3} normalEC The surface normal in eye coordinates. 10 | * @param {float} shininess The sharpness of the specular reflection. Higher values create a smaller, more focused specular highlight. 11 | * 12 | * @returns {float} The intensity of the specular highlight. 13 | * 14 | * @see czm_phong 15 | * 16 | * @example 17 | * float diffuseIntensity = czm_getLambertDiffuse(lightDirectionEC, normalEC); 18 | * float specularIntensity = czm_getSpecular(lightDirectionEC, toEyeEC, normalEC, 200); 19 | * vec3 color = (diffuseColor * diffuseIntensity) + (specularColor * specularIntensity); 20 | */ 21 | float czm_getSpecular(vec3 lightDirectionEC, vec3 toEyeEC, vec3 normalEC, float shininess) 22 | { 23 | vec3 toReflectedLight = reflect(-lightDirectionEC, normalEC); 24 | float specular = max(dot(toReflectedLight, toEyeEC), 0.0); 25 | 26 | // pow has undefined behavior if both parameters <= 0. 27 | // Prevent this by making sure shininess is at least czm_epsilon2. 28 | return pow(specular, max(shininess, czm_epsilon2)); 29 | } 30 | -------------------------------------------------------------------------------- /src/Core/parseResponseHeaders.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Parses the result of XMLHttpRequest's getAllResponseHeaders() method into 3 | * a dictionary. 4 | * 5 | * @function parseResponseHeaders 6 | * 7 | * @param {String} headerString The header string returned by getAllResponseHeaders(). The format is 8 | * described here: http://www.w3.org/TR/XMLHttpRequest/#the-getallresponseheaders()-method 9 | * @returns {Object} A dictionary of key/value pairs, where each key is the name of a header and the corresponding value 10 | * is that header's value. 11 | * 12 | * @private 13 | */ 14 | function parseResponseHeaders (headerString: string): any { 15 | const headers = {}; 16 | 17 | if (!headerString) { 18 | return headers; 19 | } 20 | 21 | const headerPairs = headerString.split('\u000d\u000a'); 22 | 23 | for (let i = 0; i < headerPairs.length; ++i) { 24 | const headerPair = headerPairs[i]; 25 | // Can't use split() here because it does the wrong thing 26 | // if the header value has the string ": " in it. 27 | const index = headerPair.indexOf('\u003a\u0020'); 28 | if (index > 0) { 29 | const key = headerPair.substring(0, index); 30 | const val = headerPair.substring(index + 2); 31 | headers[key] = val; 32 | } 33 | } 34 | 35 | return headers; 36 | } 37 | export { parseResponseHeaders }; 38 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/eyeToWindowCoordinates.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Transforms a position from eye to window coordinates. The transformation 3 | * from eye to clip coordinates is done using {@link czm_projection}. 4 | * The transform from normalized device coordinates to window coordinates is 5 | * done using {@link czm_viewportTransformation}, which assumes a depth range 6 | * of near = 0 and far = 1. 7 | *

8 | * This transform is useful when there is a need to manipulate window coordinates 9 | * in a vertex shader as done by {@link BillboardCollection}. 10 | * 11 | * @name czm_eyeToWindowCoordinates 12 | * @glslFunction 13 | * 14 | * @param {vec4} position The position in eye coordinates to transform. 15 | * 16 | * @returns {vec4} The transformed position in window coordinates. 17 | * 18 | * @see czm_modelToWindowCoordinates 19 | * @see czm_projection 20 | * @see czm_viewportTransformation 21 | * @see BillboardCollection 22 | * 23 | * @example 24 | * vec4 positionWC = czm_eyeToWindowCoordinates(positionEC); 25 | */ 26 | vec4 czm_eyeToWindowCoordinates(vec4 positionEC) 27 | { 28 | vec4 q = czm_projection * positionEC; // clip coordinates 29 | q.xyz /= q.w; // normalized device coordinates 30 | q.xyz = (czm_viewportTransformation * vec4(q.xyz, 1.0)).xyz; // window coordinates 31 | return q; 32 | } 33 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/fog.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Gets the color with fog at a distance from the camera. 3 | * 4 | * @name czm_fog 5 | * @glslFunction 6 | * 7 | * @param {float} distanceToCamera The distance to the camera in meters. 8 | * @param {vec3} color The original color. 9 | * @param {vec3} fogColor The color of the fog. 10 | * 11 | * @returns {vec3} The color adjusted for fog at the distance from the camera. 12 | */ 13 | vec3 czm_fog(float distanceToCamera, vec3 color, vec3 fogColor) 14 | { 15 | float scalar = distanceToCamera * czm_fogDensity; 16 | float fog = 1.0 - exp(-(scalar * scalar)); 17 | return mix(color, fogColor, fog); 18 | } 19 | 20 | /** 21 | * Gets the color with fog at a distance from the camera. 22 | * 23 | * @name czm_fog 24 | * @glslFunction 25 | * 26 | * @param {float} distanceToCamera The distance to the camera in meters. 27 | * @param {vec3} color The original color. 28 | * @param {vec3} fogColor The color of the fog. 29 | * @param {float} fogModifierConstant A constant to modify the appearance of fog. 30 | * 31 | * @returns {vec3} The color adjusted for fog at the distance from the camera. 32 | */ 33 | vec3 czm_fog(float distanceToCamera, vec3 color, vec3 fogColor, float fogModifierConstant) 34 | { 35 | float scalar = distanceToCamera * czm_fogDensity; 36 | float fog = 1.0 - exp(-((fogModifierConstant * scalar + fogModifierConstant) * (scalar * (1.0 + fogModifierConstant)))); 37 | return mix(color, fogColor, fog); 38 | } 39 | -------------------------------------------------------------------------------- /src/Shader/RGBShiftShader.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * RGB Shift Shader 3 | * Shifts red and blue channels from center in opposite directions 4 | * Ported from http://kriss.cx/tom/2009/05/rgb-shift/ 5 | * by Tom Butterworth / http://kriss.cx/tom/ 6 | * 7 | * amount: shift distance (1 is width of input) 8 | * angle: shift angle in radians 9 | */ 10 | 11 | const RGBShiftShader = { 12 | 13 | uniforms: { 14 | 15 | colorTexture: { value: null }, 16 | amount: { value: 0.005 }, 17 | angle: { value: 0.0 } 18 | 19 | }, 20 | 21 | vertexShader: /* glsl */` 22 | 23 | varying vec2 vUv; 24 | 25 | void main() { 26 | 27 | vUv = uv; 28 | gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); 29 | 30 | }`, 31 | 32 | fragmentShader: /* glsl */` 33 | 34 | uniform sampler2D colorTexture; 35 | uniform float amount; 36 | uniform float angle; 37 | 38 | varying vec2 vUv; 39 | 40 | void main() { 41 | 42 | // vec2 offset = amount * vec2( cos(angle), sin(angle)); 43 | // vec4 cr = texture2D(colorTexture, vUv + offset); 44 | // vec4 cga = texture2D(colorTexture, vUv); 45 | // vec4 cb = texture2D(colorTexture, vUv - offset); 46 | // gl_FragColor = vec4(cr.r, cga.g, cb.b, cga.a); 47 | 48 | 49 | gl_FragColor = texture2D(colorTexture, vUv); 50 | }` 51 | 52 | }; 53 | 54 | export { RGBShiftShader }; 55 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/transpose.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Returns the transpose of the matrix. The input matrix can be 3 | * a mat2, mat3, or mat4. 4 | * 5 | * @name czm_transpose 6 | * @glslFunction 7 | * 8 | * @param {} matrix The matrix to transpose. 9 | * 10 | * @returns {} The transposed matrix. 11 | * 12 | * @example 13 | * // GLSL declarations 14 | * mat2 czm_transpose(mat2 matrix); 15 | * mat3 czm_transpose(mat3 matrix); 16 | * mat4 czm_transpose(mat4 matrix); 17 | * 18 | * // Transpose a 3x3 rotation matrix to find its inverse. 19 | * mat3 eastNorthUpToEye = czm_eastNorthUpToEyeCoordinates( 20 | * positionMC, normalEC); 21 | * mat3 eyeToEastNorthUp = czm_transpose(eastNorthUpToEye); 22 | */ 23 | mat2 czm_transpose(mat2 matrix) 24 | { 25 | return mat2( 26 | matrix[0][0], matrix[1][0], 27 | matrix[0][1], matrix[1][1]); 28 | } 29 | 30 | mat3 czm_transpose(mat3 matrix) 31 | { 32 | return mat3( 33 | matrix[0][0], matrix[1][0], matrix[2][0], 34 | matrix[0][1], matrix[1][1], matrix[2][1], 35 | matrix[0][2], matrix[1][2], matrix[2][2]); 36 | } 37 | 38 | mat4 czm_transpose(mat4 matrix) 39 | { 40 | return mat4( 41 | matrix[0][0], matrix[1][0], matrix[2][0], matrix[3][0], 42 | matrix[0][1], matrix[1][1], matrix[2][1], matrix[3][1], 43 | matrix[0][2], matrix[1][2], matrix[2][2], matrix[3][2], 44 | matrix[0][3], matrix[1][3], matrix[2][3], matrix[3][3]); 45 | } 46 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/pbrMetallicRoughnessMaterial.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Compute parameters for physically based rendering using the 3 | * metallic/roughness workflow. All inputs are linear; sRGB texture values must 4 | * be decoded beforehand 5 | * 6 | * @name czm_pbrMetallicRoughnessMaterial 7 | * @glslFunction 8 | * 9 | * @param {vec3} baseColor For dielectrics, this is the base color. For metals, this is the f0 value (reflectance at normal incidence) 10 | * @param {float} metallic 0.0 indicates dielectric. 1.0 indicates metal. Values in between are allowed (e.g. to model rust or dirt); 11 | * @param {float} roughness A value between 0.0 and 1.0 12 | * @return {czm_pbrParameters} parameters to pass into {@link czm_pbrLighting} 13 | */ 14 | czm_pbrParameters czm_pbrMetallicRoughnessMaterial( 15 | vec3 baseColor, 16 | float metallic, 17 | float roughness 18 | ) { 19 | czm_pbrParameters results; 20 | 21 | // roughness is authored as perceptual roughness 22 | // square it to get material roughness 23 | roughness = clamp(roughness, 0.0, 1.0); 24 | results.roughness = roughness * roughness; 25 | 26 | // dielectrics us f0 = 0.04, metals use albedo as f0 27 | metallic = clamp(metallic, 0.0, 1.0); 28 | const vec3 REFLECTANCE_DIELECTRIC = vec3(0.04); 29 | vec3 f0 = mix(REFLECTANCE_DIELECTRIC, baseColor, metallic); 30 | results.f0 = f0; 31 | 32 | // diffuse only applies to dielectrics. 33 | results.diffuseColor = baseColor * (1.0 - f0) * (1.0 - metallic); 34 | 35 | return results; 36 | } 37 | -------------------------------------------------------------------------------- /src/Core/NearFarScalar.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Represents a scalar value's lower and upper bound at a near distance and far distance in eye space. 3 | * @alias NearFarScalar 4 | * @constructor 5 | * 6 | * @param {Number} [near=0.0] The lower bound of the camera range. 7 | * @param {Number} [nearValue=0.0] The value at the lower bound of the camera range. 8 | * @param {Number} [far=1.0] The upper bound of the camera range. 9 | * @param {Number} [farValue=0.0] The value at the upper bound of the camera range. 10 | * 11 | * @see Packable 12 | */ 13 | 14 | class NearFarScalar { 15 | near: number; 16 | nearValue: number; 17 | far: number; 18 | farValue: number; 19 | constructor (near = 0.0, nearValue = 0.0, far = 1.0, farValue = 0.0) { 20 | /** 21 | * The lower bound of the camera range. 22 | * @type {Number} 23 | * @default 0.0 24 | */ 25 | this.near = near; 26 | /** 27 | * The value at the lower bound of the camera range. 28 | * @type {Number} 29 | * @default 0.0 30 | */ 31 | this.nearValue = nearValue; 32 | /** 33 | * The upper bound of the camera range. 34 | * @type {Number} 35 | * @default 1.0 36 | */ 37 | this.far = far; 38 | /** 39 | * The value at the upper bound of the camera range. 40 | * @type {Number} 41 | * @default 0.0 42 | */ 43 | this.farValue = farValue; 44 | } 45 | } 46 | 47 | export { NearFarScalar }; 48 | -------------------------------------------------------------------------------- /src/Scene/CameraCopy.ts: -------------------------------------------------------------------------------- 1 | import { Cartesian3 } from '@/Core/Cartesian3'; 2 | import { Frustum, Vector3 } from 'three'; 3 | import { OrthographicFrustumCameraParameters } from './OrthographicFrustumCamera'; 4 | import { PerspectiveFrustumCamera, PerspectiveFrustumCameraParameters } from './PerspectiveFrustumCamera'; 5 | import { Scene } from './Scene'; 6 | 7 | class Camera { 8 | readonly activeCamera: PerspectiveFrustumCamera; 9 | constructor (scene: Scene, options: PerspectiveFrustumCameraParameters | OrthographicFrustumCameraParameters) { 10 | // 默认使用透视相机 11 | this.activeCamera = new PerspectiveFrustumCamera(scene, options); 12 | 13 | // this.cullingVolume = new CullingVolume(); 14 | } 15 | 16 | get frustum (): Frustum { 17 | return this.activeCamera.frustum; 18 | } 19 | 20 | get position (): Vector3 { 21 | return this.activeCamera.position; 22 | } 23 | 24 | get direction (): Cartesian3 { 25 | return this.activeCamera.directionWC; 26 | } 27 | 28 | get positionWC ():Cartesian3 { 29 | return this.activeCamera.positionWC; 30 | } 31 | 32 | // computeCullingVolume () { 33 | 34 | // } 35 | 36 | _adjustOrthographicFrustum (zooming: number): void { 37 | // if (!(this.frustum instanceof OrthographicFrustum)) { 38 | 39 | // } 40 | 41 | } 42 | 43 | resize (container: Element): void { 44 | this.activeCamera.resize(container); 45 | } 46 | 47 | update (mode: number): void { 48 | return undefined; 49 | } 50 | } 51 | export { Camera }; 52 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/getWaterNoise.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * @private 3 | */ 4 | vec4 czm_getWaterNoise(sampler2D normalMap, vec2 uv, float time, float angleInRadians) 5 | { 6 | float cosAngle = cos(angleInRadians); 7 | float sinAngle = sin(angleInRadians); 8 | 9 | // time dependent sampling directions 10 | vec2 s0 = vec2(1.0/17.0, 0.0); 11 | vec2 s1 = vec2(-1.0/29.0, 0.0); 12 | vec2 s2 = vec2(1.0/101.0, 1.0/59.0); 13 | vec2 s3 = vec2(-1.0/109.0, -1.0/57.0); 14 | 15 | // rotate sampling direction by specified angle 16 | s0 = vec2((cosAngle * s0.x) - (sinAngle * s0.y), (sinAngle * s0.x) + (cosAngle * s0.y)); 17 | s1 = vec2((cosAngle * s1.x) - (sinAngle * s1.y), (sinAngle * s1.x) + (cosAngle * s1.y)); 18 | s2 = vec2((cosAngle * s2.x) - (sinAngle * s2.y), (sinAngle * s2.x) + (cosAngle * s2.y)); 19 | s3 = vec2((cosAngle * s3.x) - (sinAngle * s3.y), (sinAngle * s3.x) + (cosAngle * s3.y)); 20 | 21 | vec2 uv0 = (uv/103.0) + (time * s0); 22 | vec2 uv1 = uv/107.0 + (time * s1) + vec2(0.23); 23 | vec2 uv2 = uv/vec2(897.0, 983.0) + (time * s2) + vec2(0.51); 24 | vec2 uv3 = uv/vec2(991.0, 877.0) + (time * s3) + vec2(0.71); 25 | 26 | uv0 = fract(uv0); 27 | uv1 = fract(uv1); 28 | uv2 = fract(uv2); 29 | uv3 = fract(uv3); 30 | vec4 noise = (texture2D(normalMap, uv0)) + 31 | (texture2D(normalMap, uv1)) + 32 | (texture2D(normalMap, uv2)) + 33 | (texture2D(normalMap, uv3)); 34 | 35 | // average and scale to between -1 and 1 36 | return ((noise / 4.0) - 0.5) * 2.0; 37 | } 38 | -------------------------------------------------------------------------------- /src/Scene/PrimitiveCollection.ts: -------------------------------------------------------------------------------- 1 | import { defined } from '@/Core/defined'; 2 | import { Object3DCollection } from '@/Core/Object3DCollection'; 3 | import { FrameState } from './FrameState'; 4 | 5 | class PrimitiveCollection extends Object3DCollection { 6 | _primitives: any[]; 7 | constructor () { 8 | super(); 9 | this._primitives = []; 10 | } 11 | 12 | update (frameState: FrameState): void { 13 | if (!this.visible) { 14 | return; 15 | } 16 | 17 | const primitives = this._primitives; 18 | // Using primitives.length in the loop is a temporary workaround 19 | // to allow quadtree updates to add and remove primitives in 20 | // update(). This will be changed to manage added and removed lists. 21 | for (let i = 0; i < primitives.length; ++i) { 22 | primitives[i].update(frameState); 23 | } 24 | } 25 | 26 | /** 27 | * @private 28 | */ 29 | prePassesUpdate (frameState: FrameState): void { 30 | const primitives = this._primitives; 31 | // Using primitives.length in the loop is a temporary workaround 32 | // to allow quadtree updates to add and remove primitives in 33 | // update(). This will be changed to manage added and removed lists. 34 | for (let i = 0; i < primitives.length; ++i) { 35 | const primitive = primitives[i]; 36 | if (defined(primitive.prePassesUpdate)) { 37 | primitive.prePassesUpdate(frameState); 38 | } 39 | } 40 | } 41 | } 42 | export { PrimitiveCollection }; 43 | -------------------------------------------------------------------------------- /src/Renderer/ShaderPass.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ShaderMaterial, 3 | UniformsUtils, 4 | WebGLRenderer 5 | } from 'three'; 6 | import { Pass, FullScreenQuad } from 'three/examples/jsm/postprocessing/Pass'; 7 | 8 | class ShaderPass extends Pass { 9 | textureID: string; 10 | fsQuad: FullScreenQuad; 11 | uniforms: { [name: string]: any }; 12 | material: ShaderMaterial 13 | constructor (shader: ShaderMaterial, textureID?: string) { 14 | super(); 15 | 16 | this.textureID = (textureID !== undefined) ? textureID : 'colorTexture'; 17 | 18 | this.uniforms = shader.uniforms; 19 | 20 | this.material = shader; 21 | 22 | this.fsQuad = new FullScreenQuad(this.material); 23 | } 24 | 25 | render (renderer: WebGLRenderer, writeBuffer: any, readBuffer: any /*, deltaTime, maskActive */): void { 26 | if (this.uniforms[this.textureID]) { 27 | this.uniforms[this.textureID].value = readBuffer.texture[0]; 28 | } 29 | 30 | this.fsQuad.material = this.material; 31 | 32 | if (this.renderToScreen) { 33 | renderer.setRenderTarget(null); 34 | this.fsQuad.render(renderer); 35 | } else { 36 | renderer.setRenderTarget(writeBuffer); 37 | // TODO: Avoid using autoClear properties, see https://github.com/mrdoob/three.js/pull/15571#issuecomment-465669600 38 | if (this.clear) renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil); 39 | this.fsQuad.render(renderer); 40 | } 41 | } 42 | } 43 | 44 | export { ShaderPass }; 45 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/equalsEpsilon.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Compares left and right componentwise. Returns true 3 | * if they are within epsilon and false otherwise. The inputs 4 | * left and right can be floats, vec2s, 5 | * vec3s, or vec4s. 6 | * 7 | * @name czm_equalsEpsilon 8 | * @glslFunction 9 | * 10 | * @param {} left The first vector. 11 | * @param {} right The second vector. 12 | * @param {float} epsilon The epsilon to use for equality testing. 13 | * @returns {bool} true if the components are within epsilon and false otherwise. 14 | * 15 | * @example 16 | * // GLSL declarations 17 | * bool czm_equalsEpsilon(float left, float right, float epsilon); 18 | * bool czm_equalsEpsilon(vec2 left, vec2 right, float epsilon); 19 | * bool czm_equalsEpsilon(vec3 left, vec3 right, float epsilon); 20 | * bool czm_equalsEpsilon(vec4 left, vec4 right, float epsilon); 21 | */ 22 | bool czm_equalsEpsilon(vec4 left, vec4 right, float epsilon) { 23 | return all(lessThanEqual(abs(left - right), vec4(epsilon))); 24 | } 25 | 26 | bool czm_equalsEpsilon(vec3 left, vec3 right, float epsilon) { 27 | return all(lessThanEqual(abs(left - right), vec3(epsilon))); 28 | } 29 | 30 | bool czm_equalsEpsilon(vec2 left, vec2 right, float epsilon) { 31 | return all(lessThanEqual(abs(left - right), vec2(epsilon))); 32 | } 33 | 34 | bool czm_equalsEpsilon(float left, float right, float epsilon) { 35 | return (abs(left - right) <= epsilon); 36 | } 37 | -------------------------------------------------------------------------------- /src/Shader/envmap_fragment.ts: -------------------------------------------------------------------------------- 1 | const envmap_fragment = ` 2 | #ifdef USE_ENVMAP 3 | #ifdef ENV_WORLDPOS 4 | vec3 cameraToFrag; 5 | if ( isOrthographic ) { 6 | cameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) ); 7 | } else { 8 | cameraToFrag = normalize( vWorldPosition - cameraPosition ); 9 | } 10 | vec3 worldNormal = inverseTransformDirection( normal, viewMatrix ); 11 | 12 | #ifdef ENVMAP_MODE_REFLECTION 13 | vec3 reflectVec = reflect( cameraToFrag, worldNormal ); 14 | #else 15 | vec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio ); 16 | #endif 17 | #else 18 | vec3 reflectVec = vReflect; 19 | #endif 20 | #ifdef ENVMAP_TYPE_CUBE 21 | vec4 envColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.zy ) ); 22 | envColor = envMapTexelToLinear( envColor ); 23 | #elif defined( ENVMAP_TYPE_CUBE_UV ) 24 | vec4 envColor = textureCubeUV( envMap, reflectVec, 0.0 ); 25 | #else 26 | vec4 envColor = vec4( 0.0 ); 27 | #endif 28 | #ifdef ENVMAP_BLENDING_MULTIPLY 29 | outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity ); 30 | #elif defined( ENVMAP_BLENDING_MIX ) 31 | outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity ); 32 | #elif defined( ENVMAP_BLENDING_ADD ) 33 | outgoingLight += envColor.xyz * specularStrength * reflectivity; 34 | #endif 35 | #endif 36 | `; 37 | export { envmap_fragment }; 38 | -------------------------------------------------------------------------------- /src/Core/getAbsoluteUri.ts: -------------------------------------------------------------------------------- 1 | import { defaultValue } from './defaultValue'; 2 | import { defined } from './defined'; 3 | import { DeveloperError } from './DeveloperError'; 4 | 5 | import { URI as Uri } from './../ThirdParty/Uri'; 6 | 7 | /** 8 | * Given a relative Uri and a base Uri, returns the absolute Uri of the relative Uri. 9 | * @function 10 | * 11 | * @param {String} relative The relative Uri. 12 | * @param {String} [base] The base Uri. 13 | * @returns {String} The absolute Uri of the given relative Uri. 14 | * 15 | * @example 16 | * //absolute Uri will be "https://test.com/awesome.png"; 17 | * var absoluteUri = Cesium.getAbsoluteUri('awesome.png', 'https://test.com'); 18 | */ 19 | function getAbsoluteUri (relative:string, base?: string): string { 20 | let documentObject; 21 | if (typeof document !== 'undefined') { 22 | documentObject = document; 23 | } 24 | 25 | return getAbsoluteUri._implementation(relative, base, documentObject); 26 | } 27 | 28 | getAbsoluteUri._implementation = function (relative: string, base?: string, documentObject?:any) { 29 | // >>includeStart('debug', pragmas.debug); 30 | if (!defined(relative)) { 31 | throw new DeveloperError('relative uri is required.'); 32 | } 33 | // >>includeEnd('debug'); 34 | 35 | if (!defined(base)) { 36 | if (typeof documentObject === 'undefined') { 37 | return relative; 38 | } 39 | base = defaultValue(documentObject.baseURI, documentObject.location.href); 40 | } 41 | 42 | const baseUri = new Uri(base); 43 | const relativeUri = new Uri(relative); 44 | return relativeUri.resolve(baseUri).toString(); 45 | }; 46 | 47 | export { getAbsoluteUri }; 48 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/translateRelativeToEye.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Translates a position (or any vec3) that was encoded with {@link EncodedCartesian3}, 3 | * and then provided to the shader as separate high and low bits to 4 | * be relative to the eye. As shown in the example, the position can then be transformed in eye 5 | * or clip coordinates using {@link czm_modelViewRelativeToEye} or {@link czm_modelViewProjectionRelativeToEye}, 6 | * respectively. 7 | *

8 | * This technique, called GPU RTE, eliminates jittering artifacts when using large coordinates as 9 | * described in {@link http://help.agi.com/AGIComponents/html/BlogPrecisionsPrecisions.htm|Precisions, Precisions}. 10 | *

11 | * 12 | * @name czm_translateRelativeToEye 13 | * @glslFunction 14 | * 15 | * @param {vec3} high The position's high bits. 16 | * @param {vec3} low The position's low bits. 17 | * @returns {vec3} The position translated to be relative to the camera's position. 18 | * 19 | * @example 20 | * attribute vec3 positionHigh; 21 | * attribute vec3 positionLow; 22 | * 23 | * void main() 24 | * { 25 | * vec4 p = czm_translateRelativeToEye(positionHigh, positionLow); 26 | * gl_Position = czm_modelViewProjectionRelativeToEye * p; 27 | * } 28 | * 29 | * @see czm_modelViewRelativeToEye 30 | * @see czm_modelViewProjectionRelativeToEye 31 | * @see czm_computePosition 32 | * @see EncodedCartesian3 33 | */ 34 | vec4 czm_translateRelativeToEye(vec3 high, vec3 low) 35 | { 36 | vec3 highDifference = high - czm_encodedCameraPositionMCHigh; 37 | vec3 lowDifference = low - czm_encodedCameraPositionMCLow; 38 | 39 | return vec4(highDifference + lowDifference, 1.0); 40 | } 41 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/modelToWindowCoordinates.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Transforms a position from model to window coordinates. The transformation 3 | * from model to clip coordinates is done using {@link czm_modelViewProjection}. 4 | * The transform from normalized device coordinates to window coordinates is 5 | * done using {@link czm_viewportTransformation}, which assumes a depth range 6 | * of near = 0 and far = 1. 7 | *

8 | * This transform is useful when there is a need to manipulate window coordinates 9 | * in a vertex shader as done by {@link BillboardCollection}. 10 | *

11 | * This function should not be confused with {@link czm_viewportOrthographic}, 12 | * which is an orthographic projection matrix that transforms from window 13 | * coordinates to clip coordinates. 14 | * 15 | * @name czm_modelToWindowCoordinates 16 | * @glslFunction 17 | * 18 | * @param {vec4} position The position in model coordinates to transform. 19 | * 20 | * @returns {vec4} The transformed position in window coordinates. 21 | * 22 | * @see czm_eyeToWindowCoordinates 23 | * @see czm_modelViewProjection 24 | * @see czm_viewportTransformation 25 | * @see czm_viewportOrthographic 26 | * @see BillboardCollection 27 | * 28 | * @example 29 | * vec4 positionWC = czm_modelToWindowCoordinates(positionMC); 30 | */ 31 | vec4 czm_modelToWindowCoordinates(vec4 position) 32 | { 33 | vec4 q = czm_modelViewProjection * position; // clip coordinates 34 | q.xyz /= q.w; // normalized device coordinates 35 | q.xyz = (czm_viewportTransformation * vec4(q.xyz, 1.0)).xyz; // window coordinates 36 | return q; 37 | } 38 | -------------------------------------------------------------------------------- /src/Core/TerrainExaggeration.ts: -------------------------------------------------------------------------------- 1 | import { Cartesian3 } from './Cartesian3'; 2 | import { Cartographic } from './Cartographic'; 3 | import { Ellipsoid } from './Ellipsoid'; 4 | 5 | const scratchCartographic = new Cartographic(); 6 | 7 | /** 8 | * @private 9 | */ 10 | const TerrainExaggeration = { 11 | /** 12 | * Scales a position by exaggeration. 13 | */ 14 | getPosition: function ( 15 | position:Cartesian3, 16 | ellipsoid:Ellipsoid, 17 | terrainExaggeration: number, 18 | terrainExaggerationRelativeHeight: number, 19 | result:Cartesian3 20 | ) { 21 | const cartographic = ellipsoid.cartesianToCartographic( 22 | position, 23 | scratchCartographic 24 | ) as Cartographic; 25 | const newHeight = TerrainExaggeration.getHeight( 26 | cartographic.height, 27 | terrainExaggeration, 28 | terrainExaggerationRelativeHeight 29 | ); 30 | return Cartesian3.fromRadians( 31 | cartographic.longitude, 32 | cartographic.latitude, 33 | newHeight, 34 | ellipsoid, 35 | result 36 | ); 37 | }, 38 | /** 39 | * Scales a height relative to an offset. 40 | * 41 | * @param {Number} height The height. 42 | * @param {Number} scale A scalar used to exaggerate the terrain. If the value is 1.0 there will be no effect. 43 | * @param {Number} relativeHeight The height relative to which terrain is exaggerated. If the value is 0.0 terrain will be exaggerated relative to the ellipsoid surface. 44 | */ 45 | getHeight: (height: number, scale: number, relativeHeight: number) => { 46 | return (height - relativeHeight) * scale + relativeHeight; 47 | } 48 | }; 49 | 50 | export { TerrainExaggeration }; 51 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/antialias.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Procedural anti-aliasing by blurring two colors that meet at a sharp edge. 3 | * 4 | * @name czm_antialias 5 | * @glslFunction 6 | * 7 | * @param {vec4} color1 The color on one side of the edge. 8 | * @param {vec4} color2 The color on the other side of the edge. 9 | * @param {vec4} currentcolor The current color, either color1 or color2. 10 | * @param {float} dist The distance to the edge in texture coordinates. 11 | * @param {float} [fuzzFactor=0.1] Controls the blurriness between the two colors. 12 | * @returns {vec4} The anti-aliased color. 13 | * 14 | * @example 15 | * // GLSL declarations 16 | * vec4 czm_antialias(vec4 color1, vec4 color2, vec4 currentColor, float dist, float fuzzFactor); 17 | * vec4 czm_antialias(vec4 color1, vec4 color2, vec4 currentColor, float dist); 18 | * 19 | * // get the color for a material that has a sharp edge at the line y = 0.5 in texture space 20 | * float dist = abs(textureCoordinates.t - 0.5); 21 | * vec4 currentColor = mix(bottomColor, topColor, step(0.5, textureCoordinates.t)); 22 | * vec4 color = czm_antialias(bottomColor, topColor, currentColor, dist, 0.1); 23 | */ 24 | vec4 czm_antialias(vec4 color1, vec4 color2, vec4 currentColor, float dist, float fuzzFactor) 25 | { 26 | float val1 = clamp(dist / fuzzFactor, 0.0, 1.0); 27 | float val2 = clamp((dist - 0.5) / fuzzFactor, 0.0, 1.0); 28 | val1 = val1 * (1.0 - val2); 29 | val1 = val1 * val1 * (3.0 - (2.0 * val1)); 30 | val1 = pow(val1, 0.5); //makes the transition nicer 31 | 32 | vec4 midColor = (color1 + color2) * 0.5; 33 | return mix(midColor, currentColor, val1); 34 | } 35 | 36 | vec4 czm_antialias(vec4 color1, vec4 color2, vec4 currentColor, float dist) 37 | { 38 | return czm_antialias(color1, color2, currentColor, dist, 0.1); 39 | } 40 | -------------------------------------------------------------------------------- /src/Scene/ShadowMode.ts: -------------------------------------------------------------------------------- 1 | export enum ShadowModeEnum { 2 | DISABLED = 0, 3 | 4 | ENABLED = 1, 5 | 6 | CAST_ONLY = 2, 7 | 8 | RECEIVE_ONLY = 3, 9 | } 10 | 11 | const ShadowMode = { 12 | /** 13 | * The object does not cast or receive shadows. 14 | * 15 | * @type {Number} 16 | * @constant 17 | */ 18 | DISABLED: 0, 19 | 20 | /** 21 | * The object casts and receives shadows. 22 | * 23 | * @type {Number} 24 | * @constant 25 | */ 26 | ENABLED: 1, 27 | 28 | /** 29 | * The object casts shadows only. 30 | * 31 | * @type {Number} 32 | * @constant 33 | */ 34 | CAST_ONLY: 2, 35 | 36 | /** 37 | * The object receives shadows only. 38 | * 39 | * @type {Number} 40 | * @constant 41 | */ 42 | RECEIVE_ONLY: 3, 43 | 44 | NUMBER_OF_SHADOW_MODES: 4, 45 | 46 | /** 47 | * @private 48 | */ 49 | castShadows (shadowMode: ShadowModeEnum):boolean { 50 | return ( 51 | shadowMode === ShadowMode.ENABLED || shadowMode === ShadowMode.CAST_ONLY 52 | ); 53 | }, 54 | 55 | /** 56 | * @private 57 | */ 58 | receiveShadows (shadowMode: ShadowModeEnum): boolean { 59 | return ( 60 | shadowMode === ShadowMode.ENABLED || shadowMode === ShadowMode.RECEIVE_ONLY 61 | ); 62 | }, 63 | 64 | /** 65 | * @private 66 | */ 67 | fromCastReceive (castShadows: boolean, receiveShadows: boolean): ShadowModeEnum { 68 | if (castShadows && receiveShadows) { 69 | return ShadowMode.ENABLED; 70 | } else if (castShadows) { 71 | return ShadowMode.CAST_ONLY; 72 | } else if (receiveShadows) { 73 | return ShadowMode.RECEIVE_ONLY; 74 | } 75 | return ShadowMode.DISABLED; 76 | } 77 | }; 78 | 79 | export { ShadowMode }; 80 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/eastNorthUpToEyeCoordinates.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Computes a 3x3 rotation matrix that transforms vectors from an ellipsoid's east-north-up coordinate system 3 | * to eye coordinates. In east-north-up coordinates, x points east, y points north, and z points along the 4 | * surface normal. East-north-up can be used as an ellipsoid's tangent space for operations such as bump mapping. 5 | *

6 | * The ellipsoid is assumed to be centered at the model coordinate's origin. 7 | * 8 | * @name czm_eastNorthUpToEyeCoordinates 9 | * @glslFunction 10 | * 11 | * @param {vec3} positionMC The position on the ellipsoid in model coordinates. 12 | * @param {vec3} normalEC The normalized ellipsoid surface normal, at positionMC, in eye coordinates. 13 | * 14 | * @returns {mat3} A 3x3 rotation matrix that transforms vectors from the east-north-up coordinate system to eye coordinates. 15 | * 16 | * @example 17 | * // Transform a vector defined in the east-north-up coordinate 18 | * // system, (0, 0, 1) which is the surface normal, to eye 19 | * // coordinates. 20 | * mat3 m = czm_eastNorthUpToEyeCoordinates(positionMC, normalEC); 21 | * vec3 normalEC = m * vec3(0.0, 0.0, 1.0); 22 | */ 23 | mat3 czm_eastNorthUpToEyeCoordinates(vec3 positionMC, vec3 normalEC) 24 | { 25 | vec3 tangentMC = normalize(vec3(-positionMC.y, positionMC.x, 0.0)); // normalized surface tangent in model coordinates 26 | vec3 tangentEC = normalize(czm_normal3D * tangentMC); // normalized surface tangent in eye coordiantes 27 | vec3 bitangentEC = normalize(cross(normalEC, tangentEC)); // normalized surface bitangent in eye coordinates 28 | 29 | return mat3( 30 | tangentEC.x, tangentEC.y, tangentEC.z, 31 | bitangentEC.x, bitangentEC.y, bitangentEC.z, 32 | normalEC.x, normalEC.y, normalEC.z); 33 | } 34 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/depthClamp.glsl: -------------------------------------------------------------------------------- 1 | // emulated noperspective 2 | #if defined(GL_EXT_frag_depth) && !defined(LOG_DEPTH) 3 | varying float v_WindowZ; 4 | #endif 5 | 6 | /** 7 | * Emulates GL_DEPTH_CLAMP, which is not available in WebGL 1 or 2. 8 | * GL_DEPTH_CLAMP clamps geometry that is outside the near and far planes, 9 | * capping the shadow volume. More information here: 10 | * https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_depth_clamp.txt. 11 | * 12 | * When GL_EXT_frag_depth is available we emulate GL_DEPTH_CLAMP by ensuring 13 | * no geometry gets clipped by setting the clip space z value to 0.0 and then 14 | * sending the unaltered screen space z value (using emulated noperspective 15 | * interpolation) to the frag shader where it is clamped to [0,1] and then 16 | * written with gl_FragDepth (see czm_writeDepthClamp). This technique is based on: 17 | * https://stackoverflow.com/questions/5960757/how-to-emulate-gl-depth-clamp-nv. 18 | * 19 | * When GL_EXT_frag_depth is not available, which is the case on some mobile 20 | * devices, we must attempt to fix this only in the vertex shader. 21 | * The approach is to clamp the z value to the far plane, which closes the 22 | * shadow volume but also distorts the geometry, so there can still be artifacts 23 | * on frustum seams. 24 | * 25 | * @name czm_depthClamp 26 | * @glslFunction 27 | * 28 | * @param {vec4} coords The vertex in clip coordinates. 29 | * @returns {vec4} The modified vertex. 30 | * 31 | * @example 32 | * gl_Position = czm_depthClamp(czm_modelViewProjection * vec4(position, 1.0)); 33 | * 34 | * @see czm_writeDepthClamp 35 | */ 36 | vec4 czm_depthClamp(vec4 coords) 37 | { 38 | #ifndef LOG_DEPTH 39 | #ifdef GL_EXT_frag_depth 40 | v_WindowZ = (0.5 * (coords.z / coords.w) + 0.5) * coords.w; 41 | coords.z = 0.0; 42 | #else 43 | coords.z = min(coords.z, coords.w); 44 | #endif 45 | #endif 46 | return coords; 47 | } 48 | -------------------------------------------------------------------------------- /src/Core/RuntimeError.ts: -------------------------------------------------------------------------------- 1 | import { defined } from './defined'; 2 | 3 | /** 4 | * Constructs an exception object that is thrown due to an error that can occur at runtime, e.g., 5 | * out of memory, could not compile shader, etc. If a function may throw this 6 | * exception, the calling code should be prepared to catch it. 7 | *

8 | * On the other hand, a {@link DeveloperError} indicates an exception due 9 | * to a developer error, e.g., invalid argument, that usually indicates a bug in the 10 | * calling code. 11 | * 12 | * @alias RuntimeError 13 | * @constructor 14 | * @extends Error 15 | * 16 | * @param {String} [message] The error message for this exception. 17 | * 18 | * @see DeveloperError 19 | */ 20 | class RuntimeError { 21 | name: string; 22 | message?: string; 23 | stack: string; 24 | constructor (message?: string) { 25 | /** 26 | * 'RuntimeError' indicating that this exception was thrown due to a runtime error. 27 | * @type {String} 28 | * @readonly 29 | */ 30 | this.name = 'RuntimeError'; 31 | 32 | /** 33 | * The explanation for why this exception was thrown. 34 | * @type {String} 35 | * @readonly 36 | */ 37 | this.message = message; 38 | 39 | // Browsers such as IE don't have a stack property until you actually throw the error. 40 | let stack; 41 | try { 42 | throw new Error(); 43 | } catch (e) { 44 | stack = (e as any).stack; 45 | } 46 | 47 | /** 48 | * The stack trace of this exception, if available. 49 | * @type {String} 50 | * @readonly 51 | */ 52 | this.stack = stack; 53 | } 54 | 55 | toString (): string { 56 | let str = this.name + ': ' + this.message; 57 | 58 | if (defined(this.stack)) { 59 | str += '\n' + this.stack.toString(); 60 | } 61 | 62 | return str; 63 | } 64 | } 65 | 66 | export { RuntimeError }; 67 | -------------------------------------------------------------------------------- /src/Core/objectToQuery.ts: -------------------------------------------------------------------------------- 1 | import { defined } from './defined'; 2 | import { DeveloperError } from './DeveloperError'; 3 | 4 | /** 5 | * Converts an object representing a set of name/value pairs into a query string, 6 | * with names and values encoded properly for use in a URL. Values that are arrays 7 | * will produce multiple values with the same name. 8 | * @function objectToQuery 9 | * 10 | * @param {Object} obj The object containing data to encode. 11 | * @returns {String} An encoded query string. 12 | * 13 | * 14 | * @example 15 | * var str = Cesium.objectToQuery({ 16 | * key1 : 'some value', 17 | * key2 : 'a/b', 18 | * key3 : ['x', 'y'] 19 | * }); 20 | * 21 | * @see queryToObject 22 | * // str will be: 23 | * // 'key1=some%20value&key2=a%2Fb&key3=x&key3=y' 24 | */ 25 | function objectToQuery (obj: any): string { 26 | // >>includeStart('debug', pragmas.debug); 27 | if (!defined(obj)) { 28 | throw new DeveloperError('obj is required.'); 29 | } 30 | // >>includeEnd('debug'); 31 | 32 | let result = ''; 33 | for (const propName in obj) { 34 | // if (obj.hasOwnProperty(propName)) { 35 | if (Object.prototype.hasOwnProperty.call(obj, propName)) { 36 | const value = obj[propName]; 37 | 38 | const part = encodeURIComponent(propName) + '='; 39 | if (Array.isArray(value)) { 40 | for (let i = 0, len = value.length; i < len; ++i) { 41 | result += part + encodeURIComponent(value[i]) + '&'; 42 | } 43 | } else { 44 | result += part + encodeURIComponent(value) + '&'; 45 | } 46 | } 47 | } 48 | 49 | // trim last & 50 | result = result.slice(0, -1); 51 | 52 | // This function used to replace %20 with + which is more compact and readable. 53 | // However, some servers didn't properly handle + as a space. 54 | // https://github.com/CesiumGS/cesium/issues/2192 55 | 56 | return result; 57 | } 58 | export { objectToQuery }; 59 | -------------------------------------------------------------------------------- /src/Core/destroyObject.ts: -------------------------------------------------------------------------------- 1 | import { defaultValue } from './defaultValue'; 2 | import { DeveloperError } from './DeveloperError'; 3 | 4 | function returnTrue (): boolean { 5 | return true; 6 | } 7 | 8 | /** 9 | * Destroys an object. Each of the object's functions, including functions in its prototype, 10 | * is replaced with a function that throws a {@link DeveloperError}, except for the object's 11 | * isDestroyed function, which is set to a function that returns true. 12 | * The object's properties are removed with delete. 13 | *

14 | * This function is used by objects that hold native resources, e.g., WebGL resources, which 15 | * need to be explicitly released. Client code calls an object's destroy function, 16 | * which then releases the native resource and calls destroyObject to put itself 17 | * in a destroyed state. 18 | * 19 | * @function 20 | * 21 | * @param {Object} object The object to destroy. 22 | * @param {String} [message] The message to include in the exception that is thrown if 23 | * a destroyed object's function is called. 24 | * 25 | * 26 | * @example 27 | * // How a texture would destroy itself. 28 | * this.destroy = function () { 29 | * _gl.deleteTexture(_texture); 30 | * return Cesium.destroyObject(this); 31 | * }; 32 | * 33 | * @see DeveloperError 34 | */ 35 | function destroyObject (object: any, message?: string): void { 36 | message = defaultValue(message, 'This object was destroyed, i.e., destroy() was called.'); 37 | 38 | function throwOnDestroyed () { 39 | // >>includeStart('debug', pragmas.debug); 40 | throw new DeveloperError(message); 41 | // >>includeEnd('debug'); 42 | } 43 | 44 | for (const key in object) { 45 | if (typeof object[key] === 'function') { 46 | object[key] = throwOnDestroyed; 47 | } 48 | } 49 | 50 | object.isDestroyed = returnTrue; 51 | 52 | return undefined; 53 | } 54 | 55 | export { destroyObject }; 56 | -------------------------------------------------------------------------------- /src/Core/queryToObject.ts: -------------------------------------------------------------------------------- 1 | import { defined } from './defined'; 2 | import { DeveloperError } from './DeveloperError'; 3 | 4 | /** 5 | * Parses a query string into an object, where the keys and values of the object are the 6 | * name/value pairs from the query string, decoded. If a name appears multiple times, 7 | * the value in the object will be an array of values. 8 | * @function queryToObject 9 | * 10 | * @param {String} queryString The query string. 11 | * @returns {Object} An object containing the parameters parsed from the query string. 12 | * 13 | * 14 | * @example 15 | * var obj = Cesium.queryToObject('key1=some%20value&key2=a%2Fb&key3=x&key3=y'); 16 | * // obj will be: 17 | * // { 18 | * // key1 : 'some value', 19 | * // key2 : 'a/b', 20 | * // key3 : ['x', 'y'] 21 | * // } 22 | * 23 | * @see objectToQuery 24 | */ 25 | function queryToObject (queryString: string): any { 26 | // >>includeStart('debug', pragmas.debug); 27 | if (!defined(queryString)) { 28 | throw new DeveloperError('queryString is required.'); 29 | } 30 | // >>includeEnd('debug'); 31 | 32 | const result = {}; 33 | if (queryString === '') { 34 | return result; 35 | } 36 | const parts = queryString.replace(/\+/g, '%20').split(/[&;]/); 37 | for (let i = 0, len = parts.length; i < len; ++i) { 38 | const subparts = parts[i].split('='); 39 | 40 | const name = decodeURIComponent(subparts[0]); 41 | let value = subparts[1]; 42 | if (defined(value)) { 43 | value = decodeURIComponent(value); 44 | } else { 45 | value = ''; 46 | } 47 | 48 | const resultValue = result[name]; 49 | if (typeof resultValue === 'string') { 50 | // expand the single value to an array 51 | result[name] = [resultValue, value]; 52 | } else if (Array.isArray(resultValue)) { 53 | resultValue.push(value); 54 | } else { 55 | result[name] = value; 56 | } 57 | } 58 | return result; 59 | } 60 | export { queryToObject }; 61 | -------------------------------------------------------------------------------- /src/Core/TimeConstants.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Constants for time conversions like those done by {@link JulianDate}. 3 | * 4 | * @namespace TimeConstants 5 | * 6 | * @see JulianDate 7 | * 8 | * @private 9 | */ 10 | enum TimeConstants { 11 | /** 12 | * The number of seconds in one millisecond: 0.001 13 | * @type {Number} 14 | * @constant 15 | */ 16 | SECONDS_PER_MILLISECOND = 0.001, 17 | 18 | /** 19 | * The number of seconds in one minute: 60. 20 | * @type {Number} 21 | * @constant 22 | */ 23 | SECONDS_PER_MINUTE = 60.0, 24 | 25 | /** 26 | * The number of minutes in one hour: 60. 27 | * @type {Number} 28 | * @constant 29 | */ 30 | MINUTES_PER_HOUR = 60.0, 31 | 32 | /** 33 | * The number of hours in one day: 24. 34 | * @type {Number} 35 | * @constant 36 | */ 37 | HOURS_PER_DAY = 24.0, 38 | 39 | /** 40 | * The number of seconds in one hour: 3600. 41 | * @type {Number} 42 | * @constant 43 | */ 44 | SECONDS_PER_HOUR = 3600.0, 45 | 46 | /** 47 | * The number of minutes in one day: 1440. 48 | * @type {Number} 49 | * @constant 50 | */ 51 | MINUTES_PER_DAY = 1440.0, 52 | 53 | /** 54 | * The number of seconds in one day, ignoring leap seconds: 86400. 55 | * @type {Number} 56 | * @constant 57 | */ 58 | SECONDS_PER_DAY = 86400.0, 59 | 60 | /** 61 | * The number of days in one Julian century: 36525. 62 | * @type {Number} 63 | * @constant 64 | */ 65 | DAYS_PER_JULIAN_CENTURY = 36525.0, 66 | 67 | /** 68 | * One trillionth of a second. 69 | * @type {Number} 70 | * @constant 71 | */ 72 | PICOSECOND = 0.000000001, 73 | 74 | /** 75 | * The number of days to subtract from a Julian date to determine the 76 | * modified Julian date, which gives the number of days since midnight 77 | * on November 17, 1858. 78 | * @type {Number} 79 | * @constant 80 | */ 81 | MODIFIED_JULIAN_DATE_DIFFERENCE = 2400000.5 82 | } 83 | export { TimeConstants }; 84 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/metersPerPixel.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Computes the size of a pixel in meters at a distance from the eye. 3 | *

4 | * Use this version when passing in a custom pixel ratio. For example, passing in 1.0 will return meters per native device pixel. 5 | *

6 | * @name czm_metersPerPixel 7 | * @glslFunction 8 | * 9 | * @param {vec3} positionEC The position to get the meters per pixel in eye coordinates. 10 | * @param {float} pixelRatio The scaling factor from pixel space to coordinate space 11 | * 12 | * @returns {float} The meters per pixel at positionEC. 13 | */ 14 | float czm_metersPerPixel(vec4 positionEC, float pixelRatio) 15 | { 16 | float width = czm_viewport.z; 17 | float height = czm_viewport.w; 18 | float pixelWidth; 19 | float pixelHeight; 20 | 21 | float top = czm_frustumPlanes.x; 22 | float bottom = czm_frustumPlanes.y; 23 | float left = czm_frustumPlanes.z; 24 | float right = czm_frustumPlanes.w; 25 | 26 | if (czm_sceneMode == czm_sceneMode2D || czm_orthographicIn3D == 1.0) 27 | { 28 | float frustumWidth = right - left; 29 | float frustumHeight = top - bottom; 30 | pixelWidth = frustumWidth / width; 31 | pixelHeight = frustumHeight / height; 32 | } 33 | else 34 | { 35 | float distanceToPixel = -positionEC.z; 36 | float inverseNear = 1.0 / czm_currentFrustum.x; 37 | float tanTheta = top * inverseNear; 38 | pixelHeight = 2.0 * distanceToPixel * tanTheta / height; 39 | tanTheta = right * inverseNear; 40 | pixelWidth = 2.0 * distanceToPixel * tanTheta / width; 41 | } 42 | 43 | return max(pixelWidth, pixelHeight) * pixelRatio; 44 | } 45 | 46 | /** 47 | * Computes the size of a pixel in meters at a distance from the eye. 48 | *

49 | * Use this version when scaling by pixel ratio. 50 | *

51 | * @name czm_metersPerPixel 52 | * @glslFunction 53 | * 54 | * @param {vec3} positionEC The position to get the meters per pixel in eye coordinates. 55 | * 56 | * @returns {float} The meters per pixel at positionEC. 57 | */ 58 | float czm_metersPerPixel(vec4 positionEC) 59 | { 60 | return czm_metersPerPixel(positionEC, czm_pixelRatio); 61 | } 62 | -------------------------------------------------------------------------------- /src/Core/binarySearch.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Finds an item in a sorted array. 4 | * 5 | * @function 6 | * @param {Array} array The sorted array to search. 7 | * @param {*} itemToFind The item to find in the array. 8 | * @param {binarySearchComparator} comparator The function to use to compare the item to 9 | * elements in the array. 10 | * @returns {Number} The index of itemToFind in the array, if it exists. If itemToFind 11 | * does not exist, the return value is a negative number which is the bitwise complement (~) 12 | * of the index before which the itemToFind should be inserted in order to maintain the 13 | * sorted order of the array. 14 | * 15 | * @example 16 | * // Create a comparator function to search through an array of numbers. 17 | * function comparator(a, b) { 18 | * return a - b; 19 | * }; 20 | * var numbers = [0, 2, 4, 6, 8]; 21 | * var index = Cesium.binarySearch(numbers, 6, comparator); // 3 22 | */ 23 | function binarySearch (array: any, itemToFind: any, comparator: any) { 24 | // >>includeStart('debug', pragmas.debug); 25 | 26 | let low = 0; 27 | let high = array.length - 1; 28 | let i; 29 | let comparison; 30 | 31 | while (low <= high) { 32 | i = ~~((low + high) / 2); 33 | comparison = comparator(array[i], itemToFind); 34 | if (comparison < 0) { 35 | low = i + 1; 36 | continue; 37 | } 38 | if (comparison > 0) { 39 | high = i - 1; 40 | continue; 41 | } 42 | return i; 43 | } 44 | return ~(high + 1); 45 | } 46 | 47 | /** 48 | * A function used to compare two items while performing a binary search. 49 | * @callback binarySearchComparator 50 | * 51 | * @param {*} a An item in the array. 52 | * @param {*} b The item being searched for. 53 | * @returns {Number} Returns a negative value if a is less than b, 54 | * a positive value if a is greater than b, or 55 | * 0 if a is equal to b. 56 | * 57 | * @example 58 | * function compareNumbers(a, b) { 59 | * return a - b; 60 | * } 61 | */ 62 | export { binarySearch }; 63 | -------------------------------------------------------------------------------- /src/Core/ComponentDatatype.ts: -------------------------------------------------------------------------------- 1 | import { defined } from './defined'; 2 | import { DeveloperError } from './DeveloperError'; 3 | 4 | const ComponentDatatype = { 5 | BYTE: 5120, 6 | DOUBLE: 5130, 7 | FLOAT: 5126, 8 | INT: 5124, 9 | SHORT: 5122, 10 | UNSIGNED_BYTE: 5121, 11 | UNSIGNED_INT: 5125, 12 | UNSIGNED_SHORT: 5123, 13 | 14 | /** 15 | * Returns the size, in bytes, of the corresponding datatype. 16 | * 17 | * @param {ComponentDatatype} componentDatatype The component datatype to get the size of. 18 | * @returns {Number} The size in bytes. 19 | * 20 | * @exception {DeveloperError} componentDatatype is not a valid value. 21 | * 22 | * @example 23 | * // Returns Int8Array.BYTES_PER_ELEMENT 24 | * var size = Cesium.ComponentDatatype.getSizeInBytes(Cesium.ComponentDatatype.BYTE); 25 | */ 26 | getSizeInBytes: (componentDatatype: number) => { 27 | // >>includeStart('debug', pragmas.debug); 28 | if (!defined(componentDatatype)) { 29 | throw new DeveloperError('value is required.'); 30 | } 31 | // >>includeEnd('debug'); 32 | 33 | switch (componentDatatype) { 34 | case ComponentDatatype.BYTE: 35 | return Int8Array.BYTES_PER_ELEMENT; 36 | case ComponentDatatype.UNSIGNED_BYTE: 37 | return Uint8Array.BYTES_PER_ELEMENT; 38 | case ComponentDatatype.SHORT: 39 | return Int16Array.BYTES_PER_ELEMENT; 40 | case ComponentDatatype.UNSIGNED_SHORT: 41 | return Uint16Array.BYTES_PER_ELEMENT; 42 | case ComponentDatatype.INT: 43 | return Int32Array.BYTES_PER_ELEMENT; 44 | case ComponentDatatype.UNSIGNED_INT: 45 | return Uint32Array.BYTES_PER_ELEMENT; 46 | case ComponentDatatype.FLOAT: 47 | return Float32Array.BYTES_PER_ELEMENT; 48 | case ComponentDatatype.DOUBLE: 49 | return Float64Array.BYTES_PER_ELEMENT; 50 | // >>includeStart('debug', pragmas.debug); 51 | default: 52 | throw new DeveloperError('componentDatatype is not a valid value.'); 53 | // >>includeEnd('debug'); 54 | } 55 | } 56 | }; 57 | 58 | export { ComponentDatatype }; 59 | -------------------------------------------------------------------------------- /src/Material/GeographicReprojectMaterial.ts: -------------------------------------------------------------------------------- 1 | import { defined } from '@/Core/defined'; 2 | import { DoubleSide, RawShaderMaterial, Texture, Vector2 } from 'three'; 3 | 4 | const vs = ` 5 | 6 | 7 | attribute vec4 position; 8 | attribute float webMercatorT; 9 | 10 | uniform vec2 u_textureDimensions; 11 | 12 | uniform mat4 modelViewMatrix; // optional 13 | uniform mat4 projectionMatrix; // optional 14 | 15 | varying vec2 v_textureCoordinates; 16 | 17 | void main() 18 | { 19 | v_textureCoordinates = vec2(position.x, webMercatorT); 20 | // gl_Position = projectionMatrix * modelViewMatrix * (vec4(position.xyz, 1.0) * vec4(u_textureDimensions, 1.0, 1.0) + vec4(0.0, 0.0, 0.0, 0.0)); 21 | 22 | gl_Position = projectionMatrix * modelViewMatrix * (vec4(position.xyz + vec3(-0.5, -0.5, 0.0), 1.0)); 23 | } 24 | `; 25 | 26 | const fs = ` 27 | precision mediump float; 28 | precision mediump int; 29 | 30 | uniform sampler2D u_texture; 31 | uniform vec4 u_randomColor; 32 | varying vec2 v_textureCoordinates; 33 | 34 | void main() 35 | { 36 | gl_FragColor = texture2D(u_texture, v_textureCoordinates); 37 | } 38 | `; 39 | class GeographicReprojectMaterial extends RawShaderMaterial { 40 | constructor (parameters = {}) { 41 | super(parameters); 42 | 43 | this.lights = false; 44 | this.fog = false; 45 | 46 | this.uniforms = { 47 | u_texture: { value: new Texture() }, 48 | u_textureDimensions: { value: new Vector2() } 49 | }; 50 | 51 | this.vertexShader = vs; 52 | this.fragmentShader = fs; 53 | this.side = DoubleSide; 54 | } 55 | 56 | get texture ():Texture { 57 | return this.uniforms.u_texture.value; 58 | } 59 | 60 | set texture (value: Texture) { 61 | if (!defined(value)) { 62 | return; 63 | } 64 | this.uniforms.u_texture.value = value; 65 | } 66 | 67 | get textureDimensions (): Vector2 { 68 | return this.uniforms.u_textureDimensions.value; 69 | } 70 | 71 | set textureDimensions (value: Vector2) { 72 | if (!defined(value)) { 73 | return; 74 | } 75 | this.uniforms.u_textureDimensions.value.copy(value); 76 | } 77 | } 78 | export { GeographicReprojectMaterial }; 79 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/vertexLogDepth.glsl: -------------------------------------------------------------------------------- 1 | #ifdef LOG_DEPTH 2 | // 1.0 at the near plane, increasing linearly from there. 3 | varying float v_depthFromNearPlusOne; 4 | #ifdef SHADOW_MAP 5 | varying vec3 v_logPositionEC; 6 | #endif 7 | #endif 8 | 9 | vec4 czm_updatePositionDepth(vec4 coords) { 10 | #if defined(LOG_DEPTH) 11 | 12 | #ifdef SHADOW_MAP 13 | vec3 logPositionEC = (czm_inverseProjection * coords).xyz; 14 | v_logPositionEC = logPositionEC; 15 | #endif 16 | 17 | // With the very high far/near ratios used with the logarithmic depth 18 | // buffer, floating point rounding errors can cause linear depth values 19 | // to end up on the wrong side of the far plane, even for vertices that 20 | // are really nowhere near it. Since we always write a correct logarithmic 21 | // depth value in the fragment shader anyway, we just need to make sure 22 | // such errors don't cause the primitive to be clipped entirely before 23 | // we even get to the fragment shader. 24 | coords.z = clamp(coords.z / coords.w, -1.0, 1.0) * coords.w; 25 | #endif 26 | 27 | return coords; 28 | } 29 | 30 | /** 31 | * Writes the logarithmic depth to gl_Position using the already computed gl_Position. 32 | * 33 | * @name czm_vertexLogDepth 34 | * @glslFunction 35 | */ 36 | void czm_vertexLogDepth() 37 | { 38 | #ifdef LOG_DEPTH 39 | v_depthFromNearPlusOne = (gl_Position.w - czm_currentFrustum.x) + 1.0; 40 | gl_Position = czm_updatePositionDepth(gl_Position); 41 | #endif 42 | } 43 | 44 | /** 45 | * Writes the logarithmic depth to gl_Position using the provided clip coordinates. 46 | *

47 | * An example use case for this function would be moving the vertex in window coordinates 48 | * before converting back to clip coordinates. Use the original vertex clip coordinates. 49 | *

50 | * @name czm_vertexLogDepth 51 | * @glslFunction 52 | * 53 | * @param {vec4} clipCoords The vertex in clip coordinates. 54 | * 55 | * @example 56 | * czm_vertexLogDepth(czm_projection * vec4(positionEyeCoordinates, 1.0)); 57 | */ 58 | void czm_vertexLogDepth(vec4 clipCoords) 59 | { 60 | #ifdef LOG_DEPTH 61 | v_depthFromNearPlusOne = (clipCoords.w - czm_currentFrustum.x) + 1.0; 62 | czm_updatePositionDepth(clipCoords); 63 | #endif 64 | } 65 | -------------------------------------------------------------------------------- /src/Renderer/ComputedShaderPass.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable max-statements-per-line */ 2 | import { MapRenderer } from '@/Scene/MapRenderer'; 3 | import { 4 | Material, 5 | RawShaderMaterial, 6 | ShaderMaterial, 7 | UniformsUtils, 8 | WebGLRenderTarget 9 | } from 'three'; 10 | import { ComputedPass, FullScreenQuad } from './ComputedPass'; 11 | 12 | class ComputedShaderPass extends ComputedPass { 13 | uniforms: any; 14 | textureID: string; 15 | material: Material | undefined; 16 | fsQuad: FullScreenQuad; 17 | constructor (shader: any, textureID?: string) { 18 | super(); 19 | 20 | this.textureID = textureID !== undefined 21 | ? textureID 22 | : 'tDiffuse'; 23 | 24 | if (shader instanceof ShaderMaterial) { 25 | this.uniforms = shader.uniforms; 26 | 27 | this.material = shader; 28 | } else if (shader) { 29 | this.uniforms = UniformsUtils.clone(shader.uniforms); 30 | 31 | this.material = new ShaderMaterial({ 32 | 33 | // defines: { ...shader.defines }, 34 | uniforms: this.uniforms, 35 | vertexShader: shader.vertexShader, 36 | fragmentShader: shader.fragmentShader 37 | 38 | }); 39 | } 40 | 41 | this.fsQuad = new FullScreenQuad((this.material as Material)); 42 | } 43 | 44 | public render (renderer:MapRenderer, writeBuffer: WebGLRenderTarget, readBuffer: WebGLRenderTarget /*, deltaTime, maskActive */): void { 45 | if (this.uniforms[this.textureID]) { 46 | this.uniforms[this.textureID].value = readBuffer.texture; 47 | } 48 | 49 | this.fsQuad.material = (this.material as Material); 50 | 51 | if (this.renderToScreen) { 52 | renderer.setRenderTarget(null); 53 | this.fsQuad.render(renderer); 54 | } else { 55 | renderer.setRenderTarget(writeBuffer); 56 | // TODO: Avoid using autoClear properties, see https://github.com/mrdoob/three/pull/15571#issuecomment-465669600 57 | if (this.clear) { 58 | renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil); 59 | } 60 | this.fsQuad.render(renderer); 61 | } 62 | } 63 | } 64 | 65 | export { ComputedShaderPass }; 66 | -------------------------------------------------------------------------------- /src/Renderer/ComputedPass.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-empty-function */ 2 | /* eslint-disable @typescript-eslint/no-unused-vars */ 3 | import { MapRenderer } from '@/Scene/MapRenderer'; 4 | import { 5 | BufferGeometry, 6 | Float32BufferAttribute, 7 | OrthographicCamera, 8 | Mesh, 9 | Material 10 | } from 'three'; 11 | 12 | class ComputedPass { 13 | enabled: boolean; 14 | needsSwap: boolean; 15 | clear: boolean; 16 | renderToScreen: boolean; 17 | constructor () { 18 | // if set to true, the pass is processed by the composer 19 | this.enabled = true; 20 | 21 | // if set to true, the pass indicates to swap read and write buffer after rendering 22 | this.needsSwap = true; 23 | 24 | // if set to true, the pass clears its buffer before rendering 25 | this.clear = false; 26 | 27 | // if set to true, the result of the pass is rendered to screen. This is set automatically by EffectComposer. 28 | this.renderToScreen = false; 29 | } 30 | 31 | setSize (/* width, height */) { 32 | 33 | } 34 | 35 | public render (renderer: any, writeBuffer: any, readBuffer: any, deltaTime: any, maskActive: any):void { 36 | console.error('THREE.Pass: .render() must be implemented in derived pass.'); 37 | } 38 | } 39 | 40 | // Helper for passes that need to fill the viewport with a single quad. 41 | 42 | const _camera = new OrthographicCamera(-0.5, 0.5, 0.5, -0.5, 0, 0.5); 43 | 44 | // https://github.com/mrdoob/three/pull/21358 45 | 46 | const _geometry = new BufferGeometry(); 47 | _geometry.setAttribute('position', new Float32BufferAttribute([-1, 3, 0, -1, -1, 0, 3, -1, 0], 3)); 48 | _geometry.setAttribute('uv', new Float32BufferAttribute([0, 2, 0, 0, 2, 0], 2)); 49 | 50 | class FullScreenQuad { 51 | _mesh: Mesh 52 | constructor (material:Material) { 53 | this._mesh = new Mesh(_geometry, material); 54 | } 55 | 56 | get material (): Material { 57 | return (this._mesh.material as Material); 58 | } 59 | 60 | set material (value) { 61 | this._mesh.material = value; 62 | } 63 | 64 | dispose (): void { 65 | this._mesh.geometry.dispose(); 66 | } 67 | 68 | render (renderer: MapRenderer): void { 69 | renderer.render(this._mesh, _camera); 70 | } 71 | } 72 | 73 | export { ComputedPass, FullScreenQuad }; 74 | -------------------------------------------------------------------------------- /src/Core/RequestErrorEvent.ts: -------------------------------------------------------------------------------- 1 | import { defined } from './defined'; 2 | import { parseResponseHeaders } from './parseResponseHeaders'; 3 | 4 | /** 5 | * An event that is raised when a request encounters an error. 6 | * 7 | * @constructor 8 | * @alias RequestErrorEvent 9 | * 10 | * @param {Number} [statusCode] The HTTP error status code, such as 404. 11 | * @param {Object} [response] The response included along with the error. 12 | * @param {String|Object} [responseHeaders] The response headers, represented either as an object literal or as a 13 | * string in the format returned by XMLHttpRequest's getAllResponseHeaders() function. 14 | */ 15 | class RequestErrorEvent { 16 | statusCode: any; 17 | response: any; 18 | responseHeaders: any; 19 | constructor (statusCode?: any, response?: any, responseHeaders?: any) { 20 | /** 21 | * The HTTP error status code, such as 404. If the error does not have a particular 22 | * HTTP code, this property will be undefined. 23 | * 24 | * @type {Number} 25 | */ 26 | this.statusCode = statusCode; 27 | 28 | /** 29 | * The response included along with the error. If the error does not include a response, 30 | * this property will be undefined. 31 | * 32 | * @type {Object} 33 | */ 34 | this.response = response; 35 | 36 | /** 37 | * The headers included in the response, represented as an object literal of key/value pairs. 38 | * If the error does not include any headers, this property will be undefined. 39 | * 40 | * @type {Object} 41 | */ 42 | this.responseHeaders = responseHeaders; 43 | 44 | if (typeof this.responseHeaders === 'string') { 45 | this.responseHeaders = parseResponseHeaders(this.responseHeaders); 46 | } 47 | } 48 | 49 | /** 50 | * Creates a string representing this RequestErrorEvent. 51 | * @memberof RequestErrorEvent 52 | * 53 | * @returns {String} A string representing the provided RequestErrorEvent. 54 | */ 55 | toString () { 56 | let str = 'Request has failed.'; 57 | if (defined(this.statusCode)) { 58 | str += ' Status Code: ' + this.statusCode; 59 | } 60 | return str; 61 | } 62 | } 63 | 64 | export { RequestErrorEvent }; 65 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/writeLogDepth.glsl: -------------------------------------------------------------------------------- 1 | #ifdef LOG_DEPTH 2 | varying float v_depthFromNearPlusOne; 3 | 4 | #ifdef POLYGON_OFFSET 5 | uniform vec2 u_polygonOffset; 6 | #endif 7 | 8 | #endif 9 | 10 | /** 11 | * Writes the fragment depth to the logarithmic depth buffer. 12 | *

13 | * Use this when the vertex shader does not call {@link czm_vertexlogDepth}, for example, when 14 | * ray-casting geometry using a full screen quad. 15 | *

16 | * @name czm_writeLogDepth 17 | * @glslFunction 18 | * 19 | * @param {float} depth The depth coordinate, where 1.0 is on the near plane and 20 | * depth increases in eye-space units from there 21 | * 22 | * @example 23 | * czm_writeLogDepth((czm_projection * v_positionEyeCoordinates).w + 1.0); 24 | */ 25 | void czm_writeLogDepth(float depth) 26 | { 27 | #if defined(GL_EXT_frag_depth) && defined(LOG_DEPTH) 28 | // Discard the vertex if it's not between the near and far planes. 29 | // We allow a bit of epsilon on the near plane comparison because a 1.0 30 | // from the vertex shader (indicating the vertex should be _on_ the near 31 | // plane) will not necessarily come here as exactly 1.0. 32 | if (depth <= 0.9999999 || depth > czm_farDepthFromNearPlusOne) { 33 | discard; 34 | } 35 | 36 | #ifdef POLYGON_OFFSET 37 | // Polygon offset: m * factor + r * units 38 | float factor = u_polygonOffset[0]; 39 | float units = u_polygonOffset[1]; 40 | 41 | // If we can't compute derivatives, just leave out the factor I guess? 42 | #ifdef GL_OES_standard_derivatives 43 | // m = sqrt(dZdX^2 + dZdY^2); 44 | float x = dFdx(depth); 45 | float y = dFdy(depth); 46 | float m = sqrt(x * x + y * y); 47 | 48 | // Apply the factor before computing the log depth. 49 | depth += m * factor; 50 | #endif 51 | 52 | #endif 53 | 54 | gl_FragDepthEXT = log2(depth) * czm_oneOverLog2FarDepthFromNearPlusOne; 55 | 56 | #ifdef POLYGON_OFFSET 57 | // Apply the units after the log depth. 58 | gl_FragDepthEXT += czm_epsilon7 * units; 59 | #endif 60 | 61 | #endif 62 | } 63 | 64 | /** 65 | * Writes the fragment depth to the logarithmic depth buffer. 66 | *

67 | * Use this when the vertex shader calls {@link czm_vertexlogDepth}. 68 | *

69 | * 70 | * @name czm_writeLogDepth 71 | * @glslFunction 72 | */ 73 | void czm_writeLogDepth() { 74 | #ifdef LOG_DEPTH 75 | czm_writeLogDepth(v_depthFromNearPlusOne); 76 | #endif 77 | } 78 | -------------------------------------------------------------------------------- /src/Core/createVerticesFromHeightmap.ts: -------------------------------------------------------------------------------- 1 | 2 | import HeightmapTessellator from './HeightmapTessellator'; 3 | import Lerc from './../ThirdParty/LercDecode'; 4 | import { Ellipsoid } from './Ellipsoid'; 5 | import { Rectangle } from './Rectangle'; 6 | import { HeightmapEncoding } from './HeightmapEncoding'; 7 | import { DeveloperError } from './DeveloperError'; 8 | // import createTaskProcessorWorker from "./createTaskProcessorWorker"; 9 | 10 | function createVerticesFromHeightmap (parameters: any, transferableObjects:any[]): any { 11 | // LERC encoded buffers must be decoded, then we can process them like normal 12 | if (parameters.encoding === HeightmapEncoding.LERC) { 13 | let result; 14 | try { 15 | result = Lerc.decode(parameters.heightmap); 16 | } catch (error) { 17 | throw new DeveloperError(error as string); 18 | } 19 | 20 | const lercStatistics = result.statistics[0]; 21 | if (lercStatistics.minValue === Number.MAX_VALUE) { 22 | throw new DeveloperError('Invalid tile data'); 23 | } 24 | 25 | parameters.heightmap = result.pixels[0]; 26 | parameters.width = result.width; 27 | parameters.height = result.height; 28 | } 29 | 30 | parameters.ellipsoid = Ellipsoid.clone(parameters.ellipsoid); 31 | parameters.rectangle = Rectangle.clone(parameters.rectangle); 32 | 33 | const statistics = HeightmapTessellator.computeVertices(parameters); 34 | const vertices = statistics.vertices; 35 | transferableObjects.push(vertices.buffer); 36 | 37 | return { 38 | vertices: vertices.buffer, 39 | numberOfAttributes: statistics.encoding.stride, 40 | minimumHeight: statistics.minimumHeight, 41 | maximumHeight: statistics.maximumHeight, 42 | gridWidth: parameters.width, 43 | gridHeight: parameters.height, 44 | boundingSphere3D: statistics.boundingSphere3D, 45 | orientedBoundingBox: statistics.orientedBoundingBox, 46 | occludeePointInScaledSpace: statistics.occludeePointInScaledSpace, 47 | encoding: statistics.encoding, 48 | westIndicesSouthToNorth: statistics.westIndicesSouthToNorth, 49 | southIndicesEastToWest: statistics.southIndicesEastToWest, 50 | eastIndicesNorthToSouth: statistics.eastIndicesNorthToSouth, 51 | northIndicesWestToEast: statistics.northIndicesWestToEast 52 | }; 53 | } 54 | 55 | export { createVerticesFromHeightmap }; 56 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/phong.glsl: -------------------------------------------------------------------------------- 1 | float czm_private_getLambertDiffuseOfMaterial(vec3 lightDirectionEC, czm_material material) 2 | { 3 | return czm_getLambertDiffuse(lightDirectionEC, material.normal); 4 | } 5 | 6 | float czm_private_getSpecularOfMaterial(vec3 lightDirectionEC, vec3 toEyeEC, czm_material material) 7 | { 8 | return czm_getSpecular(lightDirectionEC, toEyeEC, material.normal, material.shininess); 9 | } 10 | 11 | /** 12 | * Computes a color using the Phong lighting model. 13 | * 14 | * @name czm_phong 15 | * @glslFunction 16 | * 17 | * @param {vec3} toEye A normalized vector from the fragment to the eye in eye coordinates. 18 | * @param {czm_material} material The fragment's material. 19 | * 20 | * @returns {vec4} The computed color. 21 | * 22 | * @example 23 | * vec3 positionToEyeEC = // ... 24 | * czm_material material = // ... 25 | * vec3 lightDirectionEC = // ... 26 | * gl_FragColor = czm_phong(normalize(positionToEyeEC), material, lightDirectionEC); 27 | * 28 | * @see czm_getMaterial 29 | */ 30 | vec4 czm_phong(vec3 toEye, czm_material material, vec3 lightDirectionEC) 31 | { 32 | // Diffuse from directional light sources at eye (for top-down) 33 | float diffuse = czm_private_getLambertDiffuseOfMaterial(vec3(0.0, 0.0, 1.0), material); 34 | if (czm_sceneMode == czm_sceneMode3D) { 35 | // (and horizon views in 3D) 36 | diffuse += czm_private_getLambertDiffuseOfMaterial(vec3(0.0, 1.0, 0.0), material); 37 | } 38 | 39 | float specular = czm_private_getSpecularOfMaterial(lightDirectionEC, toEye, material); 40 | 41 | // Temporary workaround for adding ambient. 42 | vec3 materialDiffuse = material.diffuse * 0.5; 43 | 44 | vec3 ambient = materialDiffuse; 45 | vec3 color = ambient + material.emission; 46 | color += materialDiffuse * diffuse * czm_lightColor; 47 | color += material.specular * specular * czm_lightColor; 48 | 49 | return vec4(color, material.alpha); 50 | } 51 | 52 | vec4 czm_private_phong(vec3 toEye, czm_material material, vec3 lightDirectionEC) 53 | { 54 | float diffuse = czm_private_getLambertDiffuseOfMaterial(lightDirectionEC, material); 55 | float specular = czm_private_getSpecularOfMaterial(lightDirectionEC, toEye, material); 56 | 57 | vec3 ambient = vec3(0.0); 58 | vec3 color = ambient + material.emission; 59 | color += material.diffuse * diffuse * czm_lightColor; 60 | color += material.specular * specular * czm_lightColor; 61 | 62 | return vec4(color, material.alpha); 63 | } 64 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/fastApproximateAtan.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Approxiamtes atan over the range [0, 1]. Safe to flip output for negative input. 3 | * 4 | * Based on Michal Drobot's approximation from ShaderFastLibs, which in turn is based on 5 | * "Efficient approximations for the arctangent function," Rajan, S. Sichun Wang Inkol, R. Joyal, A., May 2006. 6 | * Adapted from ShaderFastLibs under MIT License. 7 | * 8 | * Chosen for the following characteristics over range [0, 1]: 9 | * - basically no error at 0 and 1, important for getting around range limit (naive atan2 via atan requires infinite range atan) 10 | * - no visible artifacts from first-derivative discontinuities, unlike latitude via range-reduced sqrt asin approximations (at equator) 11 | * 12 | * The original code is x * (-0.1784 * abs(x) - 0.0663 * x * x + 1.0301); 13 | * Removed the abs() in here because it isn't needed, the input range is guaranteed as [0, 1] by how we're approximating atan2. 14 | * 15 | * @name czm_fastApproximateAtan 16 | * @glslFunction 17 | * 18 | * @param {float} x Value between 0 and 1 inclusive. 19 | * 20 | * @returns {float} Approximation of atan(x) 21 | */ 22 | float czm_fastApproximateAtan(float x) { 23 | return x * (-0.1784 * x - 0.0663 * x * x + 1.0301); 24 | } 25 | 26 | /** 27 | * Approximation of atan2. 28 | * 29 | * Range reduction math based on nvidia's cg reference implementation for atan2: http://developer.download.nvidia.com/cg/atan2.html 30 | * However, we replaced their atan curve with Michael Drobot's (see above). 31 | * 32 | * @name czm_fastApproximateAtan 33 | * @glslFunction 34 | * 35 | * @param {float} x Value between -1 and 1 inclusive. 36 | * @param {float} y Value between -1 and 1 inclusive. 37 | * 38 | * @returns {float} Approximation of atan2(x, y) 39 | */ 40 | float czm_fastApproximateAtan(float x, float y) { 41 | // atan approximations are usually only reliable over [-1, 1], or, in our case, [0, 1] due to modifications. 42 | // So range-reduce using abs and by flipping whether x or y is on top. 43 | float t = abs(x); // t used as swap and atan result. 44 | float opposite = abs(y); 45 | float adjacent = max(t, opposite); 46 | opposite = min(t, opposite); 47 | 48 | t = czm_fastApproximateAtan(opposite / adjacent); 49 | 50 | // Undo range reduction 51 | t = czm_branchFreeTernary(abs(y) > abs(x), czm_piOverTwo - t, t); 52 | t = czm_branchFreeTernary(x < 0.0, czm_pi - t, t); 53 | t = czm_branchFreeTernary(y < 0.0, -t, t); 54 | return t; 55 | } 56 | -------------------------------------------------------------------------------- /src/Core/DeveloperError.ts: -------------------------------------------------------------------------------- 1 | import { defined } from './defined'; 2 | 3 | /** 4 | * Constructs an exception object that is thrown due to a developer error, e.g., invalid argument, 5 | * argument out of range, etc. This exception should only be thrown during development; 6 | * it usually indicates a bug in the calling code. This exception should never be 7 | * caught; instead the calling code should strive not to generate it. 8 | *

9 | * On the other hand, a {@link RuntimeError} indicates an exception that may 10 | * be thrown at runtime, e.g., out of memory, that the calling code should be prepared 11 | * to catch. 12 | * 13 | * @alias DeveloperError 14 | * @constructor 15 | * @extends Error 16 | * 17 | * @param {String} [message] The error message for this exception. 18 | * 19 | * @see RuntimeError 20 | */ 21 | 22 | class DeveloperError { 23 | readonly name: string; 24 | 25 | readonly message?: string; 26 | 27 | readonly stack: string; 28 | 29 | constructor (message?: string) { 30 | /** 31 | * 'DeveloperError' indicating that this exception was thrown due to a developer error. 32 | * @type {String} 33 | * @readonly 34 | */ 35 | this.name = 'DeveloperError'; 36 | 37 | /** 38 | * The explanation for why this exception was thrown. 39 | * @type {String} 40 | * @readonly 41 | */ 42 | this.message = message; 43 | 44 | // Browsers such as IE don't have a stack property until you actually throw the error. 45 | let stack; 46 | try { 47 | throw new Error(); 48 | } catch (e) { 49 | stack = (e as any).stack; 50 | } 51 | 52 | /** 53 | * The stack trace of this exception, if available. 54 | * @type {String} 55 | * @readonly 56 | */ 57 | this.stack = stack; 58 | } 59 | 60 | toString (): string { 61 | let str = this.name + ': ' + this.message; 62 | 63 | if (defined(this.stack)) { 64 | str += '\n' + this.stack.toString(); 65 | } 66 | 67 | return str; 68 | } 69 | 70 | static throwInstantiationError (): void { 71 | throw new DeveloperError('This function defines an interface and should not be called directly.'); 72 | } 73 | } 74 | 75 | if (defined(Object.create)) { 76 | DeveloperError.prototype = Object.create(Error.prototype); 77 | DeveloperError.prototype.constructor = DeveloperError; 78 | } 79 | 80 | export { DeveloperError }; 81 | -------------------------------------------------------------------------------- /src/Shader/Builtin/Functions/branchFreeTernary.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Branchless ternary operator to be used when it's inexpensive to explicitly 3 | * evaluate both possibilities for a float expression. 4 | * 5 | * @name czm_branchFreeTernary 6 | * @glslFunction 7 | * 8 | * @param {bool} comparison A comparison statement 9 | * @param {float} a Value to return if the comparison is true. 10 | * @param {float} b Value to return if the comparison is false. 11 | * 12 | * @returns {float} equivalent of comparison ? a : b 13 | */ 14 | float czm_branchFreeTernary(bool comparison, float a, float b) { 15 | float useA = float(comparison); 16 | return a * useA + b * (1.0 - useA); 17 | } 18 | 19 | /** 20 | * Branchless ternary operator to be used when it's inexpensive to explicitly 21 | * evaluate both possibilities for a vec2 expression. 22 | * 23 | * @name czm_branchFreeTernary 24 | * @glslFunction 25 | * 26 | * @param {bool} comparison A comparison statement 27 | * @param {vec2} a Value to return if the comparison is true. 28 | * @param {vec2} b Value to return if the comparison is false. 29 | * 30 | * @returns {vec2} equivalent of comparison ? a : b 31 | */ 32 | vec2 czm_branchFreeTernary(bool comparison, vec2 a, vec2 b) { 33 | float useA = float(comparison); 34 | return a * useA + b * (1.0 - useA); 35 | } 36 | 37 | /** 38 | * Branchless ternary operator to be used when it's inexpensive to explicitly 39 | * evaluate both possibilities for a vec3 expression. 40 | * 41 | * @name czm_branchFreeTernary 42 | * @glslFunction 43 | * 44 | * @param {bool} comparison A comparison statement 45 | * @param {vec3} a Value to return if the comparison is true. 46 | * @param {vec3} b Value to return if the comparison is false. 47 | * 48 | * @returns {vec3} equivalent of comparison ? a : b 49 | */ 50 | vec3 czm_branchFreeTernary(bool comparison, vec3 a, vec3 b) { 51 | float useA = float(comparison); 52 | return a * useA + b * (1.0 - useA); 53 | } 54 | 55 | /** 56 | * Branchless ternary operator to be used when it's inexpensive to explicitly 57 | * evaluate both possibilities for a vec4 expression. 58 | * 59 | * @name czm_branchFreeTernary 60 | * @glslFunction 61 | * 62 | * @param {bool} comparison A comparison statement 63 | * @param {vec3} a Value to return if the comparison is true. 64 | * @param {vec3} b Value to return if the comparison is false. 65 | * 66 | * @returns {vec3} equivalent of comparison ? a : b 67 | */ 68 | vec4 czm_branchFreeTernary(bool comparison, vec4 a, vec4 b) { 69 | float useA = float(comparison); 70 | return a * useA + b * (1.0 - useA); 71 | } 72 | -------------------------------------------------------------------------------- /src/Core/Queue.ts: -------------------------------------------------------------------------------- 1 | 2 | class Queue { 3 | _array: any[]; 4 | _offset: number; 5 | _length: number; 6 | constructor () { 7 | this._array = []; 8 | this._offset = 0; 9 | this._length = 0; 10 | } 11 | 12 | get length (): number { 13 | return this._length; 14 | } 15 | 16 | /** 17 | * Enqueues the specified item. 18 | * 19 | * @param {*} item The item to enqueue. 20 | */ 21 | enqueue (item: any) { 22 | this._array.push(item); 23 | this._length++; 24 | } 25 | 26 | /** 27 | * Dequeues an item. Returns undefined if the queue is empty. 28 | * 29 | * @returns {*} The the dequeued item. 30 | */ 31 | dequeue (): any { 32 | if (this._length === 0) { 33 | return undefined; 34 | } 35 | 36 | const array = this._array; 37 | let offset = this._offset; 38 | const item = array[offset]; 39 | array[offset] = undefined; 40 | 41 | offset++; 42 | if (offset > 10 && offset * 2 > array.length) { 43 | // compact array 44 | this._array = array.slice(offset); 45 | offset = 0; 46 | } 47 | 48 | this._offset = offset; 49 | this._length--; 50 | 51 | return item; 52 | } 53 | 54 | /** 55 | * Returns the item at the front of the queue. Returns undefined if the queue is empty. 56 | * 57 | * @returns {*} The item at the front of the queue. 58 | */ 59 | peek (): any { 60 | if (this._length === 0) { 61 | return undefined; 62 | } 63 | 64 | return this._array[this._offset]; 65 | } 66 | 67 | /** 68 | * Check whether this queue contains the specified item. 69 | * 70 | * @param {*} item The item to search for. 71 | */ 72 | contains (item: any): boolean { 73 | return this._array.indexOf(item) !== -1; 74 | } 75 | 76 | /** 77 | * Remove all items from the queue. 78 | */ 79 | clear (): void { 80 | this._array.length = this._offset = this._length = 0; 81 | } 82 | 83 | /** 84 | * Sort the items in the queue in-place. 85 | * 86 | * @param {Queue.Comparator} compareFunction A function that defines the sort order. 87 | */ 88 | sort (compareFunction: any): void { 89 | if (this._offset > 0) { 90 | // compact array 91 | this._array = this._array.slice(this._offset); 92 | this._offset = 0; 93 | } 94 | 95 | this._array.sort(compareFunction); 96 | } 97 | } 98 | 99 | export { Queue }; 100 | -------------------------------------------------------------------------------- /src/Core/Ray.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Represents a ray that extends infinitely from the provided origin in the provided direction. 4 | * @alias Ray 5 | * @constructor 6 | * 7 | * @param {Cartesian3} [origin=Cartesian3.ZERO] The origin of the ray. 8 | * @param {Cartesian3} [direction=Cartesian3.ZERO] The direction of the ray. 9 | */ 10 | 11 | import { Cartesian3 } from './Cartesian3'; 12 | import { defaultValue } from './defaultValue'; 13 | import { defined } from './defined'; 14 | 15 | class Ray { 16 | origin: Cartesian3; 17 | direction: Cartesian3; 18 | constructor (origin?: Cartesian3, direction?: Cartesian3) { 19 | direction = Cartesian3.clone(defaultValue(direction, Cartesian3.ZERO) as Cartesian3) as Cartesian3; 20 | if (!Cartesian3.equals(direction, Cartesian3.ZERO)) { 21 | Cartesian3.normalize(direction, direction); 22 | } 23 | 24 | /** 25 | * The origin of the ray. 26 | * @type {Cartesian3} 27 | * @default {@link Cartesian3.ZERO} 28 | */ 29 | this.origin = Cartesian3.clone(defaultValue(origin, Cartesian3.ZERO) as Cartesian3) as Cartesian3; 30 | 31 | /** 32 | * The direction of the ray. 33 | * @type {Cartesian3} 34 | */ 35 | this.direction = direction; 36 | } 37 | 38 | at (t: number, target: Cartesian3): Cartesian3 { 39 | // return target.copy(this.direction).multiplyScalar(t).add(this.origin); 40 | 41 | Cartesian3.clone(this.direction, target); 42 | Cartesian3.multiplyByScalar(target, t, target); 43 | Cartesian3.add(target, this.origin, target); 44 | return target; 45 | } 46 | 47 | /** 48 | * Computes the point along the ray given by r(t) = o + t*d, 49 | * where o is the origin of the ray and d is the direction. 50 | * 51 | * @param {Ray} ray The ray. 52 | * @param {Number} t A scalar value. 53 | * @param {Cartesian3} [result] The object in which the result will be stored. 54 | * @returns {Cartesian3} The modified result parameter, or a new instance if none was provided. 55 | * 56 | * @example 57 | * //Get the first intersection point of a ray and an ellipsoid. 58 | * var intersection = Cesium.IntersectionTests.rayEllipsoid(ray, ellipsoid); 59 | * var point = Cesium.Ray.getPoint(ray, intersection.start); 60 | */ 61 | static getPoint (ray: Ray, t: number, result?: Cartesian3): Cartesian3 { 62 | if (!defined(result)) { 63 | result = new Cartesian3(); 64 | } 65 | 66 | result = Cartesian3.multiplyByScalar(ray.direction, t, (result as Cartesian3)); 67 | return Cartesian3.add(ray.origin, result, result); 68 | } 69 | } 70 | 71 | export { Ray }; 72 | -------------------------------------------------------------------------------- /src/Renderer/DrawMeshCommand.ts: -------------------------------------------------------------------------------- 1 | import { BoundingSphere } from '@/Core/BoundingSphere'; 2 | import { defined } from '@/Core/defined'; 3 | import { OrientedBoundingBox } from '@/Core/OrientedBoundingBox'; 4 | import { Context } from '@/Scene/Context'; 5 | import { FrameState } from '@/Scene/FrameState'; 6 | import { BufferGeometry, Material, Mesh } from 'three'; 7 | import { ShaderProgram } from './ShaderProgram'; 8 | 9 | class DrawMeshCommand extends Mesh { 10 | derivedCommands: any; 11 | isCommand: boolean; 12 | isDrawMeshCommand: boolean; 13 | owner?: any; 14 | boundingVolume?: BoundingSphere; 15 | orientedBoundingBox?: OrientedBoundingBox 16 | shaderProgram?: ShaderProgram; 17 | _boundingVolume?: any; 18 | _orientedBoundingBox?: any; 19 | constructor (geometry?: BufferGeometry, material?: Material) { 20 | super(geometry, material); 21 | 22 | this.derivedCommands = { 23 | originalMaterial: this.material, 24 | oit: undefined, 25 | // 用于颜色拾取的材质 26 | picking: undefined, 27 | oitMaterial: undefined, 28 | depth: undefined, 29 | // 对数深度 30 | logDepth: undefined 31 | }; 32 | // this.pass = CommandRenderPass.OPAQUE; 33 | this.isCommand = true; 34 | this.allowPicking = true; 35 | 36 | this.isDrawMeshCommand = true; 37 | 38 | this.frustumCulled = false; 39 | 40 | this.frustumCulled = false; 41 | 42 | this.owner = undefined; 43 | } 44 | 45 | get levelId (): number { 46 | return this.owner.levelId; 47 | } 48 | 49 | compressVertices () { 50 | // const geometry = this.geometry; 51 | } 52 | 53 | static shallowClone (command?: DrawMeshCommand, result = new DrawMeshCommand()): DrawMeshCommand | undefined { 54 | if (!defined(command)) { 55 | return undefined; 56 | } 57 | 58 | result._boundingVolume = command?._boundingVolume; 59 | result._orientedBoundingBox = command?._orientedBoundingBox; 60 | 61 | result.geometry = (command as DrawMeshCommand).geometry; 62 | (result.material as Material).copy((command?.material as Material)); 63 | 64 | return result; 65 | } 66 | 67 | update (frameState: FrameState): void { 68 | // this.material.picking = false; 69 | 70 | // if (defined(this.material.update)) { 71 | // this.material.update(frameState); 72 | // } 73 | 74 | // if (frameState.passes.pick) { 75 | // this.material.picking = true; 76 | // } 77 | } 78 | 79 | execute (context: Context, passState?: any): void { 80 | context.draw(this); 81 | } 82 | } 83 | 84 | export { DrawMeshCommand }; 85 | -------------------------------------------------------------------------------- /src/Core/combine.ts: -------------------------------------------------------------------------------- 1 | import { defaultValue } from './defaultValue'; 2 | import { defined } from './defined'; 3 | 4 | /** 5 | * Merges two objects, copying their properties onto a new combined object. When two objects have the same 6 | * property, the value of the property on the first object is used. If either object is undefined, 7 | * it will be treated as an empty object. 8 | * 9 | * @example 10 | * var object1 = { 11 | * propOne : 1, 12 | * propTwo : { 13 | * value1 : 10 14 | * } 15 | * } 16 | * var object2 = { 17 | * propTwo : 2 18 | * } 19 | * var final = Cesium.combine(object1, object2); 20 | * 21 | * // final === { 22 | * // propOne : 1, 23 | * // propTwo : { 24 | * // value1 : 10 25 | * // } 26 | * // } 27 | * 28 | * @param {Object} [object1] The first object to merge. 29 | * @param {Object} [object2] The second object to merge. 30 | * @param {Boolean} [deep=false] Perform a recursive merge. 31 | * @returns {Object} The combined object containing all properties from both objects. 32 | * 33 | * @function 34 | */ 35 | function combine (object1?: any, object2?: any, deep?: boolean): { [propName: string]: any } { 36 | deep = defaultValue(deep, false); 37 | 38 | const result: { [propName: string]: any } = {}; 39 | 40 | const object1Defined = defined(object1); 41 | const object2Defined = defined(object2); 42 | let property; 43 | let object1Value; 44 | let object2Value; 45 | if (object1Defined) { 46 | for (property in object1) { 47 | if (Object.prototype.hasOwnProperty.call(object1, property)) { 48 | object1Value = object1[property]; 49 | if (object2Defined && deep && 50 | typeof object1Value === 'object' && 51 | Object.prototype.hasOwnProperty.call(object2, property) 52 | ) { 53 | object2Value = object2[property]; 54 | if (typeof object2Value === 'object') { 55 | result[property] = combine(object1Value, object2Value, deep); 56 | } else { 57 | result[property] = object1Value; 58 | } 59 | } else { 60 | result[property] = object1Value; 61 | } 62 | } 63 | } 64 | } 65 | if (object2Defined) { 66 | for (property in object2) { 67 | if (Object.prototype.hasOwnProperty.call(object2, property) && 68 | !Object.prototype.hasOwnProperty.call(result, property) 69 | ) { 70 | object2Value = object2[property]; 71 | result[property] = object2Value; 72 | } 73 | } 74 | } 75 | return result; 76 | } 77 | export { combine }; 78 | -------------------------------------------------------------------------------- /src/Scene/Axis.ts: -------------------------------------------------------------------------------- 1 | import { CesiumMath } from '@/Core/CesiumMath'; 2 | import { CesiumMatrix3 } from '@/Core/CesiumMatrix3'; 3 | import { CesiumMatrix4 } from '@/Core/CesiumMatrix4'; 4 | 5 | /** 6 | * An enum describing the x, y, and z axes and helper conversion functions. 7 | * 8 | * @enum {Number} 9 | */ 10 | const Axis = { 11 | /** 12 | * Denotes the x-axis. 13 | * 14 | * @type {Number} 15 | * @constant 16 | */ 17 | X: 0, 18 | 19 | /** 20 | * Denotes the y-axis. 21 | * 22 | * @type {Number} 23 | * @constant 24 | */ 25 | Y: 1, 26 | 27 | /** 28 | * Denotes the z-axis. 29 | * 30 | * @type {Number} 31 | * @constant 32 | */ 33 | Z: 2, 34 | 35 | /** 36 | * Matrix used to convert from y-up to z-up 37 | * 38 | * @type {Matrix4} 39 | * @constant 40 | */ 41 | Y_UP_TO_Z_UP: CesiumMatrix4.fromRotationTranslation( 42 | CesiumMatrix3.fromRotationX(CesiumMath.PI_OVER_TWO) 43 | ), 44 | 45 | /** 46 | * Matrix used to convert from z-up to y-up 47 | * 48 | * @type {Matrix4} 49 | * @constant 50 | */ 51 | Z_UP_TO_Y_UP: CesiumMatrix4.fromRotationTranslation( 52 | CesiumMatrix3.fromRotationX(-CesiumMath.PI_OVER_TWO) 53 | ), 54 | 55 | /** 56 | * Matrix used to convert from x-up to z-up 57 | * 58 | * @type {Matrix4} 59 | * @constant 60 | */ 61 | X_UP_TO_Z_UP: CesiumMatrix4.fromRotationTranslation( 62 | CesiumMatrix3.fromRotationY(-CesiumMath.PI_OVER_TWO) 63 | ), 64 | 65 | /** 66 | * Matrix used to convert from z-up to x-up 67 | * 68 | * @type {Matrix4} 69 | * @constant 70 | */ 71 | Z_UP_TO_X_UP: CesiumMatrix4.fromRotationTranslation( 72 | CesiumMatrix3.fromRotationY(CesiumMath.PI_OVER_TWO) 73 | ), 74 | 75 | /** 76 | * Matrix used to convert from x-up to y-up 77 | * 78 | * @type {Matrix4} 79 | * @constant 80 | */ 81 | X_UP_TO_Y_UP: CesiumMatrix4.fromRotationTranslation( 82 | CesiumMatrix3.fromRotationZ(CesiumMath.PI_OVER_TWO) 83 | ), 84 | 85 | /** 86 | * Matrix used to convert from y-up to x-up 87 | * 88 | * @type {Matrix4} 89 | * @constant 90 | */ 91 | Y_UP_TO_X_UP: CesiumMatrix4.fromRotationTranslation( 92 | CesiumMatrix3.fromRotationZ(-CesiumMath.PI_OVER_TWO) 93 | ), 94 | 95 | /** 96 | * Gets the axis by name 97 | * 98 | * @param {String} name The name of the axis. 99 | * @returns {Number} The axis enum. 100 | */ 101 | fromName (name: number): number { 102 | return Axis[name]; 103 | } 104 | 105 | }; 106 | export { Axis }; 107 | --------------------------------------------------------------------------------